From bf963adeb53a5cffc65ee31527cbfccad5a1fdcc Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 26 Nov 2018 21:47:42 +0100 Subject: [PATCH] Print metadata and v2svk header --- source/DataModel.cpp | 10 ++++ source/DataModel.h | 2 + source/MetaData/MetaDataModel.cpp | 76 ++++++++++++++++++++-------- source/MetaData/MetaDataModel.h | 2 + source/SubTests/V2Svk/V2SvkModel.cpp | 12 +++++ source/SubTests/V2Svk/V2SvkModel.h | 4 ++ source/mainwindow.cpp | 3 +- 7 files changed, 88 insertions(+), 21 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 216eb8c..a8fd476 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -60,6 +60,16 @@ void DataModel::read(std::istream &inStream) m_passiv.read(dataModel.lateskillspassiv()); } +void DataModel::printTo(QTextCursor &cursor) const +{ + QTextCharFormat titleFormat; + titleFormat.setFontPointSize(18); + cursor.insertText("ESGRAF 4-8 Auswertungsbogen", titleFormat); + + m_metaData.printTo(cursor); + m_v2Svk.printTo(cursor); +} + std::string DataModel::toHtml() const { std::stringstream out; diff --git a/source/DataModel.h b/source/DataModel.h index 71a9352..6691e18 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -13,6 +13,7 @@ #include "ResultModel.h" #include +#include class DataModel : public QObject { @@ -34,6 +35,7 @@ public: public: DataModel(QObject *parent); + void printTo(QTextCursor &cursor) const; std::string toHtml() const; void write(std::ostream &outStream) const; diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 94c2a62..8308807 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -1,5 +1,6 @@ #include "MetaDataModel.h" +#include #include #include @@ -130,33 +131,68 @@ void MetaDataModel::write(ESGRAF48::MetaDataModel &model) const model.set_remarks(m_remarks.toStdString()); } +void MetaDataModel::printTo(QTextCursor &cursor) const +{ + cursor.insertBlock(); + + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + 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); + cursor.insertText("Bemerkungen:"); + 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()); + + cursor.movePosition(QTextCursor::NextBlock); +} + std::string MetaDataModel::toHtml() const { std::ostringstream out; - out << "" - << std::endl; + out << "
" << std::endl; out << "" << std::endl; - out << "" << std::endl; - out << "" - << std::endl; - out << "" << std::endl; - out << "" - << std::endl; + out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; - out << "" << std::endl; - out << "" - << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" - << std::endl; - out << "" - << std::endl; + out << "" << std::endl; + out << "" + << std::endl; + out << "" + << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 0c8bbeb..cecf8ca 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -8,6 +8,7 @@ #include #include #include +#include class MetaDataModel : public QAbstractTableModel { @@ -33,6 +34,7 @@ public: void read(const ESGRAF48::MetaDataModel &model); void write(ESGRAF48::MetaDataModel &model) const; + void printTo(QTextCursor &cursor) const; std::string toHtml() const; Age getAge() const diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 2196ba4..0362db4 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -199,3 +199,15 @@ void V2SvkModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +void V2SvkModel::printTo(QTextCursor &cursor) const +{ + cursor.insertBlock(); + + QTextCharFormat headerFormat; + headerFormat.setFontPointSize(12); + cursor.insertText("Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)", headerFormat); + + cursor.movePosition(QTextCursor::NextBlock); +} + diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index 519508a..6b070d8 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -3,6 +3,8 @@ #include "CheckableTestModel.h" #include "V2SvkModel.pb.h" +#include + class V2SvkModel : public CheckableTestModel { Q_OBJECT @@ -16,6 +18,8 @@ public: void write(ESGRAF48::V2SvkModel &model) const; void read(const ESGRAF48::V2SvkModel &model); + void printTo(QTextCursor &cursor) const; + protected: bool isValidIndex(const QModelIndex &index) const override; }; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 20d877a..1ac4270 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -144,7 +144,8 @@ void MainWindow::print() const } QTextDocument printDoc; - printDoc.setHtml(QString::fromStdString(m_dataModel->toHtml())); + QTextCursor printCursor(&printDoc); + m_dataModel->printTo(printCursor); printDoc.print(&printer); }
Name, Vorname" << m_participant.toHtmlEscaped().toStdString() << "Untersucher(in)" << m_instructor.toHtmlEscaped().toStdString() << "Bemerkungen
Geburtsdatum" << m_dateOfBirth.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "Bemerkungen
Untersuchungsdatum" << m_dateOfTest.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "" - << m_remarks.trimmed().toHtmlEscaped().replace("\n", "
").toStdString() << "
Untersuchungsdatum" << m_dateOfTest.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "" + << m_remarks.trimmed().toHtmlEscaped().replace("\n", "
").toStdString() << "
Alter am Testtag