2018-05-15 12:24:15 +00:00
|
|
|
#include "MetaDataModel.h"
|
|
|
|
|
2018-11-26 20:47:42 +00:00
|
|
|
#include <QTextTable>
|
2018-05-15 12:24:15 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2018-11-03 21:29:38 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2018-08-11 14:48:42 +00:00
|
|
|
MetaDataModel::MetaDataModel(QObject *parent)
|
2018-11-03 21:29:38 +00:00
|
|
|
: QAbstractTableModel(parent)
|
2018-05-15 12:24:15 +00:00
|
|
|
{
|
2018-08-11 13:53:29 +00:00
|
|
|
m_dateOfBirth = QDate::currentDate().addYears(-9);
|
2018-05-20 10:04:21 +00:00
|
|
|
m_dateOfTest = QDate::currentDate();
|
2018-05-15 12:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int MetaDataModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetaDataModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2018-06-14 17:52:19 +00:00
|
|
|
return 6;
|
2018-05-15 12:24:15 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 17:52:19 +00:00
|
|
|
QVariant MetaDataModel::data(const QModelIndex &modelIndex, int role) const
|
2018-05-15 12:24:15 +00:00
|
|
|
{
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
|
|
|
{
|
2018-06-14 17:52:19 +00:00
|
|
|
switch (modelIndex.column())
|
2018-05-15 12:24:15 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return m_participant;
|
|
|
|
case 1:
|
|
|
|
return m_instructor;
|
|
|
|
case 2:
|
|
|
|
return m_dateOfBirth;
|
|
|
|
case 3:
|
|
|
|
return m_dateOfTest;
|
|
|
|
case 4:
|
|
|
|
return m_remarks;
|
2018-06-14 17:52:19 +00:00
|
|
|
case 5:
|
|
|
|
return QString::fromStdString(getAge().toString());
|
2018-05-15 12:24:15 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
2018-05-15 12:37:16 +00:00
|
|
|
|
2018-06-14 17:52:19 +00:00
|
|
|
Qt::ItemFlags MetaDataModel::flags(const QModelIndex &modelIndex) const
|
2018-05-17 17:42:35 +00:00
|
|
|
{
|
2018-06-14 17:52:19 +00:00
|
|
|
return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable;
|
2018-05-17 17:42:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-03 21:29:38 +00:00
|
|
|
bool MetaDataModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
|
2018-05-17 17:42:35 +00:00
|
|
|
{
|
|
|
|
if (role != Qt::EditRole)
|
|
|
|
{
|
2018-06-14 17:52:19 +00:00
|
|
|
return QAbstractTableModel::setData(modelIndex, value, role);
|
2018-05-17 17:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool valueChanged = false;
|
|
|
|
|
2018-06-14 17:52:19 +00:00
|
|
|
switch (modelIndex.column())
|
2018-05-17 17:42:35 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (value.toString() != m_participant)
|
|
|
|
{
|
|
|
|
m_participant = value.toString();
|
|
|
|
valueChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (value.toString() != m_instructor)
|
|
|
|
{
|
|
|
|
m_instructor = value.toString();
|
|
|
|
valueChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2018-05-18 18:36:48 +00:00
|
|
|
if (value.toDate() != m_dateOfBirth)
|
2018-05-17 17:42:35 +00:00
|
|
|
{
|
2018-05-18 18:36:48 +00:00
|
|
|
m_dateOfBirth = value.toDate();
|
2018-06-14 17:52:19 +00:00
|
|
|
emit dataChanged(index(0, 5), index(0, 5));
|
2018-05-17 17:42:35 +00:00
|
|
|
valueChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2018-05-18 18:36:48 +00:00
|
|
|
if (value.toDate() != m_dateOfTest)
|
2018-05-17 17:42:35 +00:00
|
|
|
{
|
2018-05-18 18:36:48 +00:00
|
|
|
m_dateOfTest = value.toDate();
|
2018-06-14 17:52:19 +00:00
|
|
|
emit dataChanged(index(0, 5), index(0, 5));
|
2018-05-17 17:42:35 +00:00
|
|
|
valueChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (value.toString() != m_remarks)
|
|
|
|
{
|
|
|
|
m_remarks = value.toString();
|
|
|
|
valueChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-08 18:25:21 +00:00
|
|
|
if (valueChanged)
|
|
|
|
{
|
2018-06-14 17:52:19 +00:00
|
|
|
emit dataChanged(modelIndex, modelIndex);
|
2018-06-08 18:25:21 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 17:42:35 +00:00
|
|
|
return valueChanged;
|
|
|
|
}
|
|
|
|
|
2018-11-20 06:59:12 +00:00
|
|
|
void MetaDataModel::read(const ESGRAF48::MetaDataModel &model)
|
2018-11-16 22:21:02 +00:00
|
|
|
{
|
|
|
|
setData(index(0, 0), QString::fromStdString(model.participantname()));
|
|
|
|
setData(index(0, 1), QString::fromStdString(model.instructorname()));
|
|
|
|
setData(index(0, 2), QString::fromStdString(model.dateofbirth()));
|
|
|
|
setData(index(0, 3), QString::fromStdString(model.dateoftest()));
|
|
|
|
setData(index(0, 4), QString::fromStdString(model.remarks()));
|
|
|
|
}
|
|
|
|
|
2018-11-20 06:59:12 +00:00
|
|
|
void MetaDataModel::write(ESGRAF48::MetaDataModel &model) const
|
2018-11-16 22:21:02 +00:00
|
|
|
{
|
|
|
|
model.set_participantname(m_participant.toStdString());
|
|
|
|
model.set_instructorname(m_instructor.toStdString());
|
|
|
|
model.set_dateofbirth(m_dateOfBirth.toString(Qt::ISODate).toStdString());
|
|
|
|
model.set_dateoftest(m_dateOfTest.toString(Qt::ISODate).toStdString());
|
|
|
|
model.set_remarks(m_remarks.toStdString());
|
|
|
|
}
|
2018-11-13 23:17:29 +00:00
|
|
|
|
2018-11-26 20:47:42 +00:00
|
|
|
void MetaDataModel::printTo(QTextCursor &cursor) const
|
|
|
|
{
|
|
|
|
cursor.insertBlock();
|
|
|
|
|
2018-12-15 15:12:20 +00:00
|
|
|
QTextTableFormat tableFormat = defaultTableFormat();
|
2018-12-08 20:02:35 +00:00
|
|
|
tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_None);
|
2018-11-26 20:47:42 +00:00
|
|
|
|
|
|
|
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 25),
|
|
|
|
QTextLength(QTextLength::PercentageLength, 25),
|
|
|
|
QTextLength(QTextLength::PercentageLength, 25),
|
|
|
|
QTextLength(QTextLength::PercentageLength, 25)});
|
|
|
|
|
|
|
|
QTextTable *table = cursor.insertTable(4, 4, tableFormat);
|
|
|
|
table->mergeCells(1, 2, 1, 2);
|
|
|
|
table->mergeCells(2, 2, 2, 2);
|
|
|
|
|
|
|
|
cursor.insertText("Name, Vorname");
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
|
|
|
cursor.insertText(m_participant);
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
|
|
|
cursor.insertText("Untersucher(in)");
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
|
|
|
cursor.insertText(m_instructor);
|
|
|
|
cursor.movePosition(QTextCursor::NextRow);
|
|
|
|
|
|
|
|
cursor.insertText("Geburtsdatum");
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
|
|
|
cursor.insertText(m_dateOfBirth.toString("dd.MM.yyyy"));
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
2018-12-08 20:02:35 +00:00
|
|
|
if (!m_remarks.trimmed().isEmpty())
|
|
|
|
{
|
|
|
|
cursor.insertText("Bemerkungen:");
|
|
|
|
}
|
2018-11-26 20:47:42 +00:00
|
|
|
cursor.movePosition(QTextCursor::NextRow);
|
|
|
|
|
|
|
|
cursor.insertText("Untersuchungsdatum");
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
|
|
|
cursor.insertText(m_dateOfTest.toString("dd.MM.yyyy"));
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
|
|
|
cursor.insertText(m_remarks.trimmed());
|
|
|
|
cursor.movePosition(QTextCursor::NextRow);
|
|
|
|
|
|
|
|
cursor.insertText("Alter am Testtag");
|
|
|
|
cursor.movePosition(QTextCursor::NextCell);
|
|
|
|
cursor.insertText(getAge().toString().c_str());
|
|
|
|
|
2018-12-08 20:02:35 +00:00
|
|
|
cursor.movePosition(QTextCursor::End);
|
2018-11-26 20:47:42 +00:00
|
|
|
}
|
|
|
|
|