From bf963adeb53a5cffc65ee31527cbfccad5a1fdcc Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 26 Nov 2018 21:47:42 +0100 Subject: [PATCH 01/16] 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); } From bf08d0c5e46a922c8ade890abbf8edacf7776f12 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 28 Nov 2018 22:39:51 +0100 Subject: [PATCH 02/16] Print formatting --- source/DataModel.cpp | 2 ++ source/SubTests/V2Svk/V2SvkModel.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index a8fd476..05bf9d2 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -65,8 +65,10 @@ void DataModel::printTo(QTextCursor &cursor) const QTextCharFormat titleFormat; titleFormat.setFontPointSize(18); cursor.insertText("ESGRAF 4-8 Auswertungsbogen", titleFormat); + cursor.insertText("\n", titleFormat); m_metaData.printTo(cursor); + cursor.insertText("\n", titleFormat); m_v2Svk.printTo(cursor); } diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 0362db4..cdf7596 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -206,7 +206,15 @@ void V2SvkModel::printTo(QTextCursor &cursor) const QTextCharFormat headerFormat; headerFormat.setFontPointSize(12); - cursor.insertText("Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)", headerFormat); + cursor.insertText( + "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)", + headerFormat); + + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + QTextTable *table = cursor.insertTable(1, 1, tableFormat); cursor.movePosition(QTextCursor::NextBlock); } From bcd0b17caaab45c40d1ec7a714056b99ce442866 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 28 Nov 2018 22:43:32 +0100 Subject: [PATCH 03/16] Removed html output --- source/DataModel.cpp | 23 ----------------------- source/DataModel.h | 1 - source/MetaData/MetaDataModel.cpp | 24 ------------------------ source/MetaData/MetaDataModel.h | 1 - source/mainwindow.cpp | 3 --- 5 files changed, 52 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 05bf9d2..b49039a 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -72,29 +72,6 @@ void DataModel::printTo(QTextCursor &cursor) const m_v2Svk.printTo(cursor); } -std::string DataModel::toHtml() const -{ - std::stringstream out; - - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "

ESGRAF 4-8 Auswertungsbogen

" << std::endl; - out << "

" << std::endl; - out << m_metaData.toHtml(); - out << "

" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - - return out.str(); -} - void DataModel::pluralModelChanged() { m_results.setPluralResult(m_plural.getPoints()); diff --git a/source/DataModel.h b/source/DataModel.h index 6691e18..a718ef7 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -36,7 +36,6 @@ public: DataModel(QObject *parent); void printTo(QTextCursor &cursor) const; - std::string toHtml() const; void write(std::ostream &outStream) const; void read(std::istream &inStream); diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 8308807..c6ef6dd 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -178,27 +178,3 @@ void MetaDataModel::printTo(QTextCursor &cursor) const cursor.movePosition(QTextCursor::NextBlock); } -std::string MetaDataModel::toHtml() const -{ - std::ostringstream out; - - out << "
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
" << 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 << "
Bemerkungen
Untersuchungsdatum" << m_dateOfTest.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "" - << m_remarks.trimmed().toHtmlEscaped().replace("\n", "
").toStdString() << "
Alter am Testtag" << getAge().toString() << "
" << std::endl; - - return out.str(); -} diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index cecf8ca..a96f75a 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -35,7 +35,6 @@ public: void write(ESGRAF48::MetaDataModel &model) const; void printTo(QTextCursor &cursor) const; - std::string toHtml() const; Age getAge() const { diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 1ac4270..3e608b2 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -132,9 +132,6 @@ void MainWindow::closeFile() void MainWindow::print() const { - //std::ofstream htmlfile("print.html"); - //htmlfile << m_dataModel->toHtml(); - QPrinter printer; QPrintDialog dialog(&printer); From b06e71757505bc410f58f5936f283b769836748d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 2 Dec 2018 18:26:22 +0100 Subject: [PATCH 04/16] Very basic subtest 2 print output --- source/CheckableItem/CheckableItem.cpp | 21 --- source/CheckableItem/CheckableItem.h | 3 - source/CheckableItem/CheckableItems.cpp | 28 +-- source/CheckableItem/CheckableItems.h | 3 +- source/CheckableTest/CheckableTest.cpp | 7 + source/CheckableTest/CheckableTest.h | 2 + .../CheckableTestModel/CheckableTestModel.cpp | 29 +-- .../CheckableTestModel/CheckableTestModel.h | 3 - source/DataModel.cpp | 9 + source/ResultWidget/CMakeLists.txt | 1 + source/ResultWidget/ResultModel.cpp | 20 +++ source/ResultWidget/ResultModel.h | 52 +----- source/ResultWidget/TestResult.cpp | 31 ++++ source/ResultWidget/TestResult.h | 22 +++ source/SubTests/VerbEnd/VerbEndModel.cpp | 167 +++++++++++++++++- source/SubTests/VerbEnd/VerbEndModel.h | 4 + 16 files changed, 272 insertions(+), 130 deletions(-) create mode 100644 source/ResultWidget/TestResult.cpp create mode 100644 source/ResultWidget/TestResult.h diff --git a/source/CheckableItem/CheckableItem.cpp b/source/CheckableItem/CheckableItem.cpp index 6d6a16a..faed665 100644 --- a/source/CheckableItem/CheckableItem.cpp +++ b/source/CheckableItem/CheckableItem.cpp @@ -34,24 +34,3 @@ unsigned int CheckableItem::points() const { return m_checked ? m_value : 0; } - -void CheckableItem::write(QJsonObject &json) const -{ - json["text"] = m_text.c_str(); - json["checked"] = m_checked; -} - -void CheckableItem::read(const QJsonObject &json) -{ - const auto &text = json["text"]; - if (text.isString()) - { - m_text = text.toString().toStdString(); - } - - const auto &checked = json["checked"]; - if (checked.isBool()) - { - m_checked = checked.toBool(); - } -} diff --git a/source/CheckableItem/CheckableItem.h b/source/CheckableItem/CheckableItem.h index a37086e..89feffe 100644 --- a/source/CheckableItem/CheckableItem.h +++ b/source/CheckableItem/CheckableItem.h @@ -24,7 +24,4 @@ public: void setValue(unsigned int value); unsigned int points() const; - - void write(QJsonObject &json) const; - void read(const QJsonObject &json); }; diff --git a/source/CheckableItem/CheckableItems.cpp b/source/CheckableItem/CheckableItems.cpp index 30532f3..f9b59f3 100644 --- a/source/CheckableItem/CheckableItems.cpp +++ b/source/CheckableItem/CheckableItems.cpp @@ -2,6 +2,8 @@ #include +#include + CheckableItems::CheckableItems(std::initializer_list itemNames) { for (const auto &itemName : itemNames) @@ -10,27 +12,9 @@ CheckableItems::CheckableItems(std::initializer_list itemNames) } } -void CheckableItems::write(QJsonArray &json) const +unsigned int CheckableItems::getPoints() const { - for (const auto &item : *this) - { - QJsonObject itemObject; - item.write(itemObject); - json.append(itemObject); - } -} - -void CheckableItems::read(const QJsonArray &json) -{ - clear(); - - for (const auto &itemObject : json) - { - if (itemObject.isObject()) - { - CheckableItem item; - item.read(itemObject.toObject()); - emplace_back(item); - } - } + return std::accumulate(begin(), end(), 0, [](int base, const CheckableItem &item) { + return base + item.points(); + }); } diff --git a/source/CheckableItem/CheckableItems.h b/source/CheckableItem/CheckableItems.h index 164f829..b147e27 100644 --- a/source/CheckableItem/CheckableItems.h +++ b/source/CheckableItem/CheckableItems.h @@ -10,6 +10,5 @@ class CheckableItems : public std::vector public: CheckableItems(std::initializer_list itemNames); - void write(QJsonArray &json) const; - void read(const QJsonArray &json); + unsigned int getPoints() const; }; diff --git a/source/CheckableTest/CheckableTest.cpp b/source/CheckableTest/CheckableTest.cpp index 0d0cbf5..fabf0c3 100644 --- a/source/CheckableTest/CheckableTest.cpp +++ b/source/CheckableTest/CheckableTest.cpp @@ -1,5 +1,7 @@ #include "CheckableTest.h" +#include + CheckableTest::CheckableTest( const char *name, std::initializer_list items) : m_name(name) @@ -26,3 +28,8 @@ CheckableItems &CheckableTest::items() { return m_items; } + +unsigned int CheckableTest::getPoints() const +{ + return m_items.getPoints(); +} diff --git a/source/CheckableTest/CheckableTest.h b/source/CheckableTest/CheckableTest.h index 32f6da0..f4a0c20 100644 --- a/source/CheckableTest/CheckableTest.h +++ b/source/CheckableTest/CheckableTest.h @@ -17,6 +17,8 @@ public: const QString &name() const; const CheckableItems &items() const; CheckableItems &items(); + + unsigned int getPoints() const; }; using CheckableTests = std::vector; diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 493bd76..c0a60a1 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -107,30 +107,6 @@ QVariant CheckableTestModel::headerData( return QAbstractTableModel::headerData(section, orientation, role); } -void CheckableTestModel::write(QJsonObject &json) const -{ - for (const auto &test : m_tests) - { - QJsonArray testData; - test.items().write(testData); - json[test.name()] = testData; - } -} - -void CheckableTestModel::read(const QJsonObject &json) -{ - for (auto &test : m_tests) - { - auto testData = json[test.name()]; - if (testData.isArray()) - { - test.items().read(testData.toArray()); - } - } - - emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); -} - bool CheckableTestModel::isValidIndex(const QModelIndex &index) const { if (index.row() < m_tests.size()) @@ -190,10 +166,7 @@ unsigned int CheckableTestModel::getPoints() const for (const auto &test : m_tests) { - for (const auto &item : test.items()) - { - points += item.points(); - } + points += test.getPoints(); } return points; diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 7b4ed9d..2fd5434 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -25,9 +25,6 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - void write(QJsonObject &json) const; - void read(const QJsonObject &json); - unsigned int getPoints() const; protected: diff --git a/source/DataModel.cpp b/source/DataModel.cpp index b49039a..4ac4ffb 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -64,12 +64,21 @@ void DataModel::printTo(QTextCursor &cursor) const { QTextCharFormat titleFormat; titleFormat.setFontPointSize(18); + cursor.insertText("ESGRAF 4-8 Auswertungsbogen", titleFormat); cursor.insertText("\n", titleFormat); m_metaData.printTo(cursor); cursor.insertText("\n", titleFormat); + m_v2Svk.printTo(cursor); + cursor.insertText("\n", titleFormat); + + m_verbEnd.printTo(cursor); + cursor.insertText("\n", titleFormat); + + //m_results.printTo(cursor); + //cursor.insertText("\n", titleFormat); } void DataModel::pluralModelChanged() diff --git a/source/ResultWidget/CMakeLists.txt b/source/ResultWidget/CMakeLists.txt index bfdd22c..9e70573 100644 --- a/source/ResultWidget/CMakeLists.txt +++ b/source/ResultWidget/CMakeLists.txt @@ -12,6 +12,7 @@ qt5_wrap_ui(GENUS_UI add_library(${PROJECT_NAME} ResultWidget.cpp + TestResult.cpp ResultModel.cpp PRMap.cpp ${GENUS_UI} diff --git a/source/ResultWidget/ResultModel.cpp b/source/ResultWidget/ResultModel.cpp index c905346..bd6cbf6 100644 --- a/source/ResultWidget/ResultModel.cpp +++ b/source/ResultWidget/ResultModel.cpp @@ -210,3 +210,23 @@ void ResultModel::setGenitivResult(unsigned int points) emit dataChanged(index(0, 7), index(4, 7)); } } + +void ResultModel::printTo(QTextCursor &cursor) const +{ + cursor.insertBlock(); + + QTextCharFormat headerFormat; + headerFormat.setFontPointSize(12); + cursor.insertText( + "Prozentränge (PR)", + headerFormat); + + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + QTextTable *table = cursor.insertTable(1, 1, tableFormat); + + cursor.movePosition(QTextCursor::NextBlock); +} + diff --git a/source/ResultWidget/ResultModel.h b/source/ResultWidget/ResultModel.h index ae6dd78..31b09ed 100644 --- a/source/ResultWidget/ResultModel.h +++ b/source/ResultWidget/ResultModel.h @@ -1,46 +1,11 @@ #pragma once #include "Age.h" +#include "TestResult.h" + #include +#include -class TestResult -{ -private: - QString m_name; - size_t m_points = 0; - size_t m_pr = 0; - -public: - TestResult(const char *name) - : m_name(name) - { - } - - void setPoints(const size_t &points) - { - m_points = points; - } - - void setPR(const unsigned int &pr) - { - m_pr = pr; - } - - const QString &name() const - { - return m_name; - } - - const size_t points() const - { - return m_points; - } - - const size_t pr() const - { - return m_pr; - } -}; class ResultModel : public QAbstractTableModel { @@ -56,11 +21,10 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; - QVariant data( - const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const override; + int role = Qt::DisplayRole) const override; void setAge(const Age &age); void setPluralResult(unsigned int points); @@ -70,6 +34,8 @@ public: void setDativResult(unsigned int points); void setV2Result(unsigned int points); void setSvkResult(unsigned int points); - void setPassivResult(unsigned int points); - void setGenitivResult(unsigned int points); + void setPassivResult(unsigned int points); + void setGenitivResult(unsigned int points); + + void printTo(QTextCursor &cursor) const; }; diff --git a/source/ResultWidget/TestResult.cpp b/source/ResultWidget/TestResult.cpp new file mode 100644 index 0000000..fb9800b --- /dev/null +++ b/source/ResultWidget/TestResult.cpp @@ -0,0 +1,31 @@ +#include "TestResult.h" + +TestResult::TestResult(const char *name) + : m_name(name) +{ +} + +void TestResult::setPoints(const size_t &points) +{ + m_points = points; +} + +void TestResult::setPR(const unsigned int &pr) +{ + m_pr = pr; +} + +QString TestResult::name() const +{ + return m_name; +} + +size_t TestResult::points() const +{ + return m_points; +} + +size_t TestResult::pr() const +{ + return m_pr; +} diff --git a/source/ResultWidget/TestResult.h b/source/ResultWidget/TestResult.h new file mode 100644 index 0000000..001e210 --- /dev/null +++ b/source/ResultWidget/TestResult.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +class TestResult +{ +private: + QString m_name; + size_t m_points = 0; + size_t m_pr = 0; + +public: + TestResult(const char *name); + + void setPoints(const size_t &points); + void setPR(const unsigned int &pr); + + QString name() const; + size_t points() const; + size_t pr() const; +}; + diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index dea4d95..dce3e76 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -1,15 +1,14 @@ #include "VerbEndModel.h" +#include + VerbEndModel::VerbEndModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { { "Telefonat", - { "Kausal", "Kausal", "Relativ", "Kausal", - "Final", "Temporal", "Temporal" } }, - { "Zaubertrick", { "Relativ", "Final", "Kausal", "Final", - "Temporal", "Kausal", "Temporal" } }, - { "Zauberregel", { "Temporal", "Kausal", "Final", "Relativ", - "Temporal", "Relativ" } } }; + m_tests = { + {"Telefonat", {"Kausal", "Kausal", "Relativ", "Kausal", "Final", "Temporal", "Temporal"}}, + {"Zaubertrick", {"Relativ", "Final", "Kausal", "Final", "Temporal", "Kausal", "Temporal"}}, + {"Zauberregel", {"Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ"}}}; } void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const @@ -98,3 +97,155 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +void VerbEndModel::printTo(QTextCursor &cursor) const +{ + cursor.insertBlock(); + + QTextCharFormat headerFormat; + headerFormat.setFontPointSize(12); + cursor.insertText("Subtest 2: Verbendstellungsregel (VE)", headerFormat); + + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 15), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 2), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 5)}); + + QTextTable *table = cursor.insertTable(6, 13, tableFormat); + table->mergeCells(0, 0, 2, 1); + table->mergeCells(2, 0, 2, 1); + table->mergeCells(4, 0, 2, 1); + + const char *emptyBox = "\u2610"; + //const char *checkBox = "\u2611"; + const char *checkBox = "x"; + + cursor.insertText("Telefonat"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Kausal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Kausal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Relativ"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Kausal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Final"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Temporal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Temporal"); + cursor.movePosition(QTextCursor::NextRow); + + const auto &telTestItems = m_tests.at(0).items(); + cursor.insertText(telTestItems[0].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(telTestItems[1].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(telTestItems[2].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(telTestItems[3].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(telTestItems[4].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(telTestItems[5].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(telTestItems[6].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(QString::number(m_tests.at(0).getPoints())); + cursor.movePosition(QTextCursor::NextRow); + + cursor.insertText("Zaubertrick"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Relativ"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Final"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Kausal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Final"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Temporal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Kausal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Temporal"); + cursor.movePosition(QTextCursor::NextRow); + + const auto &trickTestItems = m_tests.at(1).items(); + cursor.insertText(trickTestItems[0].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(trickTestItems[1].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(trickTestItems[2].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(trickTestItems[3].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(trickTestItems[4].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(trickTestItems[5].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(trickTestItems[6].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(QString::number(m_tests.at(1).getPoints())); + cursor.movePosition(QTextCursor::NextRow); + + cursor.insertText("Zauberregel"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Temporal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Kausal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Final"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Relativ"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Temporal"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Relativ"); + cursor.movePosition(QTextCursor::NextRow); + + const auto ®elTestItems = m_tests.at(2).items(); + cursor.insertText(regelTestItems[0].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(regelTestItems[1].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(regelTestItems[2].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(regelTestItems[3].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(regelTestItems[4].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(regelTestItems[5].isChecked() ? checkBox : emptyBox); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(QString::number(m_tests.at(2).getPoints())); + + cursor.movePosition(QTextCursor::NextBlock); +} + diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index cf6342a..e6a859c 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -3,6 +3,8 @@ #include "CheckableTestModel.h" #include "VerbEndModel.pb.h" +#include + class VerbEndModel : public CheckableTestModel { Q_OBJECT @@ -12,4 +14,6 @@ public: void write(ESGRAF48::VerbEndModel &model) const; void read(const ESGRAF48::VerbEndModel &model); + + void printTo(QTextCursor &cursor) const; }; From 49b52f1dbc0d17bedb8e1c77ea8b53687e284fd9 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 8 Dec 2018 21:02:35 +0100 Subject: [PATCH 05/16] Print subtests 2, 3 and 4 --- source/CheckableTestModel/CMakeLists.txt | 2 + .../CheckableTestModel/CheckableTestModel.cpp | 165 +++++++++++++++--- .../CheckableTestModel/CheckableTestModel.h | 7 + source/DataModel.cpp | 15 +- source/MetaData/MetaDataModel.cpp | 8 +- .../AkkusativDativ/AkkusativModel.cpp | 5 + .../SubTests/AkkusativDativ/AkkusativModel.h | 3 + source/SubTests/AkkusativDativ/DativModel.cpp | 5 + source/SubTests/AkkusativDativ/DativModel.h | 3 + source/SubTests/Genus/GenusModel.cpp | 5 + source/SubTests/Genus/GenusModel.h | 3 + source/SubTests/LateSkills/GenitivModel.cpp | 5 + source/SubTests/LateSkills/GenitivModel.h | 3 + source/SubTests/LateSkills/PassivModel.cpp | 5 + source/SubTests/LateSkills/PassivModel.h | 3 + source/SubTests/Plural/PluralModel.cpp | 5 + source/SubTests/Plural/PluralModel.h | 3 + source/SubTests/V2Svk/V2SvkModel.cpp | 19 +- source/SubTests/V2Svk/V2SvkModel.h | 4 +- source/SubTests/VerbEnd/VerbEndModel.cpp | 153 +--------------- source/SubTests/VerbEnd/VerbEndModel.h | 3 +- 21 files changed, 223 insertions(+), 201 deletions(-) diff --git a/source/CheckableTestModel/CMakeLists.txt b/source/CheckableTestModel/CMakeLists.txt index 2ce7c3b..a9400cf 100644 --- a/source/CheckableTestModel/CMakeLists.txt +++ b/source/CheckableTestModel/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(CheckableTestModel LANGUAGES CXX) find_package(Qt5Core REQUIRED) +find_package(Qt5Gui REQUIRED) add_library(${PROJECT_NAME} CheckableTestModel.cpp @@ -22,4 +23,5 @@ target_link_libraries(${PROJECT_NAME} CheckableItem CheckableTest Qt5::Core + Qt5::Gui ) diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index c0a60a1..5530173 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -2,16 +2,17 @@ #include #include +#include #include CheckableTestModel::CheckableTestModel(QObject *parent) - : QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } int CheckableTestModel::rowCount(const QModelIndex &) const { - return static_cast(m_tests.size()); + return static_cast(m_tests.size()); } int CheckableTestModel::columnCount(const QModelIndex &) const @@ -20,7 +21,7 @@ int CheckableTestModel::columnCount(const QModelIndex &) const for (const auto &test : m_tests) { - columnCount = std::max(columnCount, static_cast(test.size())); + columnCount = std::max(columnCount, static_cast(test.size())); } return columnCount; @@ -37,17 +38,17 @@ QVariant CheckableTestModel::data(const QModelIndex &index, int role) const { auto &item = getItem(index); - switch (role) - { - case Qt::DisplayRole: - { - return item.getText().c_str(); - } - case Qt::CheckStateRole: - { - return item.isChecked() ? Qt::Checked : Qt::Unchecked; - } - } + switch (role) + { + case Qt::DisplayRole: + { + return item.getText().c_str(); + } + case Qt::CheckStateRole: + { + return item.isChecked() ? Qt::Checked : Qt::Unchecked; + } + } } catch (std::runtime_error &e) { @@ -67,8 +68,7 @@ Qt::ItemFlags CheckableTestModel::flags(const QModelIndex &index) const return Qt::NoItemFlags; } -bool CheckableTestModel::setData( - const QModelIndex &index, const QVariant &value, int role) +bool CheckableTestModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!isValidIndex(index)) { @@ -93,8 +93,7 @@ bool CheckableTestModel::setData( return false; } -QVariant CheckableTestModel::headerData( - int section, Qt::Orientation orientation, int role) const +QVariant CheckableTestModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole && orientation == Qt::Vertical) { @@ -104,7 +103,7 @@ QVariant CheckableTestModel::headerData( } } - return QAbstractTableModel::headerData(section, orientation, role); + return QAbstractTableModel::headerData(section, orientation, role); } bool CheckableTestModel::isValidIndex(const QModelIndex &index) const @@ -117,6 +116,129 @@ bool CheckableTestModel::isValidIndex(const QModelIndex &index) const return false; } +void CheckableTestModel::printTo(QTextCursor &cursor) const +{ + QTextCharFormat headerFormat; + headerFormat.setFontPointSize(10); + cursor.insertBlock(); + cursor.insertText("\n"); + cursor.insertText(getName().c_str(), headerFormat); + + printTableTo(cursor); + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + printSummaryTo(cursor); + cursor.movePosition(QTextCursor::End); +} + +void CheckableTestModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 9), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(m_tests.size() * 2, 13, tableFormat); + + const char *emptyBox = "\u2610"; + //const char *checkBox = "\u2611"; + const char *checkBox = "x"; + + auto insertText = [&table](int row, int column, const QString &text) { + auto cell = table->cellAt(row, column); + auto textCursor = cell.firstCursorPosition(); + + auto blockFormat = textCursor.blockFormat(); + blockFormat.setAlignment(Qt::AlignCenter); + textCursor.setBlockFormat(blockFormat); + + auto cellFormat = cell.format(); + cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + cell.setFormat(cellFormat); + + auto charFormat = textCursor.charFormat(); + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + charFormat.setFontPointSize(8); + textCursor.setCharFormat(charFormat); + + textCursor.insertText(text); + }; + + int currentRow = 0; + for (const auto &test : m_tests) + { + table->mergeCells(currentRow, 0, 2, 1); + + int currentColumn = 0; + + insertText(currentRow, currentColumn, test.name()); + currentColumn++; + + for (const auto &item : test.items()) + { + insertText(currentRow, currentColumn, item.getText().c_str()); + insertText(currentRow + 1, currentColumn, item.isChecked() ? checkBox : emptyBox); + + currentColumn++; + } + + insertText(currentRow + 1, 12, QString::number(test.getPoints())); + + currentRow += 2; + } +} + +void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 76), + QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(1, 4, tableFormat); + + auto insertText = [&table](int row, int column, const QString &text) { + auto cell = table->cellAt(row, column); + auto textCursor = cell.firstCursorPosition(); + + auto blockFormat = textCursor.blockFormat(); + blockFormat.setAlignment(Qt::AlignCenter); + textCursor.setBlockFormat(blockFormat); + + auto cellFormat = cell.format(); + cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + cell.setFormat(cellFormat); + + auto charFormat = textCursor.charFormat(); + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + charFormat.setFontPointSize(8); + textCursor.setCharFormat(charFormat); + + textCursor.insertText(text); + }; + + insertText(0, 1, "Rohwertpunkte Total:"); + insertText(0, 3, QString::number(getPoints())); +} + CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) { if (index.row() < m_tests.size()) @@ -127,8 +249,7 @@ CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) throw std::runtime_error("invalid index"); } -const CheckableItems &CheckableTestModel::getItems( - const QModelIndex &index) const +const CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) const { if (index.row() < m_tests.size()) { @@ -162,7 +283,7 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const unsigned int CheckableTestModel::getPoints() const { - unsigned int points = 0; + unsigned int points = 0; for (const auto &test : m_tests) { diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 2fd5434..8f54220 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -2,6 +2,7 @@ #include "CheckableTest.h" #include +#include class CheckableTestModel : public QAbstractTableModel { @@ -27,9 +28,15 @@ public: unsigned int getPoints() const; + virtual void printTo(QTextCursor &cursor) const; + protected: virtual bool isValidIndex(const QModelIndex &index) const; + virtual std::string getName() const = 0; + void printTableTo(QTextCursor &cursor) const; + void printSummaryTo(QTextCursor &cursor) const; + private: CheckableItems &getItems(const QModelIndex &index); const CheckableItems &getItems(const QModelIndex &index) const; diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 4ac4ffb..adebf86 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -63,22 +63,23 @@ void DataModel::read(std::istream &inStream) void DataModel::printTo(QTextCursor &cursor) const { QTextCharFormat titleFormat; - titleFormat.setFontPointSize(18); + titleFormat.setFontPointSize(14); cursor.insertText("ESGRAF 4-8 Auswertungsbogen", titleFormat); cursor.insertText("\n", titleFormat); m_metaData.printTo(cursor); - cursor.insertText("\n", titleFormat); - - m_v2Svk.printTo(cursor); - cursor.insertText("\n", titleFormat); + //m_v2Svk.printTo(cursor); m_verbEnd.printTo(cursor); - cursor.insertText("\n", titleFormat); + m_genus.printTo(cursor); + m_akkusativ.printTo(cursor); + m_dativ.printTo(cursor); + //m_plural.printTo(cursor); + //m_genitiv.printTo(cursor); + //m_passiv.printTo(cursor); //m_results.printTo(cursor); - //cursor.insertText("\n", titleFormat); } void DataModel::pluralModelChanged() diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index c6ef6dd..7f3769a 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -136,6 +136,7 @@ void MetaDataModel::printTo(QTextCursor &cursor) const cursor.insertBlock(); QTextTableFormat tableFormat; + tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_None); tableFormat.setCellPadding(2); tableFormat.setCellSpacing(0); @@ -161,7 +162,10 @@ void MetaDataModel::printTo(QTextCursor &cursor) const cursor.movePosition(QTextCursor::NextCell); cursor.insertText(m_dateOfBirth.toString("dd.MM.yyyy")); cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Bemerkungen:"); + if (!m_remarks.trimmed().isEmpty()) + { + cursor.insertText("Bemerkungen:"); + } cursor.movePosition(QTextCursor::NextRow); cursor.insertText("Untersuchungsdatum"); @@ -175,6 +179,6 @@ void MetaDataModel::printTo(QTextCursor &cursor) const cursor.movePosition(QTextCursor::NextCell); cursor.insertText(getAge().toString().c_str()); - cursor.movePosition(QTextCursor::NextBlock); + cursor.movePosition(QTextCursor::End); } diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.cpp b/source/SubTests/AkkusativDativ/AkkusativModel.cpp index 79d2c31..b481c50 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.cpp +++ b/source/SubTests/AkkusativDativ/AkkusativModel.cpp @@ -105,3 +105,8 @@ void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const futterModel->set_zucker(testItems[7].isChecked()); } } + +std::string AkkusativModel::getName() const +{ + return "Subtest 4: Akkusativ und Dativ"; +} diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.h b/source/SubTests/AkkusativDativ/AkkusativModel.h index 43a4881..ae9d2f2 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.h +++ b/source/SubTests/AkkusativDativ/AkkusativModel.h @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::AkkusativModel &model); void write(ESGRAF48::AkkusativModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index 081dfdb..1948370 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -105,3 +105,8 @@ void DativModel::write(ESGRAF48::DativModel &model) const futterModel->set_zucker(testItems[7].isChecked()); } } + +std::string DativModel::getName() const +{ + return ""; +} diff --git a/source/SubTests/AkkusativDativ/DativModel.h b/source/SubTests/AkkusativDativ/DativModel.h index 6a9a323..97b7a59 100644 --- a/source/SubTests/AkkusativDativ/DativModel.h +++ b/source/SubTests/AkkusativDativ/DativModel.h @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::DativModel &model); void write(ESGRAF48::DativModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index 3f2278b..b708ee7 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -95,3 +95,8 @@ void GenusModel::write(ESGRAF48::GenusModel &model) const zirkusModel->set_baum(testItems[3].isChecked()); } } + +std::string GenusModel::getName() const +{ + return "Subtest 3: Genus"; +} diff --git a/source/SubTests/Genus/GenusModel.h b/source/SubTests/Genus/GenusModel.h index 8261779..590873d 100644 --- a/source/SubTests/Genus/GenusModel.h +++ b/source/SubTests/Genus/GenusModel.h @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::GenusModel &model); void write(ESGRAF48::GenusModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/LateSkills/GenitivModel.cpp b/source/SubTests/LateSkills/GenitivModel.cpp index 9ebf423..ee0b8a5 100644 --- a/source/SubTests/LateSkills/GenitivModel.cpp +++ b/source/SubTests/LateSkills/GenitivModel.cpp @@ -107,3 +107,8 @@ void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel &model) const attributierungModel->set_guertel2(testItems[9].isChecked()); } } + +std::string GenitivModel::getName() const +{ + return ""; +} diff --git a/source/SubTests/LateSkills/GenitivModel.h b/source/SubTests/LateSkills/GenitivModel.h index 2346e94..1ba63c3 100644 --- a/source/SubTests/LateSkills/GenitivModel.h +++ b/source/SubTests/LateSkills/GenitivModel.h @@ -14,4 +14,7 @@ public: void read(const ESGRAF48::LateSkillsGenitivModel &model); void write(ESGRAF48::LateSkillsGenitivModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/LateSkills/PassivModel.cpp b/source/SubTests/LateSkills/PassivModel.cpp index 6f1d3a8..88399c6 100644 --- a/source/SubTests/LateSkills/PassivModel.cpp +++ b/source/SubTests/LateSkills/PassivModel.cpp @@ -65,3 +65,8 @@ void PassivModel::write(ESGRAF48::LateSkillsPassivModel &model) const model.set_fleisch1(testItems[8].isChecked()); model.set_fleisch2(testItems[9].isChecked()); } + +std::string PassivModel::getName() const +{ + return "Subtest 6: Späte Fähigkeiten (7;0 - 8;11)"; +} diff --git a/source/SubTests/LateSkills/PassivModel.h b/source/SubTests/LateSkills/PassivModel.h index e0671bb..90e93ca 100644 --- a/source/SubTests/LateSkills/PassivModel.h +++ b/source/SubTests/LateSkills/PassivModel.h @@ -14,4 +14,7 @@ public: void read(const ESGRAF48::LateSkillsPassivModel &model); void write(ESGRAF48::LateSkillsPassivModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index 0ade859..f7a5e2e 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -51,3 +51,8 @@ void PluralModel::write(ESGRAF48::PluralModel &model) const model.set_baer(testItems[7].isChecked()); model.set_apfel(testItems[8].isChecked()); } + +std::string PluralModel::getName() const +{ + return "Subtest 5: Plural"; +} diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index cadeae9..60d0ae8 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -15,4 +15,7 @@ public: void read(const ESGRAF48::PluralModel &model); void write(ESGRAF48::PluralModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index cdf7596..755eacd 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -200,22 +200,7 @@ void V2SvkModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } -void V2SvkModel::printTo(QTextCursor &cursor) const +std::string V2SvkModel::getName() const { - cursor.insertBlock(); - - QTextCharFormat headerFormat; - headerFormat.setFontPointSize(12); - cursor.insertText( - "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)", - headerFormat); - - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); - - QTextTable *table = cursor.insertTable(1, 1, tableFormat); - - cursor.movePosition(QTextCursor::NextBlock); + return "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"; } - diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index 6b070d8..ec54a81 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -18,8 +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; + + std::string getName() const override; }; diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index dce3e76..89d9a70 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -98,154 +98,7 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } -void VerbEndModel::printTo(QTextCursor &cursor) const +std::string VerbEndModel::getName() const { - cursor.insertBlock(); - - QTextCharFormat headerFormat; - headerFormat.setFontPointSize(12); - cursor.insertText("Subtest 2: Verbendstellungsregel (VE)", headerFormat); - - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); - - tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 15), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 9), - QTextLength(QTextLength::PercentageLength, 2), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 1), - QTextLength(QTextLength::PercentageLength, 5)}); - - QTextTable *table = cursor.insertTable(6, 13, tableFormat); - table->mergeCells(0, 0, 2, 1); - table->mergeCells(2, 0, 2, 1); - table->mergeCells(4, 0, 2, 1); - - const char *emptyBox = "\u2610"; - //const char *checkBox = "\u2611"; - const char *checkBox = "x"; - - cursor.insertText("Telefonat"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Kausal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Kausal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Relativ"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Kausal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Final"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Temporal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Temporal"); - cursor.movePosition(QTextCursor::NextRow); - - const auto &telTestItems = m_tests.at(0).items(); - cursor.insertText(telTestItems[0].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(telTestItems[1].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(telTestItems[2].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(telTestItems[3].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(telTestItems[4].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(telTestItems[5].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(telTestItems[6].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(QString::number(m_tests.at(0).getPoints())); - cursor.movePosition(QTextCursor::NextRow); - - cursor.insertText("Zaubertrick"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Relativ"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Final"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Kausal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Final"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Temporal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Kausal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Temporal"); - cursor.movePosition(QTextCursor::NextRow); - - const auto &trickTestItems = m_tests.at(1).items(); - cursor.insertText(trickTestItems[0].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(trickTestItems[1].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(trickTestItems[2].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(trickTestItems[3].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(trickTestItems[4].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(trickTestItems[5].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(trickTestItems[6].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(QString::number(m_tests.at(1).getPoints())); - cursor.movePosition(QTextCursor::NextRow); - - cursor.insertText("Zauberregel"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Temporal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Kausal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Final"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Relativ"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Temporal"); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText("Relativ"); - cursor.movePosition(QTextCursor::NextRow); - - const auto ®elTestItems = m_tests.at(2).items(); - cursor.insertText(regelTestItems[0].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(regelTestItems[1].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(regelTestItems[2].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(regelTestItems[3].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(regelTestItems[4].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(regelTestItems[5].isChecked() ? checkBox : emptyBox); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.movePosition(QTextCursor::NextCell); - cursor.insertText(QString::number(m_tests.at(2).getPoints())); - - cursor.movePosition(QTextCursor::NextBlock); -} - + return "Subtest 2: Verbendstellungsregel (VE)"; +}; diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index e6a859c..10b4b1e 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -15,5 +15,6 @@ public: void write(ESGRAF48::VerbEndModel &model) const; void read(const ESGRAF48::VerbEndModel &model); - void printTo(QTextCursor &cursor) const; +protected: + std::string getName() const override; }; From c065b04cbe37e21a7b02db910191dc529925278a Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 9 Dec 2018 11:27:13 +0100 Subject: [PATCH 06/16] Use std::accumulate instead of manually adding --- source/CheckableTestModel/CheckableTestModel.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 5530173..35d1579 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -174,7 +174,7 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); charFormat.setFontPointSize(8); textCursor.setCharFormat(charFormat); - + textCursor.insertText(text); }; @@ -201,7 +201,7 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const currentRow += 2; } } - + void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const { QTextTableFormat tableFormat; @@ -231,7 +231,7 @@ void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); charFormat.setFontPointSize(8); textCursor.setCharFormat(charFormat); - + textCursor.insertText(text); }; @@ -283,12 +283,6 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const unsigned int CheckableTestModel::getPoints() const { - unsigned int points = 0; - - for (const auto &test : m_tests) - { - points += test.getPoints(); - } - - return points; + return std::accumulate(std::begin(m_tests), std::end(m_tests), 0, + [](int base, const CheckableTest &test) { return base + test.getPoints(); }); } From 2570d5d5b54753f585f9f24bd7d044f0cb48fea2 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 9 Dec 2018 12:49:12 +0100 Subject: [PATCH 07/16] Print results --- source/DataModel.cpp | 2 +- source/ResultWidget/ResultModel.cpp | 109 +++++++++++++++++++++------- source/ResultWidget/ResultModel.h | 1 - 3 files changed, 82 insertions(+), 30 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index adebf86..9f2b3c4 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -79,7 +79,7 @@ void DataModel::printTo(QTextCursor &cursor) const //m_genitiv.printTo(cursor); //m_passiv.printTo(cursor); - //m_results.printTo(cursor); + m_results.printTo(cursor); } void DataModel::pluralModelChanged() diff --git a/source/ResultWidget/ResultModel.cpp b/source/ResultWidget/ResultModel.cpp index bd6cbf6..02fab59 100644 --- a/source/ResultWidget/ResultModel.cpp +++ b/source/ResultWidget/ResultModel.cpp @@ -10,13 +10,13 @@ #include "PassivPR.h" #include "GenitivPR.h" +#include #include ResultModel::ResultModel(QObject *parent) - : QAbstractTableModel(parent) + : QAbstractTableModel(parent) { - m_results = { { "V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", - "Genitiv", "Plural" } }; + m_results = {"V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural"}; } int ResultModel::rowCount(const QModelIndex &parent) const @@ -81,8 +81,7 @@ QVariant ResultModel::data(const QModelIndex &index, int role) const return {}; } -QVariant ResultModel::headerData( - int section, Qt::Orientation orientation, int role) const +QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) { @@ -102,11 +101,11 @@ QVariant ResultModel::headerData( case 0: return "RP"; case 1: - return ">= PR 84"; + return "\u2265 PR 84"; case 2: return "< PR 84"; case 3: - return "<= PR 16"; + return "\u2264 PR 16"; default: return {}; } @@ -170,7 +169,7 @@ void ResultModel::setDativResult(unsigned int points) emit dataChanged(index(0, 6), index(4, 6)); } } - + void ResultModel::setV2Result(unsigned int points) { if (m_results[0].points() != points) @@ -193,40 +192,94 @@ void ResultModel::setSvkResult(unsigned int points) void ResultModel::setPassivResult(unsigned int points) { - if (m_results[3].points() != points) - { - m_results[3].setPoints(points); - m_results[3].setPR(PassivPR().lookup(m_age, points)); - emit dataChanged(index(0, 3), index(4, 3)); - } + if (m_results[3].points() != points) + { + m_results[3].setPoints(points); + m_results[3].setPR(PassivPR().lookup(m_age, points)); + emit dataChanged(index(0, 3), index(4, 3)); + } } void ResultModel::setGenitivResult(unsigned int points) { - if (m_results[7].points() != points) - { - m_results[7].setPoints(points); - m_results[7].setPR(GenitivPR().lookup(m_age, points)); - emit dataChanged(index(0, 7), index(4, 7)); - } + if (m_results[7].points() != points) + { + m_results[7].setPoints(points); + m_results[7].setPR(GenitivPR().lookup(m_age, points)); + emit dataChanged(index(0, 7), index(4, 7)); + } } void ResultModel::printTo(QTextCursor &cursor) const { - cursor.insertBlock(); - QTextCharFormat headerFormat; - headerFormat.setFontPointSize(12); - cursor.insertText( - "Prozentränge (PR)", - headerFormat); + headerFormat.setFontPointSize(10); + cursor.insertBlock(); + cursor.insertText("\nProzentränge (PR)"); QTextTableFormat tableFormat; tableFormat.setCellPadding(2); tableFormat.setCellSpacing(0); - QTextTable *table = cursor.insertTable(1, 1, tableFormat); + const unsigned int columnCount = 10; - cursor.movePosition(QTextCursor::NextBlock); + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10)}); + + QTextTable *table = cursor.insertTable(4, columnCount, tableFormat); + + auto insertText = [&table](int row, int column, const QString &text) { + auto cell = table->cellAt(row, column); + auto textCursor = cell.firstCursorPosition(); + + auto blockFormat = textCursor.blockFormat(); + blockFormat.setAlignment(Qt::AlignCenter); + textCursor.setBlockFormat(blockFormat); + + auto cellFormat = cell.format(); + cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + + if (row == 3) + { + QBrush backgroundBrush(QColor(192, 192, 192)); + cellFormat.setBackground(backgroundBrush); + } + + cell.setFormat(cellFormat); + + auto charFormat = textCursor.charFormat(); + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + charFormat.setFontPointSize(8); + + if (row == 0 || column == 0) + { + charFormat.setFontWeight(QFont::Bold); + } + + textCursor.setCharFormat(charFormat); + + textCursor.insertText(text); + }; + + insertText(1, 0, "\u2265 PR 84"); + insertText(2, 0, "< PR 84"); + insertText(3, 0, "\u2264 PR 16"); + + for (size_t index = 0; index < m_results.size(); ++index) + { + insertText(0, index + 1, m_results[index].name()); + int pr = m_results[index].pr(); + insertText(1, index + 1, pr >= 84 ? QString::number(pr) : "-"); + insertText(2, index + 1, pr < 84 && pr > 16 ? QString::number(pr) : "-"); + insertText(3, index + 1, pr <= 16 ? QString::number(pr) : "-"); + } } diff --git a/source/ResultWidget/ResultModel.h b/source/ResultWidget/ResultModel.h index 31b09ed..67d2692 100644 --- a/source/ResultWidget/ResultModel.h +++ b/source/ResultWidget/ResultModel.h @@ -6,7 +6,6 @@ #include #include - class ResultModel : public QAbstractTableModel { Q_OBJECT From f6c2da5edc59fb567d5c314d882bdd29c66ce809 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 10 Dec 2018 21:11:46 +0100 Subject: [PATCH 08/16] Implemented plural-test printing --- .../CheckableTestModel/CheckableTestModel.cpp | 77 ++++++++----------- .../CheckableTestModel/CheckableTestModel.h | 8 +- source/DataModel.cpp | 2 +- source/SubTests/Plural/PluralModel.cpp | 39 ++++++++++ source/SubTests/Plural/PluralModel.h | 2 + 5 files changed, 78 insertions(+), 50 deletions(-) diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 35d1579..fc5a4ab 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -154,30 +154,6 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const QTextTable *table = cursor.insertTable(m_tests.size() * 2, 13, tableFormat); - const char *emptyBox = "\u2610"; - //const char *checkBox = "\u2611"; - const char *checkBox = "x"; - - auto insertText = [&table](int row, int column, const QString &text) { - auto cell = table->cellAt(row, column); - auto textCursor = cell.firstCursorPosition(); - - auto blockFormat = textCursor.blockFormat(); - blockFormat.setAlignment(Qt::AlignCenter); - textCursor.setBlockFormat(blockFormat); - - auto cellFormat = cell.format(); - cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - cell.setFormat(cellFormat); - - auto charFormat = textCursor.charFormat(); - charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - charFormat.setFontPointSize(8); - textCursor.setCharFormat(charFormat); - - textCursor.insertText(text); - }; - int currentRow = 0; for (const auto &test : m_tests) { @@ -185,18 +161,18 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const int currentColumn = 0; - insertText(currentRow, currentColumn, test.name()); + setCellText(*table, currentRow, currentColumn, test.name()); currentColumn++; for (const auto &item : test.items()) { - insertText(currentRow, currentColumn, item.getText().c_str()); - insertText(currentRow + 1, currentColumn, item.isChecked() ? checkBox : emptyBox); + setCellText(*table, currentRow, currentColumn, item.getText().c_str()); + setCellChecked(*table, currentRow + 1, currentColumn, item.isChecked()); currentColumn++; } - insertText(currentRow + 1, 12, QString::number(test.getPoints())); + setCellText(*table, currentRow + 1, 12, QString::number(test.getPoints())); currentRow += 2; } @@ -215,28 +191,34 @@ void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const QTextTable *table = cursor.insertTable(1, 4, tableFormat); - auto insertText = [&table](int row, int column, const QString &text) { - auto cell = table->cellAt(row, column); - auto textCursor = cell.firstCursorPosition(); + setCellText(*table, 0, 1, "Rohwertpunkte Total:"); + setCellText(*table, 0, 3, QString::number(getPoints())); +} - auto blockFormat = textCursor.blockFormat(); - blockFormat.setAlignment(Qt::AlignCenter); - textCursor.setBlockFormat(blockFormat); +void CheckableTestModel::setCellText(QTextTable &table, int row, int column, const QString &text) +{ + auto cell = table.cellAt(row, column); + auto textCursor = cell.firstCursorPosition(); - auto cellFormat = cell.format(); - cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - cell.setFormat(cellFormat); + auto blockFormat = textCursor.blockFormat(); + blockFormat.setAlignment(Qt::AlignCenter); + textCursor.setBlockFormat(blockFormat); - auto charFormat = textCursor.charFormat(); - charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - charFormat.setFontPointSize(8); - textCursor.setCharFormat(charFormat); + auto cellFormat = cell.format(); + cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + cell.setFormat(cellFormat); - textCursor.insertText(text); - }; + auto charFormat = textCursor.charFormat(); + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + charFormat.setFontPointSize(8); + textCursor.setCharFormat(charFormat); - insertText(0, 1, "Rohwertpunkte Total:"); - insertText(0, 3, QString::number(getPoints())); + textCursor.insertText(text); +} + +void CheckableTestModel::setCellChecked(QTextTable &table, int row, int column, bool check) +{ + setCellText(table, row, column, check ? "x" : "\u2610"); } CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) @@ -283,6 +265,7 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const unsigned int CheckableTestModel::getPoints() const { - return std::accumulate(std::begin(m_tests), std::end(m_tests), 0, - [](int base, const CheckableTest &test) { return base + test.getPoints(); }); + return std::accumulate( + std::begin(m_tests), std::end(m_tests), 0, + [](int base, const CheckableTest &test) { return base + test.getPoints(); }); } diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 8f54220..1db2880 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -34,8 +34,12 @@ protected: virtual bool isValidIndex(const QModelIndex &index) const; virtual std::string getName() const = 0; - void printTableTo(QTextCursor &cursor) const; - void printSummaryTo(QTextCursor &cursor) const; + + virtual void printTableTo(QTextCursor &cursor) const; + virtual void printSummaryTo(QTextCursor &cursor) const; + + static void setCellText(QTextTable &table, int row, int column, const QString &text); + static void setCellChecked(QTextTable &table, int row, int column, bool check); private: CheckableItems &getItems(const QModelIndex &index); diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 9f2b3c4..20398be 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -75,7 +75,7 @@ void DataModel::printTo(QTextCursor &cursor) const m_genus.printTo(cursor); m_akkusativ.printTo(cursor); m_dativ.printTo(cursor); - //m_plural.printTo(cursor); + m_plural.printTo(cursor); //m_genitiv.printTo(cursor); //m_passiv.printTo(cursor); diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index f7a5e2e..bc407dc 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -1,6 +1,10 @@ #include "PluralModel.h" #include +#include +#include + +#include PluralModel::PluralModel(QObject *parent) : CheckableTestModel(parent) @@ -56,3 +60,38 @@ std::string PluralModel::getName() const { return "Subtest 5: Plural"; } + +void PluralModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10)}); + + QTextTable *table = cursor.insertTable(2, 10, tableFormat); + + const auto &test = m_tests.front(); + + int currentColumn = 0; + for (const auto &item : test.items()) + { + std::string itemName = std::regex_replace(item.getText(), std::regex("\\s"), "\n", + std::regex_constants::format_first_only); + + setCellText(*table, 0, currentColumn, itemName.c_str()); + setCellChecked(*table, 1, currentColumn, item.isChecked()); + + currentColumn++; + } +} + diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index 60d0ae8..cfa977f 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -18,4 +18,6 @@ public: protected: std::string getName() const override; + + void printTableTo(QTextCursor &cursor) const override; }; From 98196e05d6a87196d59890f5354990e6ae8a7083 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 10 Dec 2018 22:29:49 +0100 Subject: [PATCH 09/16] Implemented printing for late skills tests --- .../CheckableTestModel/CheckableTestModel.cpp | 4 +- .../CheckableTestModel/CheckableTestModel.h | 6 ++ source/DataModel.cpp | 5 +- source/SubTests/LateSkills/CMakeLists.txt | 1 + source/SubTests/LateSkills/GenitivModel.cpp | 2 +- source/SubTests/LateSkills/GenitivModel.h | 4 +- .../SubTests/LateSkills/LateSkillsModel.cpp | 67 +++++++++++++++++++ source/SubTests/LateSkills/LateSkillsModel.h | 14 ++++ source/SubTests/LateSkills/PassivModel.cpp | 2 +- source/SubTests/LateSkills/PassivModel.h | 4 +- source/SubTests/Plural/PluralModel.cpp | 2 +- 11 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 source/SubTests/LateSkills/LateSkillsModel.cpp create mode 100644 source/SubTests/LateSkills/LateSkillsModel.h diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index fc5a4ab..00da00c 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -172,7 +172,7 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const currentColumn++; } - setCellText(*table, currentRow + 1, 12, QString::number(test.getPoints())); + setCellNumber(*table, currentRow + 1, 12, test.getPoints()); currentRow += 2; } @@ -192,7 +192,7 @@ void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const QTextTable *table = cursor.insertTable(1, 4, tableFormat); setCellText(*table, 0, 1, "Rohwertpunkte Total:"); - setCellText(*table, 0, 3, QString::number(getPoints())); + setCellNumber(*table, 0, 3, getPoints()); } void CheckableTestModel::setCellText(QTextTable &table, int row, int column, const QString &text) diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 1db2880..4389e04 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -41,6 +41,12 @@ protected: static void setCellText(QTextTable &table, int row, int column, const QString &text); static void setCellChecked(QTextTable &table, int row, int column, bool check); + template + static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number) + { + setCellText(table, row, column, QString::number(number)); + } + private: CheckableItems &getItems(const QModelIndex &index); const CheckableItems &getItems(const QModelIndex &index) const; diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 20398be..4bd4df9 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -75,9 +75,10 @@ void DataModel::printTo(QTextCursor &cursor) const m_genus.printTo(cursor); m_akkusativ.printTo(cursor); m_dativ.printTo(cursor); + m_plural.printTo(cursor); - //m_genitiv.printTo(cursor); - //m_passiv.printTo(cursor); + m_passiv.printTo(cursor); + m_genitiv.printTo(cursor); m_results.printTo(cursor); } diff --git a/source/SubTests/LateSkills/CMakeLists.txt b/source/SubTests/LateSkills/CMakeLists.txt index 7fef071..3a72146 100644 --- a/source/SubTests/LateSkills/CMakeLists.txt +++ b/source/SubTests/LateSkills/CMakeLists.txt @@ -22,6 +22,7 @@ protobuf_generate_cpp(LateSkills_PROTO_SRCS LateSkills_PROTO_HDRS add_library(${PROJECT_NAME} LateSkillsWidget.cpp + LateSkillsModel.cpp PassivModel.cpp GenitivModel.cpp ${UI_HEADERS} diff --git a/source/SubTests/LateSkills/GenitivModel.cpp b/source/SubTests/LateSkills/GenitivModel.cpp index ee0b8a5..ffff088 100644 --- a/source/SubTests/LateSkills/GenitivModel.cpp +++ b/source/SubTests/LateSkills/GenitivModel.cpp @@ -1,7 +1,7 @@ #include "GenitivModel.h" GenitivModel::GenitivModel(QObject *parent) - : CheckableTestModel(parent) + : LateSkillsModel(parent) { m_tests = { {"Genitiv Präpositionen", diff --git a/source/SubTests/LateSkills/GenitivModel.h b/source/SubTests/LateSkills/GenitivModel.h index 1ba63c3..809b26e 100644 --- a/source/SubTests/LateSkills/GenitivModel.h +++ b/source/SubTests/LateSkills/GenitivModel.h @@ -1,9 +1,9 @@ #pragma once -#include "CheckableTestModel.h" +#include "LateSkillsModel.h" #include "LateSkillsGenitivModel.pb.h" -class GenitivModel : public CheckableTestModel +class GenitivModel : public LateSkillsModel { Q_OBJECT diff --git a/source/SubTests/LateSkills/LateSkillsModel.cpp b/source/SubTests/LateSkills/LateSkillsModel.cpp new file mode 100644 index 0000000..74a824f --- /dev/null +++ b/source/SubTests/LateSkills/LateSkillsModel.cpp @@ -0,0 +1,67 @@ +#include "LateSkillsModel.h" + +#include + +#include + +LateSkillsModel::LateSkillsModel(QObject *parent) + : CheckableTestModel(parent) +{ +} + +void LateSkillsModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 26), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(m_tests.size() * 3, 14, tableFormat); + + int currentRow = 0; + for (const auto &test : m_tests) + { + table->mergeCells(currentRow, 0, 3, 1); + + int currentColumn = 0; + + setCellText(*table, currentRow, currentColumn, test.name()); + currentColumn++; + + for (auto it = std::begin(test.items()); it != std::end(test.items()); std::advance(it, 2)) + { + const auto &item = *it; + const auto &nextItem = *std::next(it); + + table->mergeCells(currentRow, currentColumn, 1, 2); + + auto itemName = std::regex_replace(item.getText(), std::regex(R"((\S+).*)"), "$1"); + + setCellText(*table, currentRow, currentColumn, itemName.c_str()); + setCellText(*table, currentRow + 1, currentColumn, "1"); + setCellText(*table, currentRow + 1, currentColumn + 1, "2"); + setCellChecked(*table, currentRow + 2, currentColumn, item.isChecked()); + setCellChecked(*table, currentRow + 2, currentColumn + 1, nextItem.isChecked()); + + currentColumn += 2; + } + + setCellNumber(*table, currentRow + 2, 13, test.getPoints()); + + currentRow += 3; + } +} diff --git a/source/SubTests/LateSkills/LateSkillsModel.h b/source/SubTests/LateSkills/LateSkillsModel.h new file mode 100644 index 0000000..a891813 --- /dev/null +++ b/source/SubTests/LateSkills/LateSkillsModel.h @@ -0,0 +1,14 @@ +#pragma once + +#include "CheckableTestModel.h" + +class LateSkillsModel : public CheckableTestModel +{ + Q_OBJECT + +public: + LateSkillsModel(QObject *parent); + +protected: + void printTableTo(QTextCursor &cursor) const override; +}; diff --git a/source/SubTests/LateSkills/PassivModel.cpp b/source/SubTests/LateSkills/PassivModel.cpp index 88399c6..ceca388 100644 --- a/source/SubTests/LateSkills/PassivModel.cpp +++ b/source/SubTests/LateSkills/PassivModel.cpp @@ -1,7 +1,7 @@ #include "PassivModel.h" PassivModel::PassivModel(QObject *parent) - : CheckableTestModel(parent) + : LateSkillsModel(parent) { m_tests = {{"Passiv", {"Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", "Bälle (2)", diff --git a/source/SubTests/LateSkills/PassivModel.h b/source/SubTests/LateSkills/PassivModel.h index 90e93ca..c9fdb3f 100644 --- a/source/SubTests/LateSkills/PassivModel.h +++ b/source/SubTests/LateSkills/PassivModel.h @@ -1,9 +1,9 @@ #pragma once -#include "CheckableTestModel.h" +#include "LateSkillsModel.h" #include "LateSkillsPassivModel.pb.h" -class PassivModel : public CheckableTestModel +class PassivModel : public LateSkillsModel { Q_OBJECT diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index bc407dc..1bd733c 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -60,7 +60,7 @@ std::string PluralModel::getName() const { return "Subtest 5: Plural"; } - + void PluralModel::printTableTo(QTextCursor &cursor) const { QTextTableFormat tableFormat; From 8ef56f1855d7448bc0b655973ff1198afb944d59 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 12 Dec 2018 21:33:44 +0100 Subject: [PATCH 10/16] Display causal sentence point count below subtest 2 --- source/SubTests/VerbEnd/VerbEndModel.cpp | 27 ++++++++++++++++++++++ source/SubTests/VerbEnd/VerbEndModel.h | 8 +++++++ source/SubTests/VerbEnd/VerbEndWidget.cpp | 7 ++++++ source/SubTests/VerbEnd/VerbEndWidget.h | 3 +++ source/SubTests/VerbEnd/VerbEndWidget.ui | 28 +++++++++++++++++++++-- 5 files changed, 71 insertions(+), 2 deletions(-) diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index 89d9a70..87a17fc 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -1,6 +1,7 @@ #include "VerbEndModel.h" #include +#include VerbEndModel::VerbEndModel(QObject *parent) : CheckableTestModel(parent) @@ -9,6 +10,8 @@ VerbEndModel::VerbEndModel(QObject *parent) {"Telefonat", {"Kausal", "Kausal", "Relativ", "Kausal", "Final", "Temporal", "Temporal"}}, {"Zaubertrick", {"Relativ", "Final", "Kausal", "Final", "Temporal", "Kausal", "Temporal"}}, {"Zauberregel", {"Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ"}}}; + + connect(this, &VerbEndModel::dataChanged, this, &VerbEndModel::modelChanged); } void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const @@ -98,7 +101,31 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } +unsigned int VerbEndModel::getCausalPoints() const +{ + unsigned int points = 0; + + for (const auto &test : m_tests) + { + for (const auto &item : test.items()) + { + if (item.getText() == "Kausal") + { + points += item.points(); + } + } + } + + return points; +} + +void VerbEndModel::modelChanged() +{ + emit causalPointsChanged(getCausalPoints()); +} + std::string VerbEndModel::getName() const { return "Subtest 2: Verbendstellungsregel (VE)"; }; + diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index 10b4b1e..411d455 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -15,6 +15,14 @@ public: void write(ESGRAF48::VerbEndModel &model) const; void read(const ESGRAF48::VerbEndModel &model); + unsigned int getCausalPoints() const; + protected: std::string getName() const override; + +private slots: + void modelChanged(); + +signals: + void causalPointsChanged(unsigned int points); }; diff --git a/source/SubTests/VerbEnd/VerbEndWidget.cpp b/source/SubTests/VerbEnd/VerbEndWidget.cpp index c3ebbc5..ee3ffee 100644 --- a/source/SubTests/VerbEnd/VerbEndWidget.cpp +++ b/source/SubTests/VerbEnd/VerbEndWidget.cpp @@ -20,4 +20,11 @@ VerbEndWidget::~VerbEndWidget() void VerbEndWidget::setModel(VerbEndModel *model) { ui->verbEndTableView->setModel(model); + + connect(model, &VerbEndModel::causalPointsChanged, this, &VerbEndWidget::causalPointsChanged); +} + +void VerbEndWidget::causalPointsChanged(unsigned int points) +{ + ui->causalPointsLabel->setText(QString::number(points)); } diff --git a/source/SubTests/VerbEnd/VerbEndWidget.h b/source/SubTests/VerbEnd/VerbEndWidget.h index 95f7ef5..e3b3eaa 100644 --- a/source/SubTests/VerbEnd/VerbEndWidget.h +++ b/source/SubTests/VerbEnd/VerbEndWidget.h @@ -20,4 +20,7 @@ public: ~VerbEndWidget(); void setModel(VerbEndModel *model); + +public slots: + void causalPointsChanged(unsigned int points); }; diff --git a/source/SubTests/VerbEnd/VerbEndWidget.ui b/source/SubTests/VerbEnd/VerbEndWidget.ui index 98c9e4e..b57c1f0 100644 --- a/source/SubTests/VerbEnd/VerbEndWidget.ui +++ b/source/SubTests/VerbEnd/VerbEndWidget.ui @@ -6,8 +6,8 @@ 0 0 - 556 - 210 + 732 + 381 @@ -17,6 +17,30 @@ + + + + + + + 80 + 16777215 + + + + Kausalsätze: + + + + + + + 0 + + + + + From cc20d46a7676c8d2d6775b87de7e192d934eed4a Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 12 Dec 2018 21:40:26 +0100 Subject: [PATCH 11/16] Print causal sentence points --- source/SubTests/VerbEnd/VerbEndModel.cpp | 22 ++++++++++++++++++++++ source/SubTests/VerbEnd/VerbEndModel.h | 1 + 2 files changed, 23 insertions(+) diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index 87a17fc..6fdd889 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -129,3 +129,25 @@ std::string VerbEndModel::getName() const return "Subtest 2: Verbendstellungsregel (VE)"; }; +void VerbEndModel::printSummaryTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 46), + QTextLength(QTextLength::PercentageLength, 25), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(1, 8, tableFormat); + + setCellText(*table, 0, 1, "Rohwertpunkte Kausalsätze:"); + setCellNumber(*table, 0, 3, getCausalPoints()); + setCellText(*table, 0, 5, "Rohwertpunkte Total:"); + setCellNumber(*table, 0, 7, getPoints()); +} diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index 411d455..44a3897 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -19,6 +19,7 @@ public: protected: std::string getName() const override; + void printSummaryTo(QTextCursor &cursor) const override; private slots: void modelChanged(); From be3a3f453d36d5d4c0ad340d8df848963bf11416 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 12 Dec 2018 22:19:42 +0100 Subject: [PATCH 12/16] WIP V2/Svk printing --- source/DataModel.cpp | 2 +- source/SubTests/V2Svk/V2SvkModel.cpp | 60 ++++++++++++++++++++++++++++ source/SubTests/V2Svk/V2SvkModel.h | 1 + 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 4bd4df9..5ac55f8 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -70,7 +70,7 @@ void DataModel::printTo(QTextCursor &cursor) const m_metaData.printTo(cursor); - //m_v2Svk.printTo(cursor); + m_v2Svk.printTo(cursor); m_verbEnd.printTo(cursor); m_genus.printTo(cursor); m_akkusativ.printTo(cursor); diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 755eacd..8e8c812 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -1,5 +1,7 @@ #include "V2SvkModel.h" +#include + V2SvkModel::V2SvkModel(QObject *parent) : CheckableTestModel(parent) { @@ -204,3 +206,61 @@ std::string V2SvkModel::getName() const { return "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"; } + +void V2SvkModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 13), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(2, 17, tableFormat); + + int currentRow = 0; + int currentTest = 0; + //for (const auto &test : m_tests) + { + table->mergeCells(currentRow, 0, 2, 1); + + int currentColumn = 0; + + setCellText(*table, currentRow, currentColumn, m_tests[0].name()); + currentColumn++; + + for (auto it = std::begin(m_tests[0].items()); it != std::end(m_tests[0].items()); std::advance(it, 4)) + { + table->mergeCells(currentRow, currentColumn, 1, 4); + + auto itemName = it->getText(); + + setCellText(*table, currentRow, currentColumn, itemName.c_str()); + setCellChecked(*table, currentRow + 1, currentColumn, it->isChecked()); + setCellChecked(*table, currentRow + 1, currentColumn + 1, (it + 1)->isChecked()); + setCellChecked(*table, currentRow + 1, currentColumn + 2, (it + 2)->isChecked()); + setCellChecked(*table, currentRow + 1, currentColumn + 3, (it + 3)->isChecked()); + + currentColumn += 4; + } + + setCellNumber(*table, currentRow + 1, 14, m_tests[0].getPoints()); + + currentRow += 2; + } +} diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index ec54a81..4e524a0 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -22,4 +22,5 @@ protected: bool isValidIndex(const QModelIndex &index) const override; std::string getName() const override; + void printTableTo(QTextCursor &cursor) const override; }; From a71811374778f527ce9e1c55ee0dfdf8c8b30d88 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 13 Dec 2018 20:46:38 +0100 Subject: [PATCH 13/16] Print subtest 1 --- source/SubTests/V2Svk/V2SvkModel.cpp | 179 ++++++++++++++++++++------- source/SubTests/V2Svk/V2SvkModel.h | 5 +- source/mainwindow.cpp | 2 - source/mainwindow.h | 1 - 4 files changed, 134 insertions(+), 53 deletions(-) diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 8e8c812..2e64ef0 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -6,7 +6,7 @@ V2SvkModel::V2SvkModel(QObject *parent) : CheckableTestModel(parent) { m_tests = { - {"W-Frage", + {"W-Fragen", {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", "Gans", "Gans", "Gans"}}, {"Verbtrennung", {"", "Affe", "", "", "", "", "", "Schwein", "", "", "Gans", ""}}, @@ -31,7 +31,7 @@ V2SvkModel::V2SvkModel(QObject *parent) }; } -unsigned int V2SvkModel::getV2Points() +unsigned int V2SvkModel::getV2Points() const { unsigned int points = 0; @@ -51,7 +51,7 @@ unsigned int V2SvkModel::getV2Points() return points; } -unsigned int V2SvkModel::getSvkPoints() +unsigned int V2SvkModel::getSvkPoints() const { unsigned int points = 0; @@ -208,59 +208,142 @@ std::string V2SvkModel::getName() const } void V2SvkModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat12; + tableFormat12.setCellPadding(2); + tableFormat12.setCellSpacing(0); + + tableFormat12.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 13), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTableFormat tableFormat6; + tableFormat6.setCellPadding(2); + tableFormat6.setCellSpacing(0); + + tableFormat6.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 13), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + auto writeHeader = [](QTextTable *table, const CheckableTest &test, int colSpan) { + table->mergeCells(0, 0, 2, 1); + + int column = 1; + + for (auto it = std::begin(test.items()); it != std::end(test.items()); + std::advance(it, colSpan)) + { + table->mergeCells(0, column, 1, colSpan); + setCellText(*table, 0, column, it->getText().c_str()); + + column += colSpan; + } + }; + + auto writeLine = [](QTextTable *table, const CheckableTest &test, int row, int resultColumn) { + int column = 0; + + setCellText(*table, row, column, test.name()); + for (const auto item : test.items()) + { + column++; + + if (!item.getText().empty()) + { + setCellChecked(*table, row, column, item.isChecked()); + } + } + + setCellNumber(*table, row, resultColumn, test.getPoints()); + }; + + { + QTextTable *table = cursor.insertTable(4, 17, tableFormat12); + + writeHeader(table, m_tests[0], 4); + writeLine(table, m_tests[0], 1, 14); + writeLine(table, m_tests[1], 2, 14); + writeLine(table, m_tests[2], 3, 16); + } + + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + + { + QTextTable *table = cursor.insertTable(3, 17, tableFormat12); + + writeHeader(table, m_tests[3], 4); + writeLine(table, m_tests[3], 1, 14); + writeLine(table, m_tests[4], 2, 16); + } + + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + + { + QTextTable *table = cursor.insertTable(3, 11, tableFormat6); + + writeHeader(table, m_tests[5], 2); + writeLine(table, m_tests[5], 1, 8); + writeLine(table, m_tests[6], 2, 10); + } + + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + + { + QTextTable *table = cursor.insertTable(5, 11, tableFormat6); + + writeHeader(table, m_tests[7], 2); + writeLine(table, m_tests[7], 1, 8); + writeLine(table, m_tests[8], 2, 8); + writeLine(table, m_tests[9], 3, 10); + writeLine(table, m_tests[10], 4, 10); + } +} + +void V2SvkModel::printSummaryTo(QTextCursor &cursor) const { QTextTableFormat tableFormat; tableFormat.setCellPadding(2); tableFormat.setCellSpacing(0); - tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 5), - QTextLength(QTextLength::PercentageLength, 13), + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 72), + QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 1), QTextLength(QTextLength::PercentageLength, 3), QTextLength(QTextLength::PercentageLength, 1), QTextLength(QTextLength::PercentageLength, 3)}); - QTextTable *table = cursor.insertTable(2, 17, tableFormat); + QTextTable *table = cursor.insertTable(1, 6, tableFormat); - int currentRow = 0; - int currentTest = 0; - //for (const auto &test : m_tests) - { - table->mergeCells(currentRow, 0, 2, 1); - - int currentColumn = 0; - - setCellText(*table, currentRow, currentColumn, m_tests[0].name()); - currentColumn++; - - for (auto it = std::begin(m_tests[0].items()); it != std::end(m_tests[0].items()); std::advance(it, 4)) - { - table->mergeCells(currentRow, currentColumn, 1, 4); - - auto itemName = it->getText(); - - setCellText(*table, currentRow, currentColumn, itemName.c_str()); - setCellChecked(*table, currentRow + 1, currentColumn, it->isChecked()); - setCellChecked(*table, currentRow + 1, currentColumn + 1, (it + 1)->isChecked()); - setCellChecked(*table, currentRow + 1, currentColumn + 2, (it + 2)->isChecked()); - setCellChecked(*table, currentRow + 1, currentColumn + 3, (it + 3)->isChecked()); - - currentColumn += 4; - } - - setCellNumber(*table, currentRow + 1, 14, m_tests[0].getPoints()); - - currentRow += 2; - } + setCellText(*table, 0, 1, "Rohwertpunkte Total:"); + setCellNumber(*table, 0, 3, getV2Points()); + setCellNumber(*table, 0, 5, getSvkPoints()); } + diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index 4e524a0..7794b7a 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -12,8 +12,8 @@ class V2SvkModel : public CheckableTestModel public: V2SvkModel(QObject *parent); - unsigned int getV2Points(); - unsigned int getSvkPoints(); + unsigned int getV2Points() const; + unsigned int getSvkPoints() const; void write(ESGRAF48::V2SvkModel &model) const; void read(const ESGRAF48::V2SvkModel &model); @@ -23,4 +23,5 @@ protected: std::string getName() const override; void printTableTo(QTextCursor &cursor) const override; + void printSummaryTo(QTextCursor &cursor) const override; }; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index d0e6d9f..488af63 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -161,8 +161,6 @@ void MainWindow::print() const QTextDocument printDoc; QTextCursor printCursor(&printDoc); m_dataModel.printTo(printCursor); - - printDoc.print(&printer); } void MainWindow::dataModelChanged() diff --git a/source/mainwindow.h b/source/mainwindow.h index 9675fb7..b270840 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -5,7 +5,6 @@ #include #include - class DataModel; class QDataWidgetMapper; From 6eb585b08cad1b3a5b4781e4dfd0fdeb033bb117 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 15 Dec 2018 16:12:20 +0100 Subject: [PATCH 14/16] Use central table format for printing --- source/CMakeLists.txt | 1 + .../CheckableTestModel/CheckableTestModel.cpp | 8 ++----- .../CheckableTestModel/CheckableTestModel.h | 6 +++-- source/DataModel.h | 24 +------------------ source/MetaData/MetaDataModel.cpp | 4 +--- source/MetaData/MetaDataModel.h | 13 +++++----- source/PrintableModel.cpp | 11 +++++++++ source/PrintableModel.h | 12 ++++++++++ source/ResultWidget/ResultModel.cpp | 4 +--- source/ResultWidget/ResultModel.h | 5 ++-- .../SubTests/LateSkills/LateSkillsModel.cpp | 4 +--- source/SubTests/Plural/PluralModel.cpp | 4 +--- source/SubTests/V2Svk/V2SvkModel.cpp | 12 +++------- source/SubTests/VerbEnd/VerbEndModel.cpp | 4 +--- 14 files changed, 48 insertions(+), 64 deletions(-) create mode 100644 source/PrintableModel.cpp create mode 100644 source/PrintableModel.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 0a0f40f..147bf10 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -36,6 +36,7 @@ protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS add_executable(${PROJECT_NAME} WIN32 ESGRAF48.cpp DataModel.cpp + PrintableModel.cpp mainwindow.cpp ${LOGO_TEST_UI} ${LOGO_TEST_QRC} diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 00da00c..953089a 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -134,9 +134,7 @@ void CheckableTestModel::printTo(QTextCursor &cursor) const void CheckableTestModel::printTableTo(QTextCursor &cursor) const { - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); + QTextTableFormat tableFormat = defaultTableFormat(); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), QTextLength(QTextLength::PercentageLength, 9), @@ -180,9 +178,7 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const { - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); + QTextTableFormat tableFormat = defaultTableFormat(); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 76), QTextLength(QTextLength::PercentageLength, 20), diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 4389e04..bf58c07 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -1,10 +1,12 @@ #pragma once +#include "../PrintableModel.h" #include "CheckableTest.h" + #include #include -class CheckableTestModel : public QAbstractTableModel +class CheckableTestModel : public QAbstractTableModel, protected PrintableModel { Q_OBJECT @@ -28,7 +30,7 @@ public: unsigned int getPoints() const; - virtual void printTo(QTextCursor &cursor) const; + void printTo(QTextCursor &cursor) const override; protected: virtual bool isValidIndex(const QModelIndex &index) const; diff --git a/source/DataModel.h b/source/DataModel.h index a718ef7..ce3a92a 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -36,34 +36,12 @@ public: DataModel(QObject *parent); void printTo(QTextCursor &cursor) const; - - void write(std::ostream &outStream) const; +void write(std::ostream &outStream) const; void read(std::istream &inStream); signals: void modelChanged(); -private: - template - void write( - const ModelType &model, QJsonObject &target, const char *name) const - { - QJsonObject jsonObject; - model.write(jsonObject); - target[name] = jsonObject; - } - - template - void read( - ModelType &model, const QJsonObject &source, const char *name) const - { - const auto &jsonObject = source[name]; - if (jsonObject.isObject()) - { - model.read(jsonObject.toObject()); - } - } - private slots: void pluralModelChanged(); void metaDataChanged(); diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 7f3769a..4a8403e 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -135,10 +135,8 @@ void MetaDataModel::printTo(QTextCursor &cursor) const { cursor.insertBlock(); - QTextTableFormat tableFormat; + QTextTableFormat tableFormat = defaultTableFormat(); tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_None); - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 25), QTextLength(QTextLength::PercentageLength, 25), diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index a96f75a..c019e1a 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -1,5 +1,6 @@ #pragma once +#include "../PrintableModel.h" #include "Age.h" #include "MetaDataModel.pb.h" @@ -10,7 +11,7 @@ #include #include -class MetaDataModel : public QAbstractTableModel +class MetaDataModel : public QAbstractTableModel, protected PrintableModel { Q_OBJECT @@ -25,19 +26,17 @@ public: MetaDataModel(QObject *parent); int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; - QVariant data( - const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; - bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole) override; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; void read(const ESGRAF48::MetaDataModel &model); void write(ESGRAF48::MetaDataModel &model) const; - void printTo(QTextCursor &cursor) const; + void printTo(QTextCursor &cursor) const override; Age getAge() const { - return { m_dateOfBirth, m_dateOfTest }; + return {m_dateOfBirth, m_dateOfTest}; } }; diff --git a/source/PrintableModel.cpp b/source/PrintableModel.cpp new file mode 100644 index 0000000..7176aba --- /dev/null +++ b/source/PrintableModel.cpp @@ -0,0 +1,11 @@ +#include "PrintableModel.h" + +QTextTableFormat PrintableModel::defaultTableFormat() +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + return tableFormat; +} + diff --git a/source/PrintableModel.h b/source/PrintableModel.h new file mode 100644 index 0000000..e3bea6a --- /dev/null +++ b/source/PrintableModel.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +class PrintableModel +{ +public: + virtual void printTo(QTextCursor &cursor) const = 0; + +protected: + static QTextTableFormat defaultTableFormat(); +}; diff --git a/source/ResultWidget/ResultModel.cpp b/source/ResultWidget/ResultModel.cpp index 02fab59..2c9fdc9 100644 --- a/source/ResultWidget/ResultModel.cpp +++ b/source/ResultWidget/ResultModel.cpp @@ -217,9 +217,7 @@ void ResultModel::printTo(QTextCursor &cursor) const cursor.insertBlock(); cursor.insertText("\nProzentränge (PR)"); - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); + QTextTableFormat tableFormat = defaultTableFormat(); const unsigned int columnCount = 10; diff --git a/source/ResultWidget/ResultModel.h b/source/ResultWidget/ResultModel.h index 67d2692..3e58ba3 100644 --- a/source/ResultWidget/ResultModel.h +++ b/source/ResultWidget/ResultModel.h @@ -1,12 +1,13 @@ #pragma once +#include "../PrintableModel.h" #include "Age.h" #include "TestResult.h" #include #include -class ResultModel : public QAbstractTableModel +class ResultModel : public QAbstractTableModel, protected PrintableModel { Q_OBJECT @@ -36,5 +37,5 @@ public: void setPassivResult(unsigned int points); void setGenitivResult(unsigned int points); - void printTo(QTextCursor &cursor) const; + void printTo(QTextCursor &cursor) const override; }; diff --git a/source/SubTests/LateSkills/LateSkillsModel.cpp b/source/SubTests/LateSkills/LateSkillsModel.cpp index 74a824f..95ab46b 100644 --- a/source/SubTests/LateSkills/LateSkillsModel.cpp +++ b/source/SubTests/LateSkills/LateSkillsModel.cpp @@ -11,9 +11,7 @@ LateSkillsModel::LateSkillsModel(QObject *parent) void LateSkillsModel::printTableTo(QTextCursor &cursor) const { - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); + QTextTableFormat tableFormat = defaultTableFormat(); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), QTextLength(QTextLength::PercentageLength, 5), diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index 1bd733c..f3ccbd9 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -63,9 +63,7 @@ std::string PluralModel::getName() const void PluralModel::printTableTo(QTextCursor &cursor) const { - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); + QTextTableFormat tableFormat = defaultTableFormat(); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10), QTextLength(QTextLength::PercentageLength, 10), diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 2e64ef0..30b143c 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -209,9 +209,7 @@ std::string V2SvkModel::getName() const void V2SvkModel::printTableTo(QTextCursor &cursor) const { - QTextTableFormat tableFormat12; - tableFormat12.setCellPadding(2); - tableFormat12.setCellSpacing(0); + QTextTableFormat tableFormat12 = defaultTableFormat(); tableFormat12.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), QTextLength(QTextLength::PercentageLength, 5), @@ -231,9 +229,7 @@ void V2SvkModel::printTableTo(QTextCursor &cursor) const QTextLength(QTextLength::PercentageLength, 1), QTextLength(QTextLength::PercentageLength, 3)}); - QTextTableFormat tableFormat6; - tableFormat6.setCellPadding(2); - tableFormat6.setCellSpacing(0); + QTextTableFormat tableFormat6 = defaultTableFormat(); tableFormat6.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), QTextLength(QTextLength::PercentageLength, 10), @@ -329,9 +325,7 @@ void V2SvkModel::printTableTo(QTextCursor &cursor) const void V2SvkModel::printSummaryTo(QTextCursor &cursor) const { - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); + QTextTableFormat tableFormat = defaultTableFormat(); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 72), QTextLength(QTextLength::PercentageLength, 20), diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index 6fdd889..9061d23 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -131,9 +131,7 @@ std::string VerbEndModel::getName() const void VerbEndModel::printSummaryTo(QTextCursor &cursor) const { - QTextTableFormat tableFormat; - tableFormat.setCellPadding(2); - tableFormat.setCellSpacing(0); + QTextTableFormat tableFormat = defaultTableFormat(); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 46), QTextLength(QTextLength::PercentageLength, 25), From c8bd1bbdb8b2e285ca365ab78330713ba8ef7129 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 15 Dec 2018 16:31:51 +0100 Subject: [PATCH 15/16] Paint empty result cells gray --- .../CheckableTestModel/CheckableTestModel.cpp | 26 -------------- .../CheckableTestModel/CheckableTestModel.h | 9 ----- source/PrintableModel.cpp | 35 +++++++++++++++++++ source/PrintableModel.h | 11 ++++++ source/SubTests/V2Svk/V2SvkModel.cpp | 6 +++- source/mainwindow.cpp | 2 ++ 6 files changed, 53 insertions(+), 36 deletions(-) diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 953089a..504ab98 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -191,32 +191,6 @@ void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const setCellNumber(*table, 0, 3, getPoints()); } -void CheckableTestModel::setCellText(QTextTable &table, int row, int column, const QString &text) -{ - auto cell = table.cellAt(row, column); - auto textCursor = cell.firstCursorPosition(); - - auto blockFormat = textCursor.blockFormat(); - blockFormat.setAlignment(Qt::AlignCenter); - textCursor.setBlockFormat(blockFormat); - - auto cellFormat = cell.format(); - cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - cell.setFormat(cellFormat); - - auto charFormat = textCursor.charFormat(); - charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - charFormat.setFontPointSize(8); - textCursor.setCharFormat(charFormat); - - textCursor.insertText(text); -} - -void CheckableTestModel::setCellChecked(QTextTable &table, int row, int column, bool check) -{ - setCellText(table, row, column, check ? "x" : "\u2610"); -} - CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) { if (index.row() < m_tests.size()) diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index bf58c07..d30ad6b 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -40,15 +40,6 @@ protected: virtual void printTableTo(QTextCursor &cursor) const; virtual void printSummaryTo(QTextCursor &cursor) const; - static void setCellText(QTextTable &table, int row, int column, const QString &text); - static void setCellChecked(QTextTable &table, int row, int column, bool check); - - template - static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number) - { - setCellText(table, row, column, QString::number(number)); - } - private: CheckableItems &getItems(const QModelIndex &index); const CheckableItems &getItems(const QModelIndex &index) const; diff --git a/source/PrintableModel.cpp b/source/PrintableModel.cpp index 7176aba..c3b9d03 100644 --- a/source/PrintableModel.cpp +++ b/source/PrintableModel.cpp @@ -9,3 +9,38 @@ QTextTableFormat PrintableModel::defaultTableFormat() return tableFormat; } +void PrintableModel::setCellText(QTextTable &table, int row, int column, const QString &text) +{ + auto cell = table.cellAt(row, column); + auto textCursor = cell.firstCursorPosition(); + + auto blockFormat = textCursor.blockFormat(); + blockFormat.setAlignment(Qt::AlignCenter); + textCursor.setBlockFormat(blockFormat); + + auto cellFormat = cell.format(); + cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + cell.setFormat(cellFormat); + + auto charFormat = textCursor.charFormat(); + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + charFormat.setFontPointSize(8); + textCursor.setCharFormat(charFormat); + + textCursor.insertText(text); +} + +void PrintableModel::setCellChecked(QTextTable &table, int row, int column, bool check) +{ + setCellText(table, row, column, check ? "x" : "\u2610"); +} + +void PrintableModel::setCellBackground(QTextTable &table, int row, int column, const QColor &color) +{ + auto cell = table.cellAt(row, column); + + auto cellFormat = cell.format(); + cellFormat.setBackground(QBrush(color)); + cell.setFormat(cellFormat); +} + diff --git a/source/PrintableModel.h b/source/PrintableModel.h index e3bea6a..b3652ac 100644 --- a/source/PrintableModel.h +++ b/source/PrintableModel.h @@ -1,6 +1,7 @@ #pragma once #include +#include class PrintableModel { @@ -9,4 +10,14 @@ public: protected: static QTextTableFormat defaultTableFormat(); + + static void setCellText(QTextTable &table, int row, int column, const QString &text); + static void setCellChecked(QTextTable &table, int row, int column, bool check); + static void setCellBackground(QTextTable &table, int row, int column, const QColor &color); + + template + static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number) + { + setCellText(table, row, column, QString::number(number)); + } }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 30b143c..a982b93 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -266,7 +266,11 @@ void V2SvkModel::printTableTo(QTextCursor &cursor) const { column++; - if (!item.getText().empty()) + if (item.getText().empty()) + { + setCellBackground(*table, row, column, QColor(92, 92, 92)); + } + else { setCellChecked(*table, row, column, item.isChecked()); } diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 488af63..d0e6d9f 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -161,6 +161,8 @@ void MainWindow::print() const QTextDocument printDoc; QTextCursor printCursor(&printDoc); m_dataModel.printTo(printCursor); + + printDoc.print(&printer); } void MainWindow::dataModelChanged() From e64ef375fb32132513d8b8d8147e0ef668c90e67 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 15 Dec 2018 17:10:21 +0100 Subject: [PATCH 16/16] Increased print resolution to get thinner table borders --- source/mainwindow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index d0e6d9f..528bcc7 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -151,6 +151,7 @@ void MainWindow::closeFile() void MainWindow::print() const { QPrinter printer; + printer.setResolution(1200); QPrintDialog dialog(&printer); if (dialog.exec() != QDialog::Accepted) @@ -209,6 +210,7 @@ void MainWindow::saveFile(const QString &filename) void MainWindow::savePdf(const QString &filename) { QPrinter printer; + printer.setResolution(1200); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPaperSize(QPrinter::A4); printer.setOutputFileName(filename);