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 <QDebug>
#include <sstream>
Age::Age(unsigned int years, unsigned int months)
: m_years(years)
@ -56,3 +57,10 @@ unsigned int Age::months() const
{
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 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
{
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)
{
switch (index.column())
switch (modelIndex.column())
{
case 0:
return m_participant;
@ -34,6 +34,8 @@ QVariant MetaDataModel::data(const QModelIndex &index, int role) const
return m_dateOfTest;
case 4:
return m_remarks;
case 5:
return QString::fromStdString(getAge().toString());
default:
return QVariant();
}
@ -42,22 +44,22 @@ QVariant MetaDataModel::data(const QModelIndex &index, int role) const
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(
const QModelIndex &index, const QVariant &value, int role)
const QModelIndex &modelIndex, const QVariant &value, int role)
{
if (role != Qt::EditRole)
{
return QAbstractTableModel::setData(index, value, role);
return QAbstractTableModel::setData(modelIndex, value, role);
}
bool valueChanged = false;
switch (index.column())
switch (modelIndex.column())
{
case 0:
if (value.toString() != m_participant)
@ -77,6 +79,7 @@ bool MetaDataModel::setData(
if (value.toDate() != m_dateOfBirth)
{
m_dateOfBirth = value.toDate();
emit dataChanged(index(0, 5), index(0, 5));
valueChanged = true;
}
break;
@ -84,6 +87,7 @@ bool MetaDataModel::setData(
if (value.toDate() != m_dateOfTest)
{
m_dateOfTest = value.toDate();
emit dataChanged(index(0, 5), index(0, 5));
valueChanged = true;
}
break;
@ -100,7 +104,7 @@ bool MetaDataModel::setData(
if (valueChanged)
{
emit dataChanged(index, index);
emit dataChanged(modelIndex, modelIndex);
}
return valueChanged;

View file

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

View file

@ -16,46 +16,102 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="upperArea" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="2">
<widget class="QLabel" name="dateOfTestLabel">
<property name="text">
<string>Untersuchungsdatum</string>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="personsLayout">
<item>
<widget class="QLabel" name="participantLabel">
<property name="text">
<string>Name, Vorname</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="participantLineEdit"/>
</item>
<item>
<widget class="QLabel" name="instructorLabel">
<property name="text">
<string>Untersucher(in)</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="instructorLineEdit"/>
</item>
</layout>
</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">
<property name="text">
<string>Name, Vorname</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="instructorLineEdit"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="instructorLabel">
<property name="text">
<string>Untersucher(in)</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QDateEdit" name="dateOfTestDateEdit"/>
</item>
<item row="2" column="1">
<widget class="QDateEdit" name="dateOfBirthDateEdit"/>
<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"/>
</item>
<item>
<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>
</layout>
</widget>

View file

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