From 98196e05d6a87196d59890f5354990e6ae8a7083 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 10 Dec 2018 22:29:49 +0100 Subject: [PATCH] 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;