Some prototypical table output

feature/qt-as-conan-package
mandlm 2019-01-12 21:42:52 +01:00
parent 59c409c872
commit 463dc275d0
6 changed files with 121 additions and 1 deletions

View File

@ -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()

View File

@ -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);
}

View File

@ -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);
}

View File

@ -9,5 +9,8 @@ public:
protected:
static QFont h1Font();
static QFont h2Font();
static QFont tableFont();
static QPen tablePen();
};

View File

@ -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);
}

View File

@ -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;
};