From 59c409c872772203b2d3dce8501d23336bed87ae Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 12 Jan 2019 16:50:04 +0100 Subject: [PATCH 01/12] Print headline and meta-data --- source/CMakeLists.txt | 1 + source/DataModel.cpp | 26 +++---------- source/DataModel.h | 31 +++------------- source/MetaData/MetaDataModel.cpp | 62 +++++++++++++++---------------- source/MetaData/MetaDataModel.h | 7 ++-- source/PrintableModel.cpp | 12 ++++++ source/PrintableModel.h | 13 +++++++ source/mainwindow.cpp | 23 +++++++----- source/mainwindow.h | 1 + 9 files changed, 87 insertions(+), 89 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..895a7a4 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -35,6 +35,7 @@ protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS add_executable(${PROJECT_NAME} WIN32 ESGRAF48.cpp + PrintableModel.cpp DataModel.cpp mainwindow.cpp ${LOGO_TEST_UI} diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 216eb8c..d108729 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -59,28 +59,14 @@ void DataModel::read(std::istream &inStream) m_genitiv.read(dataModel.lateskillsgenitiv()); m_passiv.read(dataModel.lateskillspassiv()); } - -std::string DataModel::toHtml() const + +void DataModel::printTo(QPainter &painter) const { - std::stringstream out; + painter.setFont(h1Font()); + painter.drawText(0, painter.fontMetrics().lineSpacing(), "ESGRAF 4-8 Auswertungsbogen"); + painter.translate(0, 3 * painter.fontMetrics().lineSpacing()); - 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(); + m_metaData.printTo(painter); } void DataModel::pluralModelChanged() diff --git a/source/DataModel.h b/source/DataModel.h index 71a9352..3469e3e 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -1,5 +1,7 @@ #pragma once +#include "PrintableModel.h" + #include "MetaData/MetaDataModel.h" #include "GenusModel.h" #include "VerbEndModel.h" @@ -12,9 +14,9 @@ #include "ResultModel.h" -#include +#include -class DataModel : public QObject +class DataModel : public QObject, public PrintableModel { Q_OBJECT @@ -34,35 +36,14 @@ public: public: DataModel(QObject *parent); - std::string toHtml() const; - void write(std::ostream &outStream) const; void read(std::istream &inStream); + void printTo(QPainter &painter) const override; + 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 94c2a62..32ab815 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -130,39 +130,37 @@ void MetaDataModel::write(ESGRAF48::MetaDataModel &model) const model.set_remarks(m_remarks.toStdString()); } -std::string MetaDataModel::toHtml() const +void MetaDataModel::printTo(QPainter &painter) const { - std::ostringstream out; + painter.setFont(tableFont()); - 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 << "
Name, Vorname" << m_participant.toHtmlEscaped().toStdString() << "Untersucher(in)" << m_instructor.toHtmlEscaped().toStdString() << "
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() << "
Alter am Testtag" << getAge().toString() << "
" << std::endl; + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); - return out.str(); + auto hasRemarks = !m_remarks.trimmed().isEmpty(); + + painter.drawText(0, 0, "Name, Vorname"); + painter.drawText(0.25 * width, 0, m_participant); + painter.drawText(0.5 * width, 0, "Untersucher(in)"); + painter.drawText(0.75 * width, 0, m_instructor); + + painter.translate(0, height); + + painter.drawText(0, 0, "Geburtsdatum"); + painter.drawText(0.25 * width, 0, m_dateOfBirth.toString("dd.MM.yyyy")); + if (hasRemarks) + { + painter.drawText(0.5 * width, 0, "Bemerkungen:"); + painter.drawText(QRect(0.5 * width, 0.5 * height, width, 2 * height), m_remarks); + } + + painter.translate(0, height); + + painter.drawText(0, 0, "Untersuchungsdatum"); + painter.drawText(0.25 * width, 0, m_dateOfTest.toString("dd.MM.yyyy")); + + painter.translate(0, height); + + painter.drawText(0, 0, "Alter am Testtag"); + painter.drawText(0.25 * width, 0, getAge().toString().c_str()); } diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 0c8bbeb..3164b90 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -1,5 +1,7 @@ #pragma once +#include "../PrintableModel.h" + #include "Age.h" #include "MetaDataModel.pb.h" @@ -7,9 +9,8 @@ #include #include #include -#include -class MetaDataModel : public QAbstractTableModel +class MetaDataModel : public QAbstractTableModel, public PrintableModel { Q_OBJECT @@ -33,7 +34,7 @@ public: void read(const ESGRAF48::MetaDataModel &model); void write(ESGRAF48::MetaDataModel &model) const; - std::string toHtml() const; + void printTo(QPainter &painter) const override; Age getAge() const { diff --git a/source/PrintableModel.cpp b/source/PrintableModel.cpp new file mode 100644 index 0000000..ba9c0a1 --- /dev/null +++ b/source/PrintableModel.cpp @@ -0,0 +1,12 @@ +#include "PrintableModel.h" + +QFont PrintableModel::h1Font() +{ + return QFont("Helvetica", 16); +} + +QFont PrintableModel::tableFont() +{ + return QFont("Helvetica", 10); +} + diff --git a/source/PrintableModel.h b/source/PrintableModel.h new file mode 100644 index 0000000..46d2c65 --- /dev/null +++ b/source/PrintableModel.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +class PrintableModel +{ +public: + virtual void printTo(QPainter &painter) const = 0; + +protected: + static QFont h1Font(); + static QFont tableFont(); +}; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index e91549a..0a5c8de 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -150,10 +151,9 @@ void MainWindow::closeFile() void MainWindow::print() const { - //std::ofstream htmlfile("print.html"); - //htmlfile << m_dataModel.toHtml(); - QPrinter printer; + printer.setPaperSize(QPrinter::A4); + printer.setPageMargins(30, 20, 30, 20, QPrinter::Millimeter); QPrintDialog dialog(&printer); if (dialog.exec() != QDialog::Accepted) @@ -161,10 +161,12 @@ void MainWindow::print() const return; } - QTextDocument printDoc; - printDoc.setHtml(QString::fromStdString(m_dataModel.toHtml())); + QPainter painter; + painter.begin(&printer); - printDoc.print(&printer); + m_dataModel.printTo(painter); + + painter.end(); } void MainWindow::dataModelChanged() @@ -213,10 +215,13 @@ void MainWindow::savePdf(const QString &filename) QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setPaperSize(QPrinter::A4); + printer.setPageMargins(30, 20, 30, 20, QPrinter::Millimeter); printer.setOutputFileName(filename); - QTextDocument printDoc; - printDoc.setHtml(QString::fromStdString(m_dataModel.toHtml())); + QPainter painter; + painter.begin(&printer); - printDoc.print(&printer); + m_dataModel.printTo(painter); + + painter.end(); } diff --git a/source/mainwindow.h b/source/mainwindow.h index 9675fb7..006262f 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -4,6 +4,7 @@ #include #include +#include class DataModel; From 463dc275d05b6f78e9b9d819ab735a2fdd30c0a1 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 12 Jan 2019 21:42:52 +0100 Subject: [PATCH 02/12] Some prototypical table output --- source/DataModel.cpp | 1 + source/MetaData/MetaDataModel.cpp | 2 + source/PrintableModel.cpp | 9 +++ source/PrintableModel.h | 3 + source/SubTests/V2Svk/V2SvkModel.cpp | 101 +++++++++++++++++++++++++++ source/SubTests/V2Svk/V2SvkModel.h | 6 +- 6 files changed, 121 insertions(+), 1 deletion(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index d108729..9376392 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -67,6 +67,7 @@ void DataModel::printTo(QPainter &painter) const painter.translate(0, 3 * painter.fontMetrics().lineSpacing()); m_metaData.printTo(painter); + m_v2Svk.printTo(painter); } void DataModel::pluralModelChanged() diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 32ab815..5eecf6a 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -163,4 +163,6 @@ void MetaDataModel::printTo(QPainter &painter) const painter.drawText(0, 0, "Alter am Testtag"); painter.drawText(0.25 * width, 0, getAge().toString().c_str()); + + painter.translate(0, 2 * height); } diff --git a/source/PrintableModel.cpp b/source/PrintableModel.cpp index ba9c0a1..7da134b 100644 --- a/source/PrintableModel.cpp +++ b/source/PrintableModel.cpp @@ -5,8 +5,17 @@ QFont PrintableModel::h1Font() return QFont("Helvetica", 16); } +QFont PrintableModel::h2Font() +{ + return QFont("Helvetica", 12); +} + QFont PrintableModel::tableFont() { return QFont("Helvetica", 10); } +QPen PrintableModel::tablePen() +{ + return QPen(Qt::black, 1, Qt::SolidLine); +} diff --git a/source/PrintableModel.h b/source/PrintableModel.h index 46d2c65..5d99c31 100644 --- a/source/PrintableModel.h +++ b/source/PrintableModel.h @@ -9,5 +9,8 @@ public: protected: static QFont h1Font(); + static QFont h2Font(); static QFont tableFont(); + + static QPen tablePen(); }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 2196ba4..17e4284 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -199,3 +199,104 @@ void V2SvkModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +void V2SvkModel::printTo(QPainter &painter) const +{ + painter.setFont(h2Font()); + + painter.drawText( + 0, 0, "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"); + + painter.translate(0, 1.5 * painter.fontMetrics().lineSpacing()); + + painter.setFont(tableFont()); + painter.setPen(tablePen()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + auto drawTextSquare = [&](double left, double top, double width, double height, + const QString &text) { + painter.drawText(left, top, width, height, Qt::AlignCenter, text); + painter.drawLine(left, top, left + width, top); + painter.drawLine(left + width, top, left + width, top + height); + painter.drawLine(left + width, top + height, left, top + height); + painter.drawLine(left, top + height, left, top); + }; + + auto drawCheckSquare = [&](double left, double top, double width, double height, bool checked) { + drawTextSquare(left, top, width, height, checked ? "\u2612" : "\u2610"); + }; + + auto drawResultSquare = [&](bool right, bool bold, unsigned int value, double y) { + double cellWidth = 0.03 * width; + double x = width - cellWidth - (right ? 0 : 0.04 * width); + + drawTextSquare(x, y, cellWidth, height, QString::number(value)); + }; + + auto drawGreySquare = [&](double left, double top, double width, double height) { + auto prevBrush = painter.brush(); + + painter.setBrush(QBrush(QColor(224, 224, 224))); + painter.drawRect(left, top, width, height); + + painter.setBrush(prevBrush); + }; + + auto x = 0.0; + auto y = 0.0; + auto cellWidth = 0.2 * width; + drawTextSquare(x, y, cellWidth, 2 * height, "W-Fragen"); + x += cellWidth; + drawTextSquare(x, y, cellWidth, height, "Affe"); + x += cellWidth; + drawTextSquare(x, y, cellWidth, height, "Schwein"); + x += cellWidth; + drawTextSquare(x, y, cellWidth, height, "Gans"); + + x = 0.2 * width; + y += height; + cellWidth = 0.05 * width; + for (int i = 0; i < 12; ++i) + { + drawCheckSquare(x, y, cellWidth, height, true); + x += cellWidth; + } + drawResultSquare(false, false, 9, y); + + x = 0; + y += height; + cellWidth = 0.2 * width; + drawTextSquare(x, y, cellWidth, height, "Verbtrennung"); + x += cellWidth; + cellWidth = 0.05 * width; + drawGreySquare(x, y, cellWidth, height); + x += cellWidth; + drawCheckSquare(x, y, cellWidth, height, true); + x += cellWidth; + drawGreySquare(x, y, 5 * cellWidth, height); + x += 5 * cellWidth; + drawCheckSquare(x, y, cellWidth, height, true); + x += cellWidth; + drawGreySquare(x, y, 2 * cellWidth, height); + x += 2 * cellWidth; + drawCheckSquare(x, y, cellWidth, height, true); + x += cellWidth; + drawGreySquare(x, y, cellWidth, height); + x += cellWidth; + drawResultSquare(false, false, 2, y); + + x = 0; + y += height; + cellWidth = 0.2 * width; + drawTextSquare(x, y, cellWidth, height, "SVK: /-st/"); + x += cellWidth; + cellWidth = 0.05 * width; + for (int i = 0; i < 12; ++i) + { + drawCheckSquare(x, y, cellWidth, height, true); + x += cellWidth; + } + drawResultSquare(true, false, 8, y); +} diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index 519508a..becad53 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -1,9 +1,11 @@ #pragma once +#include "../../PrintableModel.h" + #include "CheckableTestModel.h" #include "V2SvkModel.pb.h" -class V2SvkModel : public CheckableTestModel +class V2SvkModel : public CheckableTestModel, public PrintableModel { Q_OBJECT @@ -16,6 +18,8 @@ public: void write(ESGRAF48::V2SvkModel &model) const; void read(const ESGRAF48::V2SvkModel &model); + void printTo(QPainter &painter) const override; + protected: bool isValidIndex(const QModelIndex &index) const override; }; From 61bcb7566c22f006f1f151c41ec9dfc0fb4e37c0 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 13 Jan 2019 18:44:07 +0100 Subject: [PATCH 03/12] Print subtest 1 --- 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 | 24 --- .../CheckableTestModel/CheckableTestModel.h | 3 - source/PrintableModel.cpp | 2 +- source/SubTests/V2Svk/V2SvkModel.cpp | 161 ++++++++++++------ source/SubTests/V2Svk/V2SvkModel.h | 4 +- source/mainwindow.cpp | 4 +- 12 files changed, 127 insertions(+), 135 deletions(-) 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..7b66014 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()) 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/PrintableModel.cpp b/source/PrintableModel.cpp index 7da134b..2f5a16c 100644 --- a/source/PrintableModel.cpp +++ b/source/PrintableModel.cpp @@ -12,7 +12,7 @@ QFont PrintableModel::h2Font() QFont PrintableModel::tableFont() { - return QFont("Helvetica", 10); + return QFont("Helvetica", 8); } QPen PrintableModel::tablePen() diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 17e4284..e621207 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -29,7 +29,7 @@ V2SvkModel::V2SvkModel(QObject *parent) }; } -unsigned int V2SvkModel::getV2Points() +unsigned int V2SvkModel::getV2Points() const { unsigned int points = 0; @@ -49,7 +49,7 @@ unsigned int V2SvkModel::getV2Points() return points; } -unsigned int V2SvkModel::getSvkPoints() +unsigned int V2SvkModel::getSvkPoints() const { unsigned int points = 0; @@ -207,8 +207,6 @@ void V2SvkModel::printTo(QPainter &painter) const painter.drawText( 0, 0, "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"); - painter.translate(0, 1.5 * painter.fontMetrics().lineSpacing()); - painter.setFont(tableFont()); painter.setPen(tablePen()); @@ -228,7 +226,7 @@ void V2SvkModel::printTo(QPainter &painter) const drawTextSquare(left, top, width, height, checked ? "\u2612" : "\u2610"); }; - auto drawResultSquare = [&](bool right, bool bold, unsigned int value, double y) { + auto drawResultSquare = [&](bool right, unsigned int value, double y) { double cellWidth = 0.03 * width; double x = width - cellWidth - (right ? 0 : 0.04 * width); @@ -237,66 +235,119 @@ void V2SvkModel::printTo(QPainter &painter) const auto drawGreySquare = [&](double left, double top, double width, double height) { auto prevBrush = painter.brush(); + auto prevPen = painter.pen(); painter.setBrush(QBrush(QColor(224, 224, 224))); - painter.drawRect(left, top, width, height); - + painter.setPen(QPen(Qt::NoPen)); + QPointF points[4] = {{left, top}, {left + width, top}, {left + width, top + height}, {left, top + height}}; + painter.drawPolygon(points, 4); + + painter.setPen(tablePen()); + painter.drawLine(left, top, left + width, top); + painter.drawLine(left + width, top, left + width, top + height); + painter.drawLine(left + width, top + height, left, top + height); + painter.drawLine(left, top + height, left, top); + painter.setBrush(prevBrush); + painter.setPen(prevPen); }; - auto x = 0.0; - auto y = 0.0; - auto cellWidth = 0.2 * width; - drawTextSquare(x, y, cellWidth, 2 * height, "W-Fragen"); - x += cellWidth; - drawTextSquare(x, y, cellWidth, height, "Affe"); - x += cellWidth; - drawTextSquare(x, y, cellWidth, height, "Schwein"); - x += cellWidth; - drawTextSquare(x, y, cellWidth, height, "Gans"); + std::set blockStarters = {0, 3, 5, 7}; + std::set v2Tests = {0, 1, 3, 5, 7, 8}; + std::set svkTests = {2, 4, 6, 9, 10}; - x = 0.2 * width; - y += height; - cellWidth = 0.05 * width; - for (int i = 0; i < 12; ++i) + double x = 0; + double y = 0; + auto testIndex = 0; + for (const auto &test : m_tests) { - drawCheckSquare(x, y, cellWidth, height, true); - x += cellWidth; + 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(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(x, y, cellWidth, rowHeight, columnHeader.first.c_str()); + x += cellWidth; + } + x = rowHeaderWidth; + y += rowHeight; + } + else + { + drawTextSquare(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(x - emptyItemsStack * resultCellWidth, y, + emptyItemsStack * resultCellWidth, rowHeight); + emptyItemsStack = 0; + } + + drawCheckSquare(x, y, resultCellWidth, rowHeight, item.isChecked()); + } + x += resultCellWidth; + } + if (emptyItemsStack > 0) + { + drawGreySquare(x - emptyItemsStack * resultCellWidth, y, + emptyItemsStack * resultCellWidth, rowHeight); + emptyItemsStack = 0; + } + + if (v2Tests.find(testIndex) != v2Tests.end()) + { + drawResultSquare(false, test.getPoints(), y); + } + + if (svkTests.find(testIndex) != svkTests.end()) + { + drawResultSquare(true, test.getPoints(), y); + } + + x = 0; + y += rowHeight; + + testIndex++; } - drawResultSquare(false, false, 9, y); x = 0; y += height; - cellWidth = 0.2 * width; - drawTextSquare(x, y, cellWidth, height, "Verbtrennung"); - x += cellWidth; - cellWidth = 0.05 * width; - drawGreySquare(x, y, cellWidth, height); - x += cellWidth; - drawCheckSquare(x, y, cellWidth, height, true); - x += cellWidth; - drawGreySquare(x, y, 5 * cellWidth, height); - x += 5 * cellWidth; - drawCheckSquare(x, y, cellWidth, height, true); - x += cellWidth; - drawGreySquare(x, y, 2 * cellWidth, height); - x += 2 * cellWidth; - drawCheckSquare(x, y, cellWidth, height, true); - x += cellWidth; - drawGreySquare(x, y, cellWidth, height); - x += cellWidth; - drawResultSquare(false, false, 2, y); - x = 0; - y += height; - cellWidth = 0.2 * width; - drawTextSquare(x, y, cellWidth, height, "SVK: /-st/"); - x += cellWidth; - cellWidth = 0.05 * width; - for (int i = 0; i < 12; ++i) - { - drawCheckSquare(x, y, cellWidth, height, true); - x += cellWidth; - } - drawResultSquare(true, false, 8, y); + painter.drawText(x, y, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, + "Rohwertpunkte Total:"); + drawResultSquare(false, getV2Points(), y); + drawResultSquare(true, getSvkPoints(), y); } diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index becad53..c7090c3 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -12,8 +12,8 @@ class V2SvkModel : public CheckableTestModel, public PrintableModel 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); diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 0a5c8de..88a67e3 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -153,7 +153,7 @@ void MainWindow::print() const { QPrinter printer; printer.setPaperSize(QPrinter::A4); - printer.setPageMargins(30, 20, 30, 20, QPrinter::Millimeter); + printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); QPrintDialog dialog(&printer); if (dialog.exec() != QDialog::Accepted) @@ -215,7 +215,7 @@ void MainWindow::savePdf(const QString &filename) QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setPaperSize(QPrinter::A4); - printer.setPageMargins(30, 20, 30, 20, QPrinter::Millimeter); + printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); printer.setOutputFileName(filename); QPainter painter; From d298238ae88ca60ee295a5e79a024e262040e95c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 13 Jan 2019 19:54:09 +0100 Subject: [PATCH 04/12] Refactored printing code from model to base-class --- source/CMakeLists.txt | 3 +- source/MetaData/CMakeLists.txt | 1 + source/MetaData/MetaDataModel.h | 2 +- source/PrintableModel.cpp | 21 ------- source/PrintableModel.h | 16 ----- source/PrintableModel/CMakeLists.txt | 25 ++++++++ source/PrintableModel/PrintableModel.cpp | 78 ++++++++++++++++++++++++ source/PrintableModel/PrintableModel.h | 25 ++++++++ source/SubTests/V2Svk/CMakeLists.txt | 1 + source/SubTests/V2Svk/V2SvkModel.cpp | 63 ++++--------------- source/SubTests/V2Svk/V2SvkModel.h | 2 +- 11 files changed, 146 insertions(+), 91 deletions(-) delete mode 100644 source/PrintableModel.cpp delete mode 100644 source/PrintableModel.h create mode 100644 source/PrintableModel/CMakeLists.txt create mode 100644 source/PrintableModel/PrintableModel.cpp create mode 100644 source/PrintableModel/PrintableModel.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 895a7a4..f1329f6 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -35,7 +35,6 @@ protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS add_executable(${PROJECT_NAME} WIN32 ESGRAF48.cpp - PrintableModel.cpp DataModel.cpp mainwindow.cpp ${LOGO_TEST_UI} @@ -61,6 +60,7 @@ target_link_libraries(${PROJECT_NAME} CheckableItem CheckableTest CheckableTestModel + PrintableModel MetaData VerbEnd Plural @@ -78,6 +78,7 @@ add_subdirectory(Age) add_subdirectory(CheckableItem) add_subdirectory(CheckableTest) add_subdirectory(CheckableTestModel) +add_subdirectory(PrintableModel) add_subdirectory(MetaData) add_subdirectory(SubTests) diff --git a/source/MetaData/CMakeLists.txt b/source/MetaData/CMakeLists.txt index e00d8de..ab2b0f0 100644 --- a/source/MetaData/CMakeLists.txt +++ b/source/MetaData/CMakeLists.txt @@ -42,6 +42,7 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE Age + PrintableModel Qt5::Widgets ${Protobuf_LIBRARIES} ) diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 3164b90..7774f99 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -1,6 +1,6 @@ #pragma once -#include "../PrintableModel.h" +#include "PrintableModel.h" #include "Age.h" diff --git a/source/PrintableModel.cpp b/source/PrintableModel.cpp deleted file mode 100644 index 2f5a16c..0000000 --- a/source/PrintableModel.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "PrintableModel.h" - -QFont PrintableModel::h1Font() -{ - return QFont("Helvetica", 16); -} - -QFont PrintableModel::h2Font() -{ - return QFont("Helvetica", 12); -} - -QFont PrintableModel::tableFont() -{ - return QFont("Helvetica", 8); -} - -QPen PrintableModel::tablePen() -{ - return QPen(Qt::black, 1, Qt::SolidLine); -} diff --git a/source/PrintableModel.h b/source/PrintableModel.h deleted file mode 100644 index 5d99c31..0000000 --- a/source/PrintableModel.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -class PrintableModel -{ -public: - virtual void printTo(QPainter &painter) const = 0; - -protected: - static QFont h1Font(); - static QFont h2Font(); - static QFont tableFont(); - - static QPen tablePen(); -}; diff --git a/source/PrintableModel/CMakeLists.txt b/source/PrintableModel/CMakeLists.txt new file mode 100644 index 0000000..0a09f00 --- /dev/null +++ b/source/PrintableModel/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.6) + +project(PrintableModel LANGUAGES CXX) + +find_package(Qt5Core REQUIRED) +find_package(Qt5Widgets REQUIRED) + +add_library(${PROJECT_NAME} + PrintableModel.cpp +) + +set_target_properties(${PROJECT_NAME} + PROPERTIES CXX_STANDARD 14 +) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE + Qt5::Core + Qt5::Widgets +) diff --git a/source/PrintableModel/PrintableModel.cpp b/source/PrintableModel/PrintableModel.cpp new file mode 100644 index 0000000..21d57a2 --- /dev/null +++ b/source/PrintableModel/PrintableModel.cpp @@ -0,0 +1,78 @@ +#include "PrintableModel.h" + +QFont PrintableModel::h1Font() +{ + return QFont("Helvetica", 16); +} + +QFont PrintableModel::h2Font() +{ + return QFont("Helvetica", 12); +} + +QFont PrintableModel::tableFont() +{ + return QFont("Helvetica", 8); +} + +QPen PrintableModel::tablePen() +{ + return QPen(Qt::black, 1, Qt::SolidLine); +} + +void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text) +{ + auto prevPen = painter.pen(); + painter.setPen(tablePen()); + + painter.drawText(cell, Qt::AlignCenter, text); + + painter.drawLine(cell.topLeft(), cell.topRight()); + painter.drawLine(cell.topRight(), cell.bottomRight()); + painter.drawLine(cell.bottomRight(), cell.bottomLeft()); + painter.drawLine(cell.bottomLeft(), cell.topLeft()); + + painter.setPen(prevPen); +} + +void PrintableModel::PrintableModel::drawCheckSquare(QPainter &painter, const QRectF &cell, + bool checked) +{ + drawTextSquare(painter, cell, checked ? "\u2612" : "\u2610"); +} + +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 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) +{ + auto prevBrush = painter.brush(); + auto prevPen = painter.pen(); + + painter.setBrush(QBrush(QColor(224, 224, 224))); + painter.setPen(QPen(Qt::NoPen)); + QPointF points[4] = {cell.topLeft(), cell.topRight(), cell.bottomRight(), cell.bottomLeft()}; + painter.drawPolygon(points, 4); + + painter.setPen(tablePen()); + painter.drawLine(cell.topLeft(), cell.topRight()); + painter.drawLine(cell.topRight(), cell.bottomRight()); + painter.drawLine(cell.bottomRight(), cell.bottomLeft()); + painter.drawLine(cell.bottomLeft(), cell.topLeft()); + + painter.setBrush(prevBrush); + painter.setPen(prevPen); +} diff --git a/source/PrintableModel/PrintableModel.h b/source/PrintableModel/PrintableModel.h new file mode 100644 index 0000000..ab08433 --- /dev/null +++ b/source/PrintableModel/PrintableModel.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include +#include + +class PrintableModel +{ +public: + virtual void printTo(QPainter &painter) const = 0; + +protected: + static QFont h1Font(); + static QFont h2Font(); + static QFont tableFont(); + + static QPen tablePen(); + + static void drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text); + 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); +}; diff --git a/source/SubTests/V2Svk/CMakeLists.txt b/source/SubTests/V2Svk/CMakeLists.txt index caf6c8c..5cd3661 100644 --- a/source/SubTests/V2Svk/CMakeLists.txt +++ b/source/SubTests/V2Svk/CMakeLists.txt @@ -42,6 +42,7 @@ target_link_libraries(${PROJECT_NAME} CheckableItem CheckableTest CheckableTestModel + PrintableModel Qt5::Widgets ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index e621207..ab9a833 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -213,45 +213,6 @@ void V2SvkModel::printTo(QPainter &painter) const auto width = painter.device()->width(); auto height = 1.5 * painter.fontMetrics().lineSpacing(); - auto drawTextSquare = [&](double left, double top, double width, double height, - const QString &text) { - painter.drawText(left, top, width, height, Qt::AlignCenter, text); - painter.drawLine(left, top, left + width, top); - painter.drawLine(left + width, top, left + width, top + height); - painter.drawLine(left + width, top + height, left, top + height); - painter.drawLine(left, top + height, left, top); - }; - - auto drawCheckSquare = [&](double left, double top, double width, double height, bool checked) { - drawTextSquare(left, top, width, height, checked ? "\u2612" : "\u2610"); - }; - - auto drawResultSquare = [&](bool right, unsigned int value, double y) { - double cellWidth = 0.03 * width; - double x = width - cellWidth - (right ? 0 : 0.04 * width); - - drawTextSquare(x, y, cellWidth, height, QString::number(value)); - }; - - auto drawGreySquare = [&](double left, double top, double width, double height) { - auto prevBrush = painter.brush(); - auto prevPen = painter.pen(); - - painter.setBrush(QBrush(QColor(224, 224, 224))); - painter.setPen(QPen(Qt::NoPen)); - QPointF points[4] = {{left, top}, {left + width, top}, {left + width, top + height}, {left, top + height}}; - painter.drawPolygon(points, 4); - - painter.setPen(tablePen()); - painter.drawLine(left, top, left + width, top); - painter.drawLine(left + width, top, left + width, top + height); - painter.drawLine(left + width, top + height, left, top + height); - painter.drawLine(left, top + height, left, top); - - painter.setBrush(prevBrush); - painter.setPen(prevPen); - }; - std::set blockStarters = {0, 3, 5, 7}; std::set v2Tests = {0, 1, 3, 5, 7, 8}; std::set svkTests = {2, 4, 6, 9, 10}; @@ -268,7 +229,7 @@ void V2SvkModel::printTo(QPainter &painter) const if (blockStarters.find(testIndex) != blockStarters.end()) { y += rowHeight; - drawTextSquare(x, y, rowHeaderWidth, 2 * rowHeight, test.name()); + drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, test.name()); x += rowHeaderWidth; std::vector> columnHeaders; @@ -288,7 +249,7 @@ void V2SvkModel::printTo(QPainter &painter) const for (const auto &columnHeader : columnHeaders) { double cellWidth = columnHeader.second * resultCellWidth; - drawTextSquare(x, y, cellWidth, rowHeight, columnHeader.first.c_str()); + drawTextSquare(painter, {x, y, cellWidth, rowHeight}, columnHeader.first.c_str()); x += cellWidth; } x = rowHeaderWidth; @@ -296,7 +257,7 @@ void V2SvkModel::printTo(QPainter &painter) const } else { - drawTextSquare(x, y, rowHeaderWidth, rowHeight, test.name()); + drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, test.name()); x += rowHeaderWidth; } @@ -311,30 +272,30 @@ void V2SvkModel::printTo(QPainter &painter) const { if (emptyItemsStack > 0) { - drawGreySquare(x - emptyItemsStack * resultCellWidth, y, - emptyItemsStack * resultCellWidth, rowHeight); + drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y, + emptyItemsStack * resultCellWidth, rowHeight}); emptyItemsStack = 0; } - drawCheckSquare(x, y, resultCellWidth, rowHeight, item.isChecked()); + drawCheckSquare(painter, {x, y, resultCellWidth, rowHeight}, item.isChecked()); } x += resultCellWidth; } if (emptyItemsStack > 0) { - drawGreySquare(x - emptyItemsStack * resultCellWidth, y, - emptyItemsStack * resultCellWidth, rowHeight); + drawGreySquare(painter, {x - emptyItemsStack * resultCellWidth, y, + emptyItemsStack * resultCellWidth, rowHeight}); emptyItemsStack = 0; } if (v2Tests.find(testIndex) != v2Tests.end()) { - drawResultSquare(false, test.getPoints(), y); + drawResultSquare(painter, y, false, test.getPoints()); } if (svkTests.find(testIndex) != svkTests.end()) { - drawResultSquare(true, test.getPoints(), y); + drawResultSquare(painter, y, true, test.getPoints()); } x = 0; @@ -348,6 +309,6 @@ void V2SvkModel::printTo(QPainter &painter) const painter.drawText(x, y, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, "Rohwertpunkte Total:"); - drawResultSquare(false, getV2Points(), y); - drawResultSquare(true, getSvkPoints(), y); + drawResultSquare(painter, y, false, getV2Points()); + drawResultSquare(painter, y, true, getSvkPoints()); } diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index c7090c3..2b282ee 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -1,6 +1,6 @@ #pragma once -#include "../../PrintableModel.h" +#include "PrintableModel.h" #include "CheckableTestModel.h" #include "V2SvkModel.pb.h" From baf0cb8dbe14b86bb186c72e555117a76ea89700 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 2 Feb 2019 14:44:01 +0100 Subject: [PATCH 05/12] Set equal size for all row headers --- .../CheckableTestModel/CheckableTestModel.cpp | 63 +++++++++++-------- source/SubTests/Plural/PluralModel.cpp | 12 +--- source/SubTests/Plural/PluralModel.h | 3 - source/SubTests/Plural/PluralWidget.cpp | 3 +- source/SubTests/Plural/PluralWidget.ui | 12 +--- 5 files changed, 42 insertions(+), 51 deletions(-) diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 493bd76..9c46e03 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -5,13 +5,13 @@ #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 +20,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 +37,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 +67,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,18 +92,33 @@ 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) + switch (orientation) { - if (section < m_tests.size()) + case Qt::Vertical: { - return m_tests.at(section).name(); + switch (role) + { + case Qt::DisplayRole: + { + if (section < m_tests.size()) + { + return m_tests.at(section).name(); + } + } + case Qt::SizeHintRole: + { + return QSize(200, 0); + } + } + break; } + default: + break; } - return QAbstractTableModel::headerData(section, orientation, role); + return QAbstractTableModel::headerData(section, orientation, role); } void CheckableTestModel::write(QJsonObject &json) const @@ -151,8 +165,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()) { @@ -186,7 +199,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/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index 0ade859..dcd0959 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -5,21 +5,11 @@ PluralModel::PluralModel(QObject *parent) : CheckableTestModel(parent) { - m_tests = {{"", + m_tests = {{"Plural", {"Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/", "Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML"}}}; } -QVariant PluralModel::data(const QModelIndex &index, int role) const -{ - if (role == Qt::SizeHintRole) - { - return QSize(180, 0); - } - - return CheckableTestModel::data(index, role); -} - void PluralModel::read(const ESGRAF48::PluralModel &model) { auto &testItems = m_tests.at(0).items(); diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index cadeae9..ef1381f 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -10,9 +10,6 @@ class PluralModel : public CheckableTestModel public: PluralModel(QObject *parent); - QVariant data( - const QModelIndex &index, int role = Qt::DisplayRole) const override; - void read(const ESGRAF48::PluralModel &model); void write(ESGRAF48::PluralModel &model) const; }; diff --git a/source/SubTests/Plural/PluralWidget.cpp b/source/SubTests/Plural/PluralWidget.cpp index 4776e52..cf78939 100644 --- a/source/SubTests/Plural/PluralWidget.cpp +++ b/source/SubTests/Plural/PluralWidget.cpp @@ -8,6 +8,8 @@ PluralWidget::PluralWidget(QWidget *parent) , ui(new Ui::PluralWidget) { ui->setupUi(this); + + ui->pluralTableView->horizontalHeader()->hide(); } PluralWidget::~PluralWidget() @@ -18,5 +20,4 @@ PluralWidget::~PluralWidget() void PluralWidget::setModel(PluralModel *model) { ui->pluralTableView->setModel(model); - ui->pluralTableView->resizeColumnsToContents(); } diff --git a/source/SubTests/Plural/PluralWidget.ui b/source/SubTests/Plural/PluralWidget.ui index ec1230f..7e78ce4 100644 --- a/source/SubTests/Plural/PluralWidget.ui +++ b/source/SubTests/Plural/PluralWidget.ui @@ -15,17 +15,7 @@ - - - false - - - 120 - - - false - - + From ab862aeaf10fe0caabfd089584c22ec26d596c5c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 3 Feb 2019 19:53:51 +0100 Subject: [PATCH 06/12] 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() From 1695174303adb50c98cd0be6e3ac8926c227d674 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 5 Feb 2019 21:32:13 +0100 Subject: [PATCH 07/12] Added fat lines around summary squares --- source/PrintableModel/PrintableModel.cpp | 24 +++++++++++-- source/PrintableModel/PrintableModel.h | 2 ++ source/SubTests/V2Svk/V2SvkModel.cpp | 8 +++-- source/SubTests/VerbEnd/VerbEndModel.cpp | 43 +++++++++++++++++++----- source/SubTests/VerbEnd/VerbEndModel.h | 5 +++ 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/source/PrintableModel/PrintableModel.cpp b/source/PrintableModel/PrintableModel.cpp index 85b6ed4..97b3fd8 100644 --- a/source/PrintableModel/PrintableModel.cpp +++ b/source/PrintableModel/PrintableModel.cpp @@ -32,6 +32,11 @@ QPen PrintableModel::tablePen() return QPen(Qt::black, 1, Qt::SolidLine); } +QPen PrintableModel::resultPen() +{ + return QPen(Qt::black, 2, Qt::SolidLine); +} + void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text) { auto prevPen = painter.pen(); @@ -47,6 +52,19 @@ void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const painter.setPen(prevPen); } +void PrintableModel::drawNumberSquare(QPainter &painter, double x, double y, int number) +{ + QRectF cell = {x, y, 0.03 * painter.device()->width(), + 1.5 * painter.fontMetrics().lineSpacing()}; + + painter.drawText(cell, Qt::AlignCenter, QString::number(number)); + + painter.drawLine(cell.topLeft(), cell.topRight()); + painter.drawLine(cell.topRight(), cell.bottomRight()); + painter.drawLine(cell.bottomRight(), cell.bottomLeft()); + painter.drawLine(cell.bottomLeft(), cell.topLeft()); +} + void PrintableModel::PrintableModel::drawCheckSquare(QPainter &painter, const QRectF &cell, bool checked) { @@ -138,14 +156,14 @@ void PrintableModel::printTests(QPainter &painter) const 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, + painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter, "Rohwertpunkte Total:"); - drawResultSquare(painter, 0, true, getPoints()); + painter.setPen(resultPen()); + drawNumberSquare(painter, 0.97 * width, 0, getPoints()); painter.translate(0, 3 * height); } diff --git a/source/PrintableModel/PrintableModel.h b/source/PrintableModel/PrintableModel.h index 8dba378..e647585 100644 --- a/source/PrintableModel/PrintableModel.h +++ b/source/PrintableModel/PrintableModel.h @@ -22,8 +22,10 @@ public: static QFont tableFont(); static QPen tablePen(); + static QPen resultPen(); static void drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text); + static void drawNumberSquare(QPainter &painter, double x, double y, int number); 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); diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 5db51d4..5416064 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -116,10 +116,12 @@ void V2SvkModel::printSummary(QPainter &painter, unsigned int v2Points, unsigned auto width = painter.device()->width(); auto height = 1.5 * painter.fontMetrics().lineSpacing(); - painter.drawText(0, 0, 0.85 * width, height, Qt::AlignRight | Qt::AlignVCenter, + painter.drawText(0, 0, 0.91 * width, height, Qt::AlignRight | Qt::AlignVCenter, "Rohwertpunkte Total:"); - PrintableModel::drawResultSquare(painter, 0, false, v2Points); - PrintableModel::drawResultSquare(painter, 0, true, svkPoints); + + painter.setPen(resultPen()); + drawNumberSquare(painter, 0.93 * width, 0, v2Points); + drawNumberSquare(painter, 0.97 * width, 0, svkPoints); painter.translate(0, 3 * height); } diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index 6aa3503..afc21cc 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -1,17 +1,14 @@ #include "VerbEndModel.h" VerbEndModel::VerbEndModel(QObject *parent) - : PrintableModel(parent) + : PrintableModel(parent) { m_title = "Subtest 2: Verbendstellungsregel (VE)"; - 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 @@ -100,4 +97,32 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } - + +unsigned int VerbEndModel::getKausalPoints() const +{ + auto points = [&](unsigned int testId, unsigned int itemId) { + return m_tests.at(testId).items().at(itemId).points(); + }; + + return points(0, 0) + points(0, 1) + points(0, 3) + points(1, 2) + points(1, 5) + points(2, 1); +} + +void VerbEndModel::printSummary(QPainter &painter) const +{ + painter.setFont(tableFont()); + + auto width = painter.device()->width(); + auto height = 1.5 * painter.fontMetrics().lineSpacing(); + + painter.drawText(0, 0, 0.71 * width, height, Qt::AlignRight | Qt::AlignVCenter, + "Rohwertpunkte Kausalsätze:"); + painter.drawText(0, 0, 0.95 * width, height, Qt::AlignRight | Qt::AlignVCenter, + "Rohwertpunkte Total:"); + + drawNumberSquare(painter, 0.73 * width, 0, getKausalPoints()); + + painter.setPen(resultPen()); + drawNumberSquare(painter, 0.97 * width, 0, getKausalPoints()); + + painter.translate(0, 3 * height); +} diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index 8baee48..0211e4f 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -12,4 +12,9 @@ public: void write(ESGRAF48::VerbEndModel &model) const; void read(const ESGRAF48::VerbEndModel &model); + + unsigned int getKausalPoints() const; + +protected: + void printSummary(QPainter &painter) const override; }; From 57fe4256e2905fc4bbd6fdb6717acbb5a3995314 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 5 Feb 2019 22:06:43 +0100 Subject: [PATCH 08/12] Print akkusativ and dativ model --- source/DataModel.cpp | 2 ++ source/SubTests/AkkusativDativ/AkkusativModel.cpp | 7 ++++++- source/SubTests/AkkusativDativ/AkkusativModel.h | 7 +++++-- source/SubTests/AkkusativDativ/CMakeLists.txt | 4 +--- source/SubTests/AkkusativDativ/DativModel.cpp | 2 +- source/SubTests/AkkusativDativ/DativModel.h | 7 +++++-- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 0d33a13..b674978 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -128,6 +128,8 @@ void DataModel::printTo(QPrinter &printer) const printer.newPage(); painter.resetTransform(); + m_akkusativ.printTo(painter); + m_dativ.printTo(painter); m_plural.printTo(painter); painter.end(); diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.cpp b/source/SubTests/AkkusativDativ/AkkusativModel.cpp index 79d2c31..368d297 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.cpp +++ b/source/SubTests/AkkusativDativ/AkkusativModel.cpp @@ -1,7 +1,7 @@ #include "AkkusativModel.h" AkkusativModel::AkkusativModel(QObject *parent) - : CheckableTestModel(parent) + : PrintableModel(parent) { m_tests = {{"Akkusativ Nominalphrase", {"Tiger", "Katze", "Affe", "Gans", "Bär", "Pferd", "Hund", "Elefant"}}, @@ -105,3 +105,8 @@ void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const futterModel->set_zucker(testItems[7].isChecked()); } } + +void AkkusativModel::printHeader(QPainter &painter) const +{ + drawHeader2(painter, "Subtest 4: Akkusativ und Dativ"); +} diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.h b/source/SubTests/AkkusativDativ/AkkusativModel.h index 43a4881..e790ad9 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.h +++ b/source/SubTests/AkkusativDativ/AkkusativModel.h @@ -1,9 +1,9 @@ #pragma once -#include "CheckableTestModel.h" +#include "PrintableModel.h" #include "AkkusativModel.pb.h" -class AkkusativModel : public CheckableTestModel +class AkkusativModel : public PrintableModel { Q_OBJECT @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::AkkusativModel &model); void write(ESGRAF48::AkkusativModel &model) const; + +protected: + void printHeader(QPainter &painter) const override; }; diff --git a/source/SubTests/AkkusativDativ/CMakeLists.txt b/source/SubTests/AkkusativDativ/CMakeLists.txt index a543ee7..da3a956 100644 --- a/source/SubTests/AkkusativDativ/CMakeLists.txt +++ b/source/SubTests/AkkusativDativ/CMakeLists.txt @@ -43,9 +43,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/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index 3741833..9a7cfa5 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -1,7 +1,7 @@ #include "DativModel.h" DativModel::DativModel(QObject *parent) - : CheckableTestModel(parent) + : PrintableModel(parent) { m_tests = {{"Dativ Nominalphrase", {"Affe", "Gans", "Tiger", "Hund", "Elefant", "Pferd", "Bär", "Katze"}}, diff --git a/source/SubTests/AkkusativDativ/DativModel.h b/source/SubTests/AkkusativDativ/DativModel.h index 6a9a323..c6c83f0 100644 --- a/source/SubTests/AkkusativDativ/DativModel.h +++ b/source/SubTests/AkkusativDativ/DativModel.h @@ -1,9 +1,9 @@ #pragma once -#include "CheckableTestModel.h" +#include "PrintableModel.h" #include "DativModel.pb.h" -class DativModel : public CheckableTestModel +class DativModel : public PrintableModel { Q_OBJECT @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::DativModel &model); void write(ESGRAF48::DativModel &model) const; + +protected: + void printHeader(QPainter &) const override {}; }; From 1f5c0de80a6567260eb61805bf7b7e1f6ae0e113 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 5 Feb 2019 22:16:30 +0100 Subject: [PATCH 09/12] Added line-break to test names --- source/PrintableModel/PrintableModel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/PrintableModel/PrintableModel.cpp b/source/PrintableModel/PrintableModel.cpp index 97b3fd8..baabe85 100644 --- a/source/PrintableModel/PrintableModel.cpp +++ b/source/PrintableModel/PrintableModel.cpp @@ -1,5 +1,7 @@ #include "PrintableModel.h" +#include + PrintableModel::PrintableModel(QObject *parent) : CheckableTestModel(parent) { @@ -134,7 +136,10 @@ void PrintableModel::printTests(QPainter &painter) const double y = 0; for (const auto &test : m_tests) { - drawTextSquare(painter, {0, y, headerWidth, 2 * rowHeight}, test.name()); + QString testName = QString::fromStdString( + std::regex_replace(test.name().toStdString(), std::regex("\\s"), "\n")); + + drawTextSquare(painter, {0, y, headerWidth, 2 * rowHeight}, testName); x = headerWidth; for (const auto &item : test.items()) From 189c24cf6180d0526ec13a2f657d50303d0501f6 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 7 Feb 2019 20:03:22 +0100 Subject: [PATCH 10/12] Wrap long row headers --- source/PrintableModel/PrintableModel.cpp | 14 ++++++-- source/PrintableModel/PrintableModel.h | 3 ++ source/SubTests/Plural/PluralModel.cpp | 41 ++++++++++++++++++++++++ source/SubTests/Plural/PluralModel.h | 3 ++ source/SubTests/V2Svk/V2SvkModel.cpp | 17 +++++++--- 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/source/PrintableModel/PrintableModel.cpp b/source/PrintableModel/PrintableModel.cpp index baabe85..3107942 100644 --- a/source/PrintableModel/PrintableModel.cpp +++ b/source/PrintableModel/PrintableModel.cpp @@ -39,6 +39,16 @@ QPen PrintableModel::resultPen() return QPen(Qt::black, 2, Qt::SolidLine); } +double PrintableModel::headerWidthFactor() +{ + return 0.17; +} + +double PrintableModel::cellWidthFactor() +{ + return 0.085; +} + void PrintableModel::drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text) { auto prevPen = painter.pen(); @@ -128,8 +138,8 @@ void PrintableModel::printTests(QPainter &painter) const auto width = painter.device()->width(); auto height = 1.5 * painter.fontMetrics().lineSpacing(); - double headerWidth = 0.2 * width; - double cellWidth = 0.08 * width; + double headerWidth = headerWidthFactor() * width; + double cellWidth = cellWidthFactor() * width; double rowHeight = height; double x = 0; diff --git a/source/PrintableModel/PrintableModel.h b/source/PrintableModel/PrintableModel.h index e647585..eb1daeb 100644 --- a/source/PrintableModel/PrintableModel.h +++ b/source/PrintableModel/PrintableModel.h @@ -24,6 +24,9 @@ public: static QPen tablePen(); static QPen resultPen(); + static double headerWidthFactor(); + static double cellWidthFactor(); + static void drawTextSquare(QPainter &painter, const QRectF &cell, const QString &text); static void drawNumberSquare(QPainter &painter, double x, double y, int number); static void drawCheckSquare(QPainter &painter, const QRectF &cell, bool checked); diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index 5448ed3..b310ae2 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -2,6 +2,8 @@ #include +#include + PluralModel::PluralModel(QObject *parent) : PrintableModel(parent) { @@ -43,3 +45,42 @@ void PluralModel::write(ESGRAF48::PluralModel &model) const model.set_baer(testItems[7].isChecked()); model.set_apfel(testItems[8].isChecked()); } + +void PluralModel::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 cellWidth = cellWidthFactor() * width; + double rowHeight = height; + + double x = 0; + double y = 0; + for (const auto &test : m_tests) + { + drawTextSquare(painter, {0, y, headerWidth, 3 * rowHeight}, test.name()); + x = headerWidth; + + for (const auto &item : test.items()) + { + QString itemText = + QString::fromStdString(std::regex_replace(item.getText(), std::regex("\\s"), "\n")); + + drawTextSquare(painter, {x, y, cellWidth, 2 * rowHeight}, itemText); + drawCheckSquare(painter, {x, y + 2 * rowHeight, cellWidth, rowHeight}, + item.isChecked()); + + x += cellWidth; + } + y += rowHeight; + + drawResultSquare(painter, y, true, test.getPoints()); + y += rowHeight; + } + + painter.translate(0, y + 2 * rowHeight); +} diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index 728258d..f7c3543 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::PluralModel &model); void write(ESGRAF48::PluralModel &model) const; + +protected: + virtual void printTests(QPainter &painter) const; }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 5416064..ff0ab00 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) : PrintableModel(parent) { @@ -21,13 +23,20 @@ void V2SvkModel::printTests(QPainter &painter) const 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 rowHeaderWidth = headerWidthFactor() * width; + double resultCellWidth = (test.size() > 8 ? 0.5 : 1) * cellWidthFactor() * width; double rowHeight = height; + QString testName = test.name(); + if (testName.length() > 20) + { + testName = QString::fromStdString( + std::regex_replace(testName.toStdString(), std::regex("[\\s-]"), "\n")); + } + if (testIndex == 0) { - drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, test.name()); + drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, testName); x += rowHeaderWidth; std::vector> columnHeaders; @@ -55,7 +64,7 @@ void V2SvkModel::printTests(QPainter &painter) const } else { - drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, test.name()); + drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, testName); x += rowHeaderWidth; } From 51271e959529a25985ca634fd378d0ea444ab65a Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 7 Feb 2019 22:36:39 +0100 Subject: [PATCH 11/12] 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); From 468006a416dde420360fac01e296378efba3a91d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 7 Feb 2019 22:40:18 +0100 Subject: [PATCH 12/12] Bumped version to 0.4 --- source/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 063ff65..bd5bc26 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.6) -set(BUILD_VERSION_MAJOR_MINOR 0.3) +set(BUILD_VERSION_MAJOR_MINOR 0.4) if ($ENV{BUILD_NUMBER}) set(BUILD_VERSION_PATCH $ENV{BUILD_NUMBER})