From b06e71757505bc410f58f5936f283b769836748d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 2 Dec 2018 18:26:22 +0100 Subject: [PATCH] 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; };