From ab862aeaf10fe0caabfd089584c22ec26d596c5c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 3 Feb 2019 19:53:51 +0100 Subject: [PATCH] Print most of the table structures --- source/CheckableTestModel/CMakeLists.txt | 3 +- .../CheckableTestModel/CheckableTestModel.cpp | 5 + .../CheckableTestModel/CheckableTestModel.h | 11 +- source/DataModel.cpp | 29 +++- source/DataModel.h | 6 +- source/MetaData/MetaDataModel.cpp | 2 +- source/MetaData/MetaDataModel.h | 2 +- source/PrintableModel/CMakeLists.txt | 2 + source/PrintableModel/PrintableModel.cpp | 87 +++++++++++- source/PrintableModel/PrintableModel.h | 20 ++- source/SubTests/Genus/CMakeLists.txt | 4 +- source/SubTests/Genus/GenusModel.cpp | 4 +- source/SubTests/Genus/GenusModel.h | 4 +- source/SubTests/Plural/CMakeLists.txt | 4 +- source/SubTests/Plural/PluralModel.cpp | 4 +- source/SubTests/Plural/PluralModel.h | 4 +- source/SubTests/V2Svk/CMakeLists.txt | 4 +- source/SubTests/V2Svk/OTModel.cpp | 16 ++- source/SubTests/V2Svk/OTModel.h | 18 ++- source/SubTests/V2Svk/TPeModel.cpp | 16 ++- source/SubTests/V2Svk/TPeModel.h | 18 ++- source/SubTests/V2Svk/TPrModel.cpp | 16 ++- source/SubTests/V2Svk/TPrModel.h | 18 ++- source/SubTests/V2Svk/V2SvkModel.cpp | 126 ++++++++++++++++++ source/SubTests/V2Svk/V2SvkModel.h | 27 ++++ source/SubTests/V2Svk/WFModel.cpp | 121 ++--------------- source/SubTests/V2Svk/WFModel.h | 19 ++- source/SubTests/VerbEnd/CMakeLists.txt | 1 + source/SubTests/VerbEnd/VerbEndModel.cpp | 5 +- source/SubTests/VerbEnd/VerbEndModel.h | 4 +- source/mainwindow.cpp | 14 +- 31 files changed, 411 insertions(+), 203 deletions(-) create mode 100644 source/SubTests/V2Svk/V2SvkModel.cpp create mode 100644 source/SubTests/V2Svk/V2SvkModel.h diff --git a/source/CheckableTestModel/CMakeLists.txt b/source/CheckableTestModel/CMakeLists.txt index 2ce7c3b..c7426fc 100644 --- a/source/CheckableTestModel/CMakeLists.txt +++ b/source/CheckableTestModel/CMakeLists.txt @@ -18,8 +18,9 @@ target_include_directories(${PROJECT_NAME} ) target_link_libraries(${PROJECT_NAME} - PRIVATE + PUBLIC CheckableItem CheckableTest + PRIVATE Qt5::Core ) diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index aafc5f9..685ea1a 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -187,3 +187,8 @@ unsigned int CheckableTestModel::getPoints() const return points; } + +QString CheckableTestModel::getTitle() const +{ + return m_title; +} diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 2fd5434..2201cec 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -8,6 +8,7 @@ class CheckableTestModel : public QAbstractTableModel Q_OBJECT protected: + QString m_title; CheckableTests m_tests; public: @@ -16,17 +17,17 @@ 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; 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; QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const override; + int role = Qt::DisplayRole) const override; unsigned int getPoints() const; + QString getTitle() const; + protected: virtual bool isValidIndex(const QModelIndex &index) const; diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 8eebb89..0d33a13 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -99,15 +99,38 @@ void DataModel::read(const QString &filename) m_genitiv.read(dataModel.lateskillsgenitiv()); m_passiv.read(dataModel.lateskillspassiv()); } - -void DataModel::printTo(QPainter &painter) const + +void DataModel::printTo(QPrinter &printer) const { - painter.setFont(h1Font()); + QPainter painter; + painter.begin(&printer); + + + painter.setFont(PrintableModel::h1Font()); painter.drawText(0, painter.fontMetrics().lineSpacing(), "ESGRAF 4-8 Auswertungsbogen"); painter.translate(0, 3 * painter.fontMetrics().lineSpacing()); m_metaData.printTo(painter); + m_wfModel.printTo(painter); + m_otModel.printTo(painter); + m_tPrModel.printTo(painter); + m_tPeModel.printTo(painter); + V2SvkModel::printSummary(painter, + m_wfModel.getV2Points() + m_otModel.getV2Points() + + m_tPrModel.getV2Points() + m_tPeModel.getV2Points(), + m_wfModel.getSvkPoints() + m_otModel.getSvkPoints() + + m_tPrModel.getSvkPoints() + m_tPeModel.getSvkPoints()); + + m_verbEnd.printTo(painter); + m_genus.printTo(painter); + + printer.newPage(); + painter.resetTransform(); + + m_plural.printTo(painter); + + painter.end(); } void DataModel::pluralModelChanged() diff --git a/source/DataModel.h b/source/DataModel.h index f99fcc4..aa0fbf3 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -19,9 +19,9 @@ #include "ResultModel.h" -#include +#include -class DataModel : public QObject, public PrintableModel +class DataModel : public QObject { Q_OBJECT @@ -49,7 +49,7 @@ public: void write(const QString &filename) const; void read(const QString &filename); - void printTo(QPainter &painter) const override; + void printTo(QPrinter &printer) const; signals: void modelChanged(); diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 24efdbd..2342b17 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -5,7 +5,7 @@ #include MetaDataModel::MetaDataModel(QObject *parent) - : QAbstractTableModel(parent) + : PrintableModel(parent) { m_dateOfBirth = QDate::currentDate().addYears(-9); m_dateOfTest = QDate::currentDate(); diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 136b463..4ab5f4b 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -10,7 +10,7 @@ #include #include -class MetaDataModel : public QAbstractTableModel, public PrintableModel +class MetaDataModel : public PrintableModel { Q_OBJECT diff --git a/source/PrintableModel/CMakeLists.txt b/source/PrintableModel/CMakeLists.txt index 0a09f00..842b0f2 100644 --- a/source/PrintableModel/CMakeLists.txt +++ b/source/PrintableModel/CMakeLists.txt @@ -19,6 +19,8 @@ target_include_directories(${PROJECT_NAME} ) target_link_libraries(${PROJECT_NAME} + PUBLIC + CheckableTestModel PRIVATE Qt5::Core Qt5::Widgets diff --git a/source/PrintableModel/PrintableModel.cpp b/source/PrintableModel/PrintableModel.cpp index 21d57a2..85b6ed4 100644 --- a/source/PrintableModel/PrintableModel.cpp +++ b/source/PrintableModel/PrintableModel.cpp @@ -1,5 +1,17 @@ #include "PrintableModel.h" +PrintableModel::PrintableModel(QObject *parent) + : CheckableTestModel(parent) +{ +} + +void PrintableModel::printTo(QPainter &painter) const +{ + printHeader(painter); + printTests(painter); + printSummary(painter); +} + QFont PrintableModel::h1Font() { return QFont("Helvetica", 16); @@ -7,7 +19,7 @@ QFont PrintableModel::h1Font() QFont PrintableModel::h2Font() { - return QFont("Helvetica", 12); + return QFont("Helvetica", 10); } QFont PrintableModel::tableFont() @@ -44,17 +56,12 @@ void PrintableModel::PrintableModel::drawCheckSquare(QPainter &painter, const QR void PrintableModel::drawResultSquare(QPainter &painter, double y, bool rightCell, unsigned int value) { - auto prevPen = painter.pen(); - painter.setPen(tablePen()); - double pageWidth = painter.device()->width(); double cellWidth = 0.03 * pageWidth; - double cellHeight = painter.fontMetrics().lineSpacing(); + double cellHeight = 1.5 * painter.fontMetrics().lineSpacing(); double x = pageWidth - cellWidth - (rightCell ? 0 : 0.04 * pageWidth); drawTextSquare(painter, {x, y, cellWidth, cellHeight}, QString::number(value)); - - painter.setPen(prevPen); } void PrintableModel::drawGreySquare(QPainter &painter, const QRectF &cell) @@ -76,3 +83,69 @@ void PrintableModel::drawGreySquare(QPainter &painter, const QRectF &cell) painter.setBrush(prevBrush); painter.setPen(prevPen); } + +void PrintableModel::drawHeader2(QPainter &painter, const QString &text) +{ + painter.setFont(h2Font()); + painter.drawText(0, 0, text); + painter.translate(0, 0.5 * painter.fontMetrics().lineSpacing()); +} + +void PrintableModel::printHeader(QPainter &painter) const +{ + auto title = getTitle(); + if (!title.isEmpty()) + { + drawHeader2(painter, getTitle()); + } +} + +void PrintableModel::printTests(QPainter &painter) const +{ + painter.setFont(tableFont()); + painter.setPen(tablePen()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + double headerWidth = 0.2 * width; + double cellWidth = 0.08 * width; + double rowHeight = height; + + double x = 0; + double y = 0; + for (const auto &test : m_tests) + { + drawTextSquare(painter, {0, y, headerWidth, 2 * rowHeight}, test.name()); + x = headerWidth; + + for (const auto &item : test.items()) + { + drawTextSquare(painter, {x, y, cellWidth, rowHeight}, item.getText().c_str()); + drawCheckSquare(painter, {x, y + rowHeight, cellWidth, rowHeight}, item.isChecked()); + + x += cellWidth; + } + y += rowHeight; + + drawResultSquare(painter, y, true, test.getPoints()); + y += rowHeight; + } + + painter.translate(0, y + rowHeight); +} + +void PrintableModel::printSummary(QPainter &painter) const +{ + painter.setFont(tableFont()); + painter.setPen(tablePen()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + painter.drawText(0, 0, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, + "Rohwertpunkte Total:"); + drawResultSquare(painter, 0, true, getPoints()); + + painter.translate(0, 3 * height); +} diff --git a/source/PrintableModel/PrintableModel.h b/source/PrintableModel/PrintableModel.h index ab08433..8dba378 100644 --- a/source/PrintableModel/PrintableModel.h +++ b/source/PrintableModel/PrintableModel.h @@ -1,17 +1,22 @@ #pragma once +#include "CheckableTestModel.h" + #include #include #include #include #include -class PrintableModel +class PrintableModel : public CheckableTestModel { -public: - virtual void printTo(QPainter &painter) const = 0; + Q_OBJECT + +public: + PrintableModel(QObject *parent); + + virtual void printTo(QPainter &painter) const; -protected: static QFont h1Font(); static QFont h2Font(); static QFont tableFont(); @@ -22,4 +27,11 @@ protected: static void drawCheckSquare(QPainter &painter, const QRectF &cell, bool checked); static void drawResultSquare(QPainter &painter, double y, bool rightCell, unsigned int value); static void drawGreySquare(QPainter &painter, const QRectF &cell); + +protected: + static void drawHeader2(QPainter &painter, const QString &text); + + virtual void printHeader(QPainter &painter) const; + virtual void printTests(QPainter &painter) const; + virtual void printSummary(QPainter &painter) const; }; diff --git a/source/SubTests/Genus/CMakeLists.txt b/source/SubTests/Genus/CMakeLists.txt index 5b29b68..b3f1ae3 100644 --- a/source/SubTests/Genus/CMakeLists.txt +++ b/source/SubTests/Genus/CMakeLists.txt @@ -39,9 +39,7 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE - CheckableItem - CheckableTest - CheckableTestModel + PrintableModel Qt5::Widgets ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index 3f2278b..faa7460 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -1,8 +1,10 @@ #include "GenusModel.h" GenusModel::GenusModel(QObject *parent) - : CheckableTestModel(parent) + : PrintableModel(parent) { + m_title = "Subtest 3: Genus"; + m_tests = {{"Tiere", {"Tiger", "Bär", "Katze", "Pferd", "Gans", "Elefant", "Affe", "Hund"}}, {"Futter", {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}, diff --git a/source/SubTests/Genus/GenusModel.h b/source/SubTests/Genus/GenusModel.h index 8261779..fd3faba 100644 --- a/source/SubTests/Genus/GenusModel.h +++ b/source/SubTests/Genus/GenusModel.h @@ -1,9 +1,9 @@ #pragma once -#include "CheckableTestModel.h" +#include "PrintableModel.h" #include "GenusModel.pb.h" -class GenusModel : public CheckableTestModel +class GenusModel : public PrintableModel { Q_OBJECT diff --git a/source/SubTests/Plural/CMakeLists.txt b/source/SubTests/Plural/CMakeLists.txt index 7a6aa58..978e936 100644 --- a/source/SubTests/Plural/CMakeLists.txt +++ b/source/SubTests/Plural/CMakeLists.txt @@ -39,9 +39,7 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE - CheckableItem - CheckableTest - CheckableTestModel + PrintableModel Qt5::Widgets ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index dcd0959..5448ed3 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -3,8 +3,10 @@ #include PluralModel::PluralModel(QObject *parent) - : CheckableTestModel(parent) + : PrintableModel(parent) { + m_title = "Subtest 5: Plural"; + m_tests = {{"Plural", {"Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/", "Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML"}}}; diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index ef1381f..728258d 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -1,9 +1,9 @@ #pragma once -#include "CheckableTestModel.h" +#include "PrintableModel.h" #include "PluralModel.pb.h" -class PluralModel : public CheckableTestModel +class PluralModel : public PrintableModel { Q_OBJECT diff --git a/source/SubTests/V2Svk/CMakeLists.txt b/source/SubTests/V2Svk/CMakeLists.txt index 2f758ce..2690a7b 100644 --- a/source/SubTests/V2Svk/CMakeLists.txt +++ b/source/SubTests/V2Svk/CMakeLists.txt @@ -19,6 +19,7 @@ protobuf_generate_cpp(V2Svk_PROTO_SRCS V2Svk_PROTO_HDRS ${V2Svk_PROTO_FILES}) add_library(${PROJECT_NAME} V2SvkWidget.cpp + V2SvkModel.cpp WFModel.cpp OTModel.cpp TPrModel.cpp @@ -42,9 +43,6 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE - CheckableItem - CheckableTest - CheckableTestModel PrintableModel Qt5::Widgets ${Protobuf_LIBRARIES} diff --git a/source/SubTests/V2Svk/OTModel.cpp b/source/SubTests/V2Svk/OTModel.cpp index 1c0f477..6760255 100644 --- a/source/SubTests/V2Svk/OTModel.cpp +++ b/source/SubTests/V2Svk/OTModel.cpp @@ -1,7 +1,7 @@ #include "OTModel.h" OTModel::OTModel(QObject *parent) - : CheckableTestModel(parent) + : V2SvkModel(parent) { m_tests = { {"Objekt-Topikalisierung", @@ -13,7 +13,7 @@ OTModel::OTModel(QObject *parent) }; } -unsigned int OTModel::getV2Points() +unsigned int OTModel::getV2Points() const { unsigned int points = 0; @@ -33,7 +33,7 @@ unsigned int OTModel::getV2Points() return points; } -unsigned int OTModel::getSvkPoints() +unsigned int OTModel::getSvkPoints() const { unsigned int points = 0; @@ -103,3 +103,13 @@ void OTModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +std::set OTModel::v2Tests() const +{ + return {0}; +}; + +std::set OTModel::svkTests() const +{ + return {1}; +}; diff --git a/source/SubTests/V2Svk/OTModel.h b/source/SubTests/V2Svk/OTModel.h index d4b5a49..c9d9e2b 100644 --- a/source/SubTests/V2Svk/OTModel.h +++ b/source/SubTests/V2Svk/OTModel.h @@ -1,18 +1,24 @@ #pragma once -#include "CheckableTestModel.h" +#include "V2SvkModel.h" #include "V2SvkModel.pb.h" -class OTModel : public CheckableTestModel +class OTModel : public V2SvkModel { Q_OBJECT public: OTModel(QObject *parent); - unsigned int getV2Points(); - unsigned int getSvkPoints(); + unsigned int getV2Points() const override; + unsigned int getSvkPoints() const override; - void write(ESGRAF48::V2SvkModel &model) const; - void read(const ESGRAF48::V2SvkModel &model); + void write(ESGRAF48::V2SvkModel &model) const override; + void read(const ESGRAF48::V2SvkModel &model) override; + +protected: + void printHeader(QPainter &) const override {}; + + std::set v2Tests() const override; + std::set svkTests() const override; }; diff --git a/source/SubTests/V2Svk/TPeModel.cpp b/source/SubTests/V2Svk/TPeModel.cpp index 2c17da3..5f66aab 100644 --- a/source/SubTests/V2Svk/TPeModel.cpp +++ b/source/SubTests/V2Svk/TPeModel.cpp @@ -1,7 +1,7 @@ #include "TPeModel.h" TPeModel::TPeModel(QObject *parent) - : CheckableTestModel(parent) + : V2SvkModel(parent) { m_tests = { {"Temporaladverb Perfekt", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, @@ -11,7 +11,7 @@ TPeModel::TPeModel(QObject *parent) }; } -unsigned int TPeModel::getV2Points() +unsigned int TPeModel::getV2Points() const { unsigned int points = 0; @@ -31,7 +31,7 @@ unsigned int TPeModel::getV2Points() return points; } -unsigned int TPeModel::getSvkPoints() +unsigned int TPeModel::getSvkPoints() const { unsigned int points = 0; @@ -93,3 +93,13 @@ void TPeModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +std::set TPeModel::v2Tests() const +{ + return {0, 1}; +}; + +std::set TPeModel::svkTests() const +{ + return {2, 3}; +}; diff --git a/source/SubTests/V2Svk/TPeModel.h b/source/SubTests/V2Svk/TPeModel.h index 19a1c12..60eb7ba 100644 --- a/source/SubTests/V2Svk/TPeModel.h +++ b/source/SubTests/V2Svk/TPeModel.h @@ -1,18 +1,24 @@ #pragma once -#include "CheckableTestModel.h" +#include "V2SvkModel.h" #include "V2SvkModel.pb.h" -class TPeModel : public CheckableTestModel +class TPeModel : public V2SvkModel { Q_OBJECT public: TPeModel(QObject *parent); - unsigned int getV2Points(); - unsigned int getSvkPoints(); + unsigned int getV2Points() const override; + unsigned int getSvkPoints() const override; - void write(ESGRAF48::V2SvkModel &model) const; - void read(const ESGRAF48::V2SvkModel &model); + void write(ESGRAF48::V2SvkModel &model) const override; + void read(const ESGRAF48::V2SvkModel &model) override; + +protected: + void printHeader(QPainter &) const override {}; + + std::set v2Tests() const override; + std::set svkTests() const override; }; diff --git a/source/SubTests/V2Svk/TPrModel.cpp b/source/SubTests/V2Svk/TPrModel.cpp index fcf9c01..995b584 100644 --- a/source/SubTests/V2Svk/TPrModel.cpp +++ b/source/SubTests/V2Svk/TPrModel.cpp @@ -1,7 +1,7 @@ #include "TPrModel.h" TPrModel::TPrModel(QObject *parent) - : CheckableTestModel(parent) + : V2SvkModel(parent) { m_tests = { {"Temporaladverb Präsens", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, @@ -9,7 +9,7 @@ TPrModel::TPrModel(QObject *parent) }; } -unsigned int TPrModel::getV2Points() +unsigned int TPrModel::getV2Points() const { unsigned int points = 0; @@ -29,7 +29,7 @@ unsigned int TPrModel::getV2Points() return points; } -unsigned int TPrModel::getSvkPoints() +unsigned int TPrModel::getSvkPoints() const { unsigned int points = 0; @@ -87,3 +87,13 @@ void TPrModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +std::set TPrModel::v2Tests() const +{ + return {0}; +}; + +std::set TPrModel::svkTests() const +{ + return {1}; +}; diff --git a/source/SubTests/V2Svk/TPrModel.h b/source/SubTests/V2Svk/TPrModel.h index 257a576..9047cbf 100644 --- a/source/SubTests/V2Svk/TPrModel.h +++ b/source/SubTests/V2Svk/TPrModel.h @@ -1,18 +1,24 @@ #pragma once -#include "CheckableTestModel.h" +#include "V2SvkModel.h" #include "V2SvkModel.pb.h" -class TPrModel : public CheckableTestModel +class TPrModel : public V2SvkModel { Q_OBJECT public: TPrModel(QObject *parent); - unsigned int getV2Points(); - unsigned int getSvkPoints(); + unsigned int getV2Points() const override; + unsigned int getSvkPoints() const override; - void write(ESGRAF48::V2SvkModel &model) const; - void read(const ESGRAF48::V2SvkModel &model); + void write(ESGRAF48::V2SvkModel &model) const override; + void read(const ESGRAF48::V2SvkModel &model) override; + +protected: + void printHeader(QPainter &) const override{}; + + std::set v2Tests() const override; + std::set svkTests() const override; }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp new file mode 100644 index 0000000..5db51d4 --- /dev/null +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -0,0 +1,126 @@ +#include "V2SvkModel.h" + +V2SvkModel::V2SvkModel(QObject *parent) + : PrintableModel(parent) +{ +} + +void V2SvkModel::printTests(QPainter &painter) const +{ + painter.setFont(tableFont()); + painter.setPen(tablePen()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + auto v2TestIndices = v2Tests(); + auto svkTestIndices = svkTests(); + + double x = 0; + double y = 0; + auto testIndex = 0; + for (const auto &test : m_tests) + { + double rowHeaderWidth = 0.2 * width; + double resultCellWidth = test.size() > 8 ? 0.04 * width : 0.08 * width; + double rowHeight = height; + + if (testIndex == 0) + { + drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, test.name()); + x += rowHeaderWidth; + + std::vector> columnHeaders; + for (const auto &item : test.items()) + { + const auto &itemText = item.getText(); + if (!columnHeaders.empty() && columnHeaders.back().first == itemText) + { + columnHeaders.back().second++; + } + else + { + columnHeaders.emplace_back(itemText, 1); + } + } + + for (const auto &columnHeader : columnHeaders) + { + double cellWidth = columnHeader.second * resultCellWidth; + drawTextSquare(painter, {x, y, cellWidth, rowHeight}, columnHeader.first.c_str()); + x += cellWidth; + } + x = rowHeaderWidth; + y += rowHeight; + } + else + { + drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, test.name()); + x += rowHeaderWidth; + } + + unsigned int emptyItemsStack = 0; + for (const auto &item : test.items()) + { + if (item.getText().empty()) + { + emptyItemsStack++; + } + else + { + if (emptyItemsStack > 0) + { + drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y, + emptyItemsStack * resultCellWidth, rowHeight}); + emptyItemsStack = 0; + } + + drawCheckSquare(painter, {x, y, resultCellWidth, rowHeight}, item.isChecked()); + } + x += resultCellWidth; + } + if (emptyItemsStack > 0) + { + drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y, + emptyItemsStack * resultCellWidth, rowHeight}); + emptyItemsStack = 0; + } + + if (v2TestIndices.find(testIndex) != v2TestIndices.end()) + { + drawResultSquare(painter, y, false, test.getPoints()); + } + + if (svkTestIndices.find(testIndex) != svkTestIndices.end()) + { + drawResultSquare(painter, y, true, test.getPoints()); + } + + x = 0; + y += rowHeight; + + testIndex++; + } + + x = 0; + y += height; + + painter.translate(0, y); +} + +void V2SvkModel::printSummary(QPainter &painter, unsigned int v2Points, unsigned int svkPoints) +{ + painter.setFont(PrintableModel::tableFont()); + painter.setPen(PrintableModel::tablePen()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + painter.drawText(0, 0, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, + "Rohwertpunkte Total:"); + PrintableModel::drawResultSquare(painter, 0, false, v2Points); + PrintableModel::drawResultSquare(painter, 0, true, svkPoints); + + painter.translate(0, 3 * height); +} + diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h new file mode 100644 index 0000000..87af510 --- /dev/null +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -0,0 +1,27 @@ +#pragma once + +#include "PrintableModel.h" +#include "V2SvkModel.pb.h" + +class V2SvkModel : public PrintableModel +{ + Q_OBJECT + +public: + V2SvkModel(QObject *parent); + + virtual unsigned int getV2Points() const = 0; + virtual unsigned int getSvkPoints() const = 0; + + virtual void write(ESGRAF48::V2SvkModel &model) const = 0; + virtual void read(const ESGRAF48::V2SvkModel &model) = 0; + + static void printSummary(QPainter &painter, unsigned int v2Points, unsigned int svkPoints); + +protected: + void printTests(QPainter &painter) const override; + void printSummary(QPainter &painter) const override {}; + + virtual std::set v2Tests() const = 0; + virtual std::set svkTests() const = 0; +}; diff --git a/source/SubTests/V2Svk/WFModel.cpp b/source/SubTests/V2Svk/WFModel.cpp index dde665a..487a5dc 100644 --- a/source/SubTests/V2Svk/WFModel.cpp +++ b/source/SubTests/V2Svk/WFModel.cpp @@ -1,8 +1,10 @@ #include "WFModel.h" WFModel::WFModel(QObject *parent) - : CheckableTestModel(parent) + : V2SvkModel(parent) { + m_title = "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"; + m_tests = { {"W-Frage", {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", @@ -134,115 +136,12 @@ void WFModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } -void WFModel::printTo(QPainter &painter) const +std::set WFModel::v2Tests() const { - painter.setFont(h2Font()); + return {0, 1}; +}; - painter.drawText( - 0, 0, "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"); - - painter.setFont(tableFont()); - painter.setPen(tablePen()); - - auto width = painter.device()->width(); - auto height = 1.5 * painter.fontMetrics().lineSpacing(); - - std::set blockStarters = {0, 3, 5, 7}; - std::set v2Tests = {0, 1, 3, 5, 7, 8}; - std::set svkTests = {2, 4, 6, 9, 10}; - - double x = 0; - double y = 0; - auto testIndex = 0; - for (const auto &test : m_tests) - { - double rowHeaderWidth = 0.2 * width; - double resultCellWidth = test.size() > 8 ? 0.05 * width : 0.1 * width; - double rowHeight = height; - - if (blockStarters.find(testIndex) != blockStarters.end()) - { - y += rowHeight; - drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, test.name()); - x += rowHeaderWidth; - - std::vector> columnHeaders; - for (const auto &item : test.items()) - { - const auto &itemText = item.getText(); - if (!columnHeaders.empty() && columnHeaders.back().first == itemText) - { - columnHeaders.back().second++; - } - else - { - columnHeaders.emplace_back(itemText, 1); - } - } - - for (const auto &columnHeader : columnHeaders) - { - double cellWidth = columnHeader.second * resultCellWidth; - drawTextSquare(painter, {x, y, cellWidth, rowHeight}, columnHeader.first.c_str()); - x += cellWidth; - } - x = rowHeaderWidth; - y += rowHeight; - } - else - { - drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, test.name()); - x += rowHeaderWidth; - } - - unsigned int emptyItemsStack = 0; - for (const auto &item : test.items()) - { - if (item.getText().empty()) - { - emptyItemsStack++; - } - else - { - if (emptyItemsStack > 0) - { - drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y, - emptyItemsStack * resultCellWidth, rowHeight}); - emptyItemsStack = 0; - } - - drawCheckSquare(painter, {x, y, resultCellWidth, rowHeight}, item.isChecked()); - } - x += resultCellWidth; - } - if (emptyItemsStack > 0) - { - drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y, - emptyItemsStack * resultCellWidth, rowHeight}); - emptyItemsStack = 0; - } - - if (v2Tests.find(testIndex) != v2Tests.end()) - { - drawResultSquare(painter, y, false, test.getPoints()); - } - - if (svkTests.find(testIndex) != svkTests.end()) - { - drawResultSquare(painter, y, true, test.getPoints()); - } - - x = 0; - y += rowHeight; - - testIndex++; - } - - x = 0; - y += height; - - painter.drawText(x, y, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, - "Rohwertpunkte Total:"); - drawResultSquare(painter, y, false, getV2Points()); - drawResultSquare(painter, y, true, getSvkPoints()); -} +std::set WFModel::svkTests() const +{ + return {2}; +}; diff --git a/source/SubTests/V2Svk/WFModel.h b/source/SubTests/V2Svk/WFModel.h index 9f2fa28..a3d801d 100644 --- a/source/SubTests/V2Svk/WFModel.h +++ b/source/SubTests/V2Svk/WFModel.h @@ -1,25 +1,24 @@ #pragma once -#include "PrintableModel.h" - -#include "CheckableTestModel.h" +#include "V2SvkModel.h" #include "V2SvkModel.pb.h" -class WFModel : public CheckableTestModel, public PrintableModel +class WFModel : public V2SvkModel { Q_OBJECT public: WFModel(QObject *parent); - unsigned int getV2Points() const; - unsigned int getSvkPoints() const; + unsigned int getV2Points() const override; + unsigned int getSvkPoints() const override; - void write(ESGRAF48::V2SvkModel &model) const; - void read(const ESGRAF48::V2SvkModel &model); - - void printTo(QPainter &painter) const override; + void write(ESGRAF48::V2SvkModel &model) const override; + void read(const ESGRAF48::V2SvkModel &model) override; protected: + std::set v2Tests() const override; + std::set svkTests() const override; + bool isValidIndex(const QModelIndex &index) const override; }; diff --git a/source/SubTests/VerbEnd/CMakeLists.txt b/source/SubTests/VerbEnd/CMakeLists.txt index 1302223..135ab66 100644 --- a/source/SubTests/VerbEnd/CMakeLists.txt +++ b/source/SubTests/VerbEnd/CMakeLists.txt @@ -42,6 +42,7 @@ target_link_libraries(${PROJECT_NAME} CheckableItem CheckableTest CheckableTestModel + PrintableModel Qt5::Widgets ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index dea4d95..6aa3503 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -1,8 +1,10 @@ #include "VerbEndModel.h" VerbEndModel::VerbEndModel(QObject *parent) - : CheckableTestModel(parent) + : PrintableModel(parent) { + m_title = "Subtest 2: Verbendstellungsregel (VE)"; + m_tests = { { "Telefonat", { "Kausal", "Kausal", "Relativ", "Kausal", "Final", "Temporal", "Temporal" } }, @@ -98,3 +100,4 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index cf6342a..8baee48 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -1,9 +1,9 @@ #pragma once -#include "CheckableTestModel.h" +#include "PrintableModel.h" #include "VerbEndModel.pb.h" -class VerbEndModel : public CheckableTestModel +class VerbEndModel : public PrintableModel { Q_OBJECT diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 7e96907..3a29063 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -178,12 +178,7 @@ void MainWindow::print() const return; } - QPainter painter; - painter.begin(&printer); - - m_dataModel.printTo(painter); - - painter.end(); + m_dataModel.printTo(printer); } void MainWindow::dataModelChanged() @@ -242,12 +237,7 @@ void MainWindow::savePdf(const QString &filename) printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); printer.setOutputFileName(filename); - QPainter painter; - painter.begin(&printer); - - m_dataModel.printTo(painter); - - painter.end(); + m_dataModel.printTo(printer); } void MainWindow::aboutDialog()