From 51271e959529a25985ca634fd378d0ea444ab65a Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 7 Feb 2019 22:36:39 +0100 Subject: [PATCH] Print subtest 6 and results --- source/DataModel.cpp | 6 +- source/PrintableModel/PrintableModel.cpp | 2 +- source/PrintableModel/PrintableModel.h | 2 +- source/ResultWidget/CMakeLists.txt | 1 + source/ResultWidget/ResultModel.cpp | 82 +++++++++++++++---- source/ResultWidget/ResultModel.h | 4 + source/SubTests/AkkusativDativ/DativModel.cpp | 5 ++ source/SubTests/AkkusativDativ/DativModel.h | 2 +- source/SubTests/LateSkills/CMakeLists.txt | 5 +- source/SubTests/LateSkills/GenitivModel.cpp | 7 +- source/SubTests/LateSkills/GenitivModel.h | 7 +- .../SubTests/LateSkills/LateSkillsModel.cpp | 64 +++++++++++++++ source/SubTests/LateSkills/LateSkillsModel.h | 15 ++++ source/SubTests/LateSkills/PassivModel.cpp | 7 +- source/SubTests/LateSkills/PassivModel.h | 10 ++- source/SubTests/Plural/PluralModel.cpp | 5 +- 16 files changed, 187 insertions(+), 37 deletions(-) create mode 100644 source/SubTests/LateSkills/LateSkillsModel.cpp create mode 100644 source/SubTests/LateSkills/LateSkillsModel.h diff --git a/source/DataModel.cpp b/source/DataModel.cpp index b674978..0b7332b 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -105,7 +105,6 @@ void DataModel::printTo(QPrinter &printer) const 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()); @@ -132,6 +131,11 @@ void DataModel::printTo(QPrinter &printer) const m_dativ.printTo(painter); m_plural.printTo(painter); + m_passiv.printTo(painter); + m_genitiv.printTo(painter); + + m_results.printTo(painter); + painter.end(); } diff --git a/source/PrintableModel/PrintableModel.cpp b/source/PrintableModel/PrintableModel.cpp index 3107942..2423ba0 100644 --- a/source/PrintableModel/PrintableModel.cpp +++ b/source/PrintableModel/PrintableModel.cpp @@ -46,7 +46,7 @@ double PrintableModel::headerWidthFactor() double PrintableModel::cellWidthFactor() { - return 0.085; + return headerWidthFactor() / 2; } void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text) diff --git a/source/PrintableModel/PrintableModel.h b/source/PrintableModel/PrintableModel.h index eb1daeb..3cbced8 100644 --- a/source/PrintableModel/PrintableModel.h +++ b/source/PrintableModel/PrintableModel.h @@ -33,9 +33,9 @@ public: 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); +protected: virtual void printHeader(QPainter &painter) const; virtual void printTests(QPainter &painter) const; virtual void printSummary(QPainter &painter) const; diff --git a/source/ResultWidget/CMakeLists.txt b/source/ResultWidget/CMakeLists.txt index bfdd22c..437eeab 100644 --- a/source/ResultWidget/CMakeLists.txt +++ b/source/ResultWidget/CMakeLists.txt @@ -30,6 +30,7 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE + PrintableModel Age Qt5::Widgets ) diff --git a/source/ResultWidget/ResultModel.cpp b/source/ResultWidget/ResultModel.cpp index c905346..85cf097 100644 --- a/source/ResultWidget/ResultModel.cpp +++ b/source/ResultWidget/ResultModel.cpp @@ -10,13 +10,14 @@ #include "PassivPR.h" #include "GenitivPR.h" +#include "PrintableModel.h" + #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 +82,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) { @@ -170,7 +170,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,20 +193,66 @@ 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(QPainter &painter) const +{ + PrintableModel::drawHeader2(painter, "Prozentränge (PR)"); + + painter.setFont(PrintableModel::tableFont()); + painter.setPen(PrintableModel::tablePen()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + double cellWidth = width / (m_results.size() + 1); + double rowHeight = 2 * height; + + double x = 0; + double y = 0; + + PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, ""); + PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight}, + "\u2265 PR 84"); + PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight}, + "< PR 84"); + + PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight}); + PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight}, + "\u2264 PR 16"); + + x += cellWidth; + for (const auto &result : m_results) + { + PrintableModel::drawTextSquare(painter, {x, y + 0 * rowHeight, cellWidth, rowHeight}, + result.name()); + const auto pr = result.pr(); + + PrintableModel::drawTextSquare(painter, {x, y + 1 * rowHeight, cellWidth, rowHeight}, + pr >= 84 ? QString::number(pr) : "-"); + PrintableModel::drawTextSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight}, + pr < 84 && pr > 16 ? QString::number(pr) : "-"); + + PrintableModel::drawGreySquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight}); + PrintableModel::drawTextSquare(painter, {x, y + 3 * rowHeight, cellWidth, rowHeight}, + pr <= 16 ? QString::number(pr) : "-"); + + x += cellWidth; + } } diff --git a/source/ResultWidget/ResultModel.h b/source/ResultWidget/ResultModel.h index ae6dd78..2430f62 100644 --- a/source/ResultWidget/ResultModel.h +++ b/source/ResultWidget/ResultModel.h @@ -1,7 +1,9 @@ #pragma once #include "Age.h" + #include +#include class TestResult { @@ -72,4 +74,6 @@ public: void setSvkResult(unsigned int points); void setPassivResult(unsigned int points); void setGenitivResult(unsigned int points); + + void printTo(QPainter &painter) const; }; diff --git a/source/SubTests/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index 9a7cfa5..c0a7560 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -105,3 +105,8 @@ void DativModel::write(ESGRAF48::DativModel &model) const nomTiereModel->set_katze(testItems[7].isChecked()); } } + +void DativModel::printHeader(QPainter &painter) const +{ + painter.translate(0, -1.5 * painter.fontMetrics().lineSpacing()); +} diff --git a/source/SubTests/AkkusativDativ/DativModel.h b/source/SubTests/AkkusativDativ/DativModel.h index c6c83f0..9b21add 100644 --- a/source/SubTests/AkkusativDativ/DativModel.h +++ b/source/SubTests/AkkusativDativ/DativModel.h @@ -14,5 +14,5 @@ public: void write(ESGRAF48::DativModel &model) const; protected: - void printHeader(QPainter &) const override {}; + void printHeader(QPainter &painter) const override; }; diff --git a/source/SubTests/LateSkills/CMakeLists.txt b/source/SubTests/LateSkills/CMakeLists.txt index 7fef071..a32a4d9 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} @@ -43,9 +44,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/LateSkills/GenitivModel.cpp b/source/SubTests/LateSkills/GenitivModel.cpp index 9ebf423..6fcf26c 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", @@ -107,3 +107,8 @@ void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel &model) const attributierungModel->set_guertel2(testItems[9].isChecked()); } } + +void GenitivModel::printHeader(QPainter &painter) const +{ + painter.translate(0, -1.5 * painter.fontMetrics().lineSpacing()); +} diff --git a/source/SubTests/LateSkills/GenitivModel.h b/source/SubTests/LateSkills/GenitivModel.h index 2346e94..4923828 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 @@ -14,4 +14,7 @@ public: void read(const ESGRAF48::LateSkillsGenitivModel &model); void write(ESGRAF48::LateSkillsGenitivModel &model) const; + +protected: + void printHeader(QPainter &painter) const override; }; diff --git a/source/SubTests/LateSkills/LateSkillsModel.cpp b/source/SubTests/LateSkills/LateSkillsModel.cpp new file mode 100644 index 0000000..1f441ce --- /dev/null +++ b/source/SubTests/LateSkills/LateSkillsModel.cpp @@ -0,0 +1,64 @@ +#include "LateSkillsModel.h" + +#include + +LateSkillsModel::LateSkillsModel(QObject *parent) + : PrintableModel(parent) +{ +} + +void LateSkillsModel::printTests(QPainter &painter) const +{ + painter.setFont(tableFont()); + painter.setPen(tablePen()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + double headerWidth = headerWidthFactor() * width; + double cellHeaderWidth = cellWidthFactor() * width; + double cellWidth = 0.5 * cellHeaderWidth; + double rowHeight = height; + + double x = 0; + double y = 0; + for (const auto &test : m_tests) + { + QString testName = QString::fromStdString( + std::regex_replace(test.name().toStdString(), std::regex("\\s"), "\n")); + + drawTextSquare(painter, {0, y, headerWidth, 3 * rowHeight}, testName); + + const auto &items = test.items(); + + x = headerWidth; + for (unsigned int i = 0; i < items.size(); i += 2) + { + const auto &item = test.items().at(i); + QString itemText = QString::fromStdString(item.getText()).split(" ").at(0); + + drawTextSquare(painter, {x, y, cellHeaderWidth, rowHeight}, itemText); + + x += cellHeaderWidth; + } + y += rowHeight; + + x = headerWidth; + for (const auto &item : items) + { + drawTextSquare(painter, {x, y, cellWidth, rowHeight}, QString::number(item.value())); + drawCheckSquare(painter, {x, y + rowHeight, cellWidth, rowHeight}, item.isChecked()); + + x += cellWidth; + } + + if (m_tests.size() > 1) + { + drawResultSquare(painter, y + rowHeight, true, test.getPoints()); + } + + y += 2 * rowHeight; + } + + painter.translate(0, y + rowHeight); +} diff --git a/source/SubTests/LateSkills/LateSkillsModel.h b/source/SubTests/LateSkills/LateSkillsModel.h new file mode 100644 index 0000000..8049f51 --- /dev/null +++ b/source/SubTests/LateSkills/LateSkillsModel.h @@ -0,0 +1,15 @@ +#pragma once + +#include "PrintableModel.h" +#include "LateSkillsPassivModel.pb.h" + +class LateSkillsModel : public PrintableModel +{ + Q_OBJECT + +public: + LateSkillsModel(QObject *parent); + +protected: + void printTests(QPainter &painter) const override; +}; diff --git a/source/SubTests/LateSkills/PassivModel.cpp b/source/SubTests/LateSkills/PassivModel.cpp index 6f1d3a8..d54d1c3 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)", @@ -65,3 +65,8 @@ void PassivModel::write(ESGRAF48::LateSkillsPassivModel &model) const model.set_fleisch1(testItems[8].isChecked()); model.set_fleisch2(testItems[9].isChecked()); } + +void PassivModel::printHeader(QPainter &painter) const +{ + drawHeader2(painter, "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..d6aabfd 100644 --- a/source/SubTests/LateSkills/PassivModel.h +++ b/source/SubTests/LateSkills/PassivModel.h @@ -1,17 +1,19 @@ #pragma once -#include "CheckableTestModel.h" +#include "LateSkillsModel.h" #include "LateSkillsPassivModel.pb.h" -class PassivModel : public CheckableTestModel +class PassivModel : public LateSkillsModel { Q_OBJECT public: PassivModel(QObject *parent); - 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::LateSkillsPassivModel &model); void write(ESGRAF48::LateSkillsPassivModel &model) const; + +protected: + void printHeader(QPainter &painter) const override; }; diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index b310ae2..cc9568e 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -76,10 +76,7 @@ void PluralModel::printTests(QPainter &painter) const x += cellWidth; } - y += rowHeight; - - drawResultSquare(painter, y, true, test.getPoints()); - y += rowHeight; + y += 2 * rowHeight; } painter.translate(0, y + 2 * rowHeight);