From 463dc275d05b6f78e9b9d819ab735a2fdd30c0a1 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 12 Jan 2019 21:42:52 +0100 Subject: [PATCH] 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; };