ESGRAF48/source/SubTests/V2Svk/V2SvkModel.cpp

138 lines
3.3 KiB
C++
Raw Normal View History

2019-02-03 18:53:51 +00:00
#include "V2SvkModel.h"
2019-02-07 19:03:22 +00:00
#include <regex>
2019-02-03 18:53:51 +00:00
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)
{
2019-02-07 19:03:22 +00:00
double rowHeaderWidth = headerWidthFactor() * width;
double resultCellWidth = (test.size() > 8 ? 0.5 : 1) * cellWidthFactor() * width;
2019-02-03 18:53:51 +00:00
double rowHeight = height;
2019-02-07 19:03:22 +00:00
QString testName = test.name();
if (testName.length() > 20)
{
testName = QString::fromStdString(
std::regex_replace(testName.toStdString(), std::regex("[\\s-]"), "\n"));
}
2019-02-03 18:53:51 +00:00
if (testIndex == 0)
{
2019-02-07 19:03:22 +00:00
drawTextSquare(painter, {x, y, rowHeaderWidth, 2 * rowHeight}, testName);
2019-02-03 18:53:51 +00:00
x += rowHeaderWidth;
std::vector<std::pair<std::string, unsigned int>> 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
{
2019-02-07 19:03:22 +00:00
drawTextSquare(painter, {x, y, rowHeaderWidth, rowHeight}, testName);
2019-02-03 18:53:51 +00:00
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();
2019-02-05 20:32:13 +00:00
painter.drawText(0, 0, 0.91 * width, height, Qt::AlignRight | Qt::AlignVCenter,
2019-02-03 18:53:51 +00:00
"Rohwertpunkte Total:");
2019-02-05 20:32:13 +00:00
painter.setPen(resultPen());
drawNumberSquare(painter, 0.93 * width, 0, v2Points);
drawNumberSquare(painter, 0.97 * width, 0, svkPoints);
2019-02-03 18:53:51 +00:00
painter.translate(0, 3 * height);
}