ESGRAF48/source/SubTests/LateSkills/LateSkillsModel.cpp

65 lines
1.8 KiB
C++
Raw Normal View History

2019-02-07 21:36:39 +00:00
#include "LateSkillsModel.h"
#include <regex>
2019-10-05 14:14:45 +00:00
LateSkillsModel::LateSkillsModel(QObject* parent)
2019-02-07 21:36:39 +00:00
: PrintableModel(parent)
{
}
2019-10-05 14:14:45 +00:00
void LateSkillsModel::printTests(QPainter& painter) const
2019-02-07 21:36:39 +00:00
{
2019-10-05 14:14:45 +00:00
painter.setFont(tableFont());
painter.setPen(tablePen());
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
auto width = painter.device()->width();
auto height = 1.5 * painter.fontMetrics().lineSpacing();
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
double headerWidth = headerWidthFactor() * width;
double cellHeaderWidth = cellWidthFactor() * width;
double cellWidth = 0.5 * cellHeaderWidth;
double rowHeight = height;
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
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"));
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
drawTextSquare(painter, {0, y, headerWidth, 3 * rowHeight}, testName);
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
const auto& items = test.items();
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
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);
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
drawTextSquare(painter, {x, y, cellHeaderWidth, rowHeight}, itemText);
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
x += cellHeaderWidth;
}
y += rowHeight;
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
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());
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
x += cellWidth;
}
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
if (m_tests.size() > 1)
{
drawResultSquare(painter, y + rowHeight, true, test.getPoints());
}
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
y += 2 * rowHeight;
}
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
painter.translate(0, y + rowHeight);
2019-02-07 21:36:39 +00:00
}