added age display to meta-data tab

This commit is contained in:
Michael Mandl 2018-06-14 19:52:19 +02:00
parent 017ff01a83
commit 060348fdc5
6 changed files with 123 additions and 52 deletions

View file

@ -1,6 +1,7 @@
#include "Age.h" #include "Age.h"
#include <QDebug> #include <QDebug>
#include <sstream>
Age::Age(unsigned int years, unsigned int months) Age::Age(unsigned int years, unsigned int months)
: m_years(years) : m_years(years)
@ -56,3 +57,10 @@ unsigned int Age::months() const
{ {
return m_months; return m_months;
} }
std::string Age::toString() const
{
std::ostringstream result;
result << m_years << ";" << m_months;
return result.str();
}

View file

@ -17,4 +17,6 @@ public:
unsigned int years() const; unsigned int years() const;
unsigned int months() const; unsigned int months() const;
std::string toString() const;
}; };

View file

@ -15,14 +15,14 @@ int MetaDataModel::rowCount(const QModelIndex &parent) const
int MetaDataModel::columnCount(const QModelIndex &parent) const int MetaDataModel::columnCount(const QModelIndex &parent) const
{ {
return 5; return 6;
} }
QVariant MetaDataModel::data(const QModelIndex &index, int role) const QVariant MetaDataModel::data(const QModelIndex &modelIndex, int role) const
{ {
if (role == Qt::DisplayRole || role == Qt::EditRole) if (role == Qt::DisplayRole || role == Qt::EditRole)
{ {
switch (index.column()) switch (modelIndex.column())
{ {
case 0: case 0:
return m_participant; return m_participant;
@ -34,6 +34,8 @@ QVariant MetaDataModel::data(const QModelIndex &index, int role) const
return m_dateOfTest; return m_dateOfTest;
case 4: case 4:
return m_remarks; return m_remarks;
case 5:
return QString::fromStdString(getAge().toString());
default: default:
return QVariant(); return QVariant();
} }
@ -42,22 +44,22 @@ QVariant MetaDataModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
Qt::ItemFlags MetaDataModel::flags(const QModelIndex &index) const Qt::ItemFlags MetaDataModel::flags(const QModelIndex &modelIndex) const
{ {
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable; return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable;
} }
bool MetaDataModel::setData( bool MetaDataModel::setData(
const QModelIndex &index, const QVariant &value, int role) const QModelIndex &modelIndex, const QVariant &value, int role)
{ {
if (role != Qt::EditRole) if (role != Qt::EditRole)
{ {
return QAbstractTableModel::setData(index, value, role); return QAbstractTableModel::setData(modelIndex, value, role);
} }
bool valueChanged = false; bool valueChanged = false;
switch (index.column()) switch (modelIndex.column())
{ {
case 0: case 0:
if (value.toString() != m_participant) if (value.toString() != m_participant)
@ -77,6 +79,7 @@ bool MetaDataModel::setData(
if (value.toDate() != m_dateOfBirth) if (value.toDate() != m_dateOfBirth)
{ {
m_dateOfBirth = value.toDate(); m_dateOfBirth = value.toDate();
emit dataChanged(index(0, 5), index(0, 5));
valueChanged = true; valueChanged = true;
} }
break; break;
@ -84,6 +87,7 @@ bool MetaDataModel::setData(
if (value.toDate() != m_dateOfTest) if (value.toDate() != m_dateOfTest)
{ {
m_dateOfTest = value.toDate(); m_dateOfTest = value.toDate();
emit dataChanged(index(0, 5), index(0, 5));
valueChanged = true; valueChanged = true;
} }
break; break;
@ -100,7 +104,7 @@ bool MetaDataModel::setData(
if (valueChanged) if (valueChanged)
{ {
emit dataChanged(index, index); emit dataChanged(modelIndex, modelIndex);
} }
return valueChanged; return valueChanged;

View file

@ -26,6 +26,7 @@ void MetaDataWidget::setModel(MetaDataModel *model)
m_widgetMapper->addMapping(ui->dateOfBirthDateEdit, 2); m_widgetMapper->addMapping(ui->dateOfBirthDateEdit, 2);
m_widgetMapper->addMapping(ui->dateOfTestDateEdit, 3); m_widgetMapper->addMapping(ui->dateOfTestDateEdit, 3);
m_widgetMapper->addMapping(ui->remarksPlainTextEdit, 4); m_widgetMapper->addMapping(ui->remarksPlainTextEdit, 4);
m_widgetMapper->addMapping(ui->ageLineEdit, 5);
m_widgetMapper->toFirst(); m_widgetMapper->toFirst();
} }

View file

@ -16,46 +16,102 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QWidget" name="upperArea" native="true"> <widget class="QWidget" name="upperArea" native="true">
<layout class="QGridLayout" name="gridLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item row="2" column="2"> <item>
<widget class="QLabel" name="dateOfTestLabel"> <layout class="QHBoxLayout" name="personsLayout">
<property name="text"> <item>
<string>Untersuchungsdatum</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="participantLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="dateOfBirthLabel">
<property name="text">
<string>Geburtsdatum</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="participantLabel"> <widget class="QLabel" name="participantLabel">
<property name="text"> <property name="text">
<string>Name, Vorname</string> <string>Name, Vorname</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="3"> <item>
<widget class="QLineEdit" name="instructorLineEdit"/> <widget class="QLineEdit" name="participantLineEdit"/>
</item> </item>
<item row="1" column="2"> <item>
<widget class="QLabel" name="instructorLabel"> <widget class="QLabel" name="instructorLabel">
<property name="text"> <property name="text">
<string>Untersucher(in)</string> <string>Untersucher(in)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="3"> <item>
<widget class="QLineEdit" name="instructorLineEdit"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="datesLayout">
<item>
<widget class="QLabel" name="dateOfBirthLabel">
<property name="text">
<string>Geburtsdatum</string>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="dateOfBirthDateEdit"/>
</item>
<item>
<widget class="QLabel" name="dateOfTestLabel">
<property name="text">
<string>Untersuchungsdatum</string>
</property>
</widget>
</item>
<item>
<widget class="QDateEdit" name="dateOfTestDateEdit"/> <widget class="QDateEdit" name="dateOfTestDateEdit"/>
</item> </item>
<item row="2" column="1"> <item>
<widget class="QDateEdit" name="dateOfBirthDateEdit"/> <spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="ageLabel">
<property name="text">
<string>Alter am Testtag</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ageLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>

View file

@ -122,7 +122,7 @@
</widget> </widget>
<action name="actionSave_as"> <action name="actionSave_as">
<property name="icon"> <property name="icon">
<iconset resource="mainwindow.qrc"> <iconset>
<normaloff>:/images/document-save-as.png</normaloff>:/images/document-save-as.png</iconset> <normaloff>:/images/document-save-as.png</normaloff>:/images/document-save-as.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -137,7 +137,7 @@
</action> </action>
<action name="actionOpen"> <action name="actionOpen">
<property name="icon"> <property name="icon">
<iconset resource="mainwindow.qrc"> <iconset>
<normaloff>:/images/document-open.png</normaloff>:/images/document-open.png</iconset> <normaloff>:/images/document-open.png</normaloff>:/images/document-open.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -149,7 +149,7 @@
</action> </action>
<action name="actionNew"> <action name="actionNew">
<property name="icon"> <property name="icon">
<iconset resource="mainwindow.qrc"> <iconset>
<normaloff>:/images/document-new.png</normaloff>:/images/document-new.png</iconset> <normaloff>:/images/document-new.png</normaloff>:/images/document-new.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@ -169,7 +169,7 @@
</action> </action>
<action name="actionSave"> <action name="actionSave">
<property name="icon"> <property name="icon">
<iconset resource="mainwindow.qrc"> <iconset>
<normaloff>:/images/document-save-as.png</normaloff>:/images/document-save-as.png</iconset> <normaloff>:/images/document-save-as.png</normaloff>:/images/document-save-as.png</iconset>
</property> </property>
<property name="text"> <property name="text">