Print most of the table structures
This commit is contained in:
parent
f895ec0c1c
commit
ab862aeaf1
31 changed files with 411 additions and 203 deletions
|
@ -19,6 +19,8 @@ target_include_directories(${PROJECT_NAME}
|
|||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
CheckableTestModel
|
||||
PRIVATE
|
||||
Qt5::Core
|
||||
Qt5::Widgets
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "CheckableTestModel.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QFont>
|
||||
#include <QPen>
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue