Implemented printing for late skills tests

This commit is contained in:
mandlm 2018-12-10 22:29:49 +01:00
parent f6c2da5edc
commit 98196e05d6
11 changed files with 100 additions and 11 deletions

View File

@ -172,7 +172,7 @@ void CheckableTestModel::printTableTo(QTextCursor &cursor) const
currentColumn++;
}
setCellText(*table, currentRow + 1, 12, QString::number(test.getPoints()));
setCellNumber(*table, currentRow + 1, 12, test.getPoints());
currentRow += 2;
}
@ -192,7 +192,7 @@ void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const
QTextTable *table = cursor.insertTable(1, 4, tableFormat);
setCellText(*table, 0, 1, "Rohwertpunkte Total:");
setCellText(*table, 0, 3, QString::number(getPoints()));
setCellNumber(*table, 0, 3, getPoints());
}
void CheckableTestModel::setCellText(QTextTable &table, int row, int column, const QString &text)

View File

@ -41,6 +41,12 @@ protected:
static void setCellText(QTextTable &table, int row, int column, const QString &text);
static void setCellChecked(QTextTable &table, int row, int column, bool check);
template <typename NumberType>
static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number)
{
setCellText(table, row, column, QString::number(number));
}
private:
CheckableItems &getItems(const QModelIndex &index);
const CheckableItems &getItems(const QModelIndex &index) const;

View File

@ -75,9 +75,10 @@ void DataModel::printTo(QTextCursor &cursor) const
m_genus.printTo(cursor);
m_akkusativ.printTo(cursor);
m_dativ.printTo(cursor);
m_plural.printTo(cursor);
//m_genitiv.printTo(cursor);
//m_passiv.printTo(cursor);
m_passiv.printTo(cursor);
m_genitiv.printTo(cursor);
m_results.printTo(cursor);
}

View File

@ -22,6 +22,7 @@ protobuf_generate_cpp(LateSkills_PROTO_SRCS LateSkills_PROTO_HDRS
add_library(${PROJECT_NAME}
LateSkillsWidget.cpp
LateSkillsModel.cpp
PassivModel.cpp
GenitivModel.cpp
${UI_HEADERS}

View File

@ -1,7 +1,7 @@
#include "GenitivModel.h"
GenitivModel::GenitivModel(QObject *parent)
: CheckableTestModel(parent)
: LateSkillsModel(parent)
{
m_tests = {
{"Genitiv Präpositionen",

View File

@ -1,9 +1,9 @@
#pragma once
#include "CheckableTestModel.h"
#include "LateSkillsModel.h"
#include "LateSkillsGenitivModel.pb.h"
class GenitivModel : public CheckableTestModel
class GenitivModel : public LateSkillsModel
{
Q_OBJECT

View File

@ -0,0 +1,67 @@
#include "LateSkillsModel.h"
#include <QTextTable>
#include <regex>
LateSkillsModel::LateSkillsModel(QObject *parent)
: CheckableTestModel(parent)
{
}
void LateSkillsModel::printTableTo(QTextCursor &cursor) const
{
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
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;
}
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "CheckableTestModel.h"
class LateSkillsModel : public CheckableTestModel
{
Q_OBJECT
public:
LateSkillsModel(QObject *parent);
protected:
void printTableTo(QTextCursor &cursor) const override;
};

View File

@ -1,7 +1,7 @@
#include "PassivModel.h"
PassivModel::PassivModel(QObject *parent)
: CheckableTestModel(parent)
: LateSkillsModel(parent)
{
m_tests = {{"Passiv",
{"Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", "Bälle (2)",

View File

@ -1,9 +1,9 @@
#pragma once
#include "CheckableTestModel.h"
#include "LateSkillsModel.h"
#include "LateSkillsPassivModel.pb.h"
class PassivModel : public CheckableTestModel
class PassivModel : public LateSkillsModel
{
Q_OBJECT

View File

@ -60,7 +60,7 @@ std::string PluralModel::getName() const
{
return "Subtest 5: Plural";
}
void PluralModel::printTableTo(QTextCursor &cursor) const
{
QTextTableFormat tableFormat;