This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
ESGRAF48/source/SubTests/LateSkills/LateSkillsModel.cpp

66 lines
2.5 KiB
C++
Raw Normal View History

#include "LateSkillsModel.h"
#include <QTextTable>
#include <regex>
LateSkillsModel::LateSkillsModel(QObject *parent)
: CheckableTestModel(parent)
{
}
void LateSkillsModel::printTableTo(QTextCursor &cursor) const
{
2018-12-15 15:12:20 +00:00
QTextTableFormat tableFormat = defaultTableFormat();
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 26),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3)});
QTextTable *table = cursor.insertTable(m_tests.size() * 3, 14, tableFormat);
int currentRow = 0;
for (const auto &test : m_tests)
{
table->mergeCells(currentRow, 0, 3, 1);
int currentColumn = 0;
setCellText(*table, currentRow, currentColumn, test.name());
currentColumn++;
for (auto it = std::begin(test.items()); it != std::end(test.items()); std::advance(it, 2))
{
const auto &item = *it;
const auto &nextItem = *std::next(it);
table->mergeCells(currentRow, currentColumn, 1, 2);
auto itemName = std::regex_replace(item.getText(), std::regex(R"((\S+).*)"), "$1");
setCellText(*table, currentRow, currentColumn, itemName.c_str());
setCellText(*table, currentRow + 1, currentColumn, "1");
setCellText(*table, currentRow + 1, currentColumn + 1, "2");
setCellChecked(*table, currentRow + 2, currentColumn, item.isChecked());
setCellChecked(*table, currentRow + 2, currentColumn + 1, nextItem.isChecked());
currentColumn += 2;
}
setCellNumber(*table, currentRow + 2, 13, test.getPoints());
currentRow += 3;
}
}