From 060348fdc5b2053be76b467bbb71b44a56f4c37f Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 14 Jun 2018 19:52:19 +0200 Subject: [PATCH] added age display to meta-data tab --- source/Age.cpp | 8 ++ source/Age.h | 2 + source/MetaData/MetaDataModel.cpp | 22 +++-- source/MetaData/MetaDataWidget.cpp | 1 + source/MetaData/MetaDataWidget.ui | 134 ++++++++++++++++++++--------- source/mainwindow.ui | 8 +- 6 files changed, 123 insertions(+), 52 deletions(-) diff --git a/source/Age.cpp b/source/Age.cpp index 2f406c6..81415e9 100644 --- a/source/Age.cpp +++ b/source/Age.cpp @@ -1,6 +1,7 @@ #include "Age.h" #include +#include 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(); +} diff --git a/source/Age.h b/source/Age.h index 1ad28a2..5bd7924 100644 --- a/source/Age.h +++ b/source/Age.h @@ -17,4 +17,6 @@ public: unsigned int years() const; unsigned int months() const; + + std::string toString() const; }; diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 6b873b5..e125e0d 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -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; diff --git a/source/MetaData/MetaDataWidget.cpp b/source/MetaData/MetaDataWidget.cpp index 811c788..b7851e1 100644 --- a/source/MetaData/MetaDataWidget.cpp +++ b/source/MetaData/MetaDataWidget.cpp @@ -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(); } diff --git a/source/MetaData/MetaDataWidget.ui b/source/MetaData/MetaDataWidget.ui index aa53971..22fbc1c 100644 --- a/source/MetaData/MetaDataWidget.ui +++ b/source/MetaData/MetaDataWidget.ui @@ -16,46 +16,102 @@ - - - - - Untersuchungsdatum - - + + + + + + + Name, Vorname + + + + + + + + + + Untersucher(in) + + + + + + + - - - - - - - Geburtsdatum - - - - - - - Name, Vorname - - - - - - - - - - Untersucher(in) - - - - - - - - + + + + + + Geburtsdatum + + + + + + + + + + Untersuchungsdatum + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Alter am Testtag + + + + + + + + 0 + 0 + + + + + 40 + 0 + + + + + 40 + 16777215 + + + + Qt::NoFocus + + + true + + + + diff --git a/source/mainwindow.ui b/source/mainwindow.ui index e04d77d..c6a0755 100644 --- a/source/mainwindow.ui +++ b/source/mainwindow.ui @@ -122,7 +122,7 @@ - + :/images/document-save-as.png:/images/document-save-as.png @@ -137,7 +137,7 @@ - + :/images/document-open.png:/images/document-open.png @@ -149,7 +149,7 @@ - + :/images/document-new.png:/images/document-new.png @@ -169,7 +169,7 @@ - + :/images/document-save-as.png:/images/document-save-as.png