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/VerbEnd/VerbEndModel.cpp

152 lines
5.1 KiB
C++
Raw Permalink Normal View History

2018-05-23 16:43:57 +00:00
#include "VerbEndModel.h"
2018-12-02 17:26:22 +00:00
#include <QTextTable>
#include <QDebug>
2018-12-02 17:26:22 +00:00
2018-05-23 16:43:57 +00:00
VerbEndModel::VerbEndModel(QObject *parent)
2018-12-02 17:26:22 +00:00
: CheckableTestModel(parent)
{
2018-12-02 17:26:22 +00:00
m_tests = {
{"Telefonat", {"Kausal", "Kausal", "Relativ", "Kausal", "Final", "Temporal", "Temporal"}},
{"Zaubertrick", {"Relativ", "Final", "Kausal", "Final", "Temporal", "Kausal", "Temporal"}},
{"Zauberregel", {"Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ"}}};
connect(this, &VerbEndModel::dataChanged, this, &VerbEndModel::modelChanged);
2018-05-23 16:43:57 +00:00
}
void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const
{
auto *telefonatModel = model.mutable_telefonat();
if (telefonatModel != nullptr)
{
const auto &testItems = m_tests.at(0).items();
telefonatModel->set_kausal1(testItems[0].isChecked());
telefonatModel->set_kausal2(testItems[1].isChecked());
telefonatModel->set_relativ(testItems[2].isChecked());
telefonatModel->set_kausal3(testItems[3].isChecked());
telefonatModel->set_final(testItems[4].isChecked());
telefonatModel->set_temporal1(testItems[5].isChecked());
telefonatModel->set_temporal2(testItems[6].isChecked());
}
auto *zaubertrickModel = model.mutable_zaubertrick();
if (zaubertrickModel != nullptr)
{
const auto &testItems = m_tests.at(1).items();
zaubertrickModel->set_relativ(testItems[0].isChecked());
zaubertrickModel->set_final1(testItems[1].isChecked());
zaubertrickModel->set_kausal1(testItems[2].isChecked());
zaubertrickModel->set_final2(testItems[3].isChecked());
zaubertrickModel->set_temporal1(testItems[4].isChecked());
zaubertrickModel->set_kausal2(testItems[5].isChecked());
zaubertrickModel->set_temporal2(testItems[6].isChecked());
}
auto *zauberregelModel = model.mutable_zauberregel();
if (zauberregelModel != nullptr)
{
const auto &testItems = m_tests.at(2).items();
zauberregelModel->set_temporal1(testItems[0].isChecked());
zauberregelModel->set_kausal(testItems[1].isChecked());
zauberregelModel->set_final(testItems[2].isChecked());
zauberregelModel->set_relativ1(testItems[3].isChecked());
zauberregelModel->set_temporal2(testItems[4].isChecked());
zauberregelModel->set_relativ2(testItems[5].isChecked());
}
}
void VerbEndModel::read(const ESGRAF48::VerbEndModel &model)
{
const auto &telefonatModel = model.telefonat();
{
auto &testItems = m_tests.at(0).items();
testItems[0].setState(telefonatModel.kausal1());
testItems[1].setState(telefonatModel.kausal2());
testItems[2].setState(telefonatModel.relativ());
testItems[3].setState(telefonatModel.kausal3());
testItems[4].setState(telefonatModel.final());
testItems[5].setState(telefonatModel.temporal1());
testItems[6].setState(telefonatModel.temporal2());
}
const auto &zaubertrickModel = model.zaubertrick();
{
auto &testItems = m_tests.at(1).items();
testItems[0].setState(zaubertrickModel.relativ());
testItems[1].setState(zaubertrickModel.final1());
testItems[2].setState(zaubertrickModel.kausal1());
testItems[3].setState(zaubertrickModel.final2());
testItems[4].setState(zaubertrickModel.temporal1());
testItems[5].setState(zaubertrickModel.kausal2());
testItems[6].setState(zaubertrickModel.temporal2());
}
const auto &zauberregelModel = model.zauberregel();
{
auto &testItems = m_tests.at(2).items();
testItems[0].setState(zauberregelModel.temporal1());
testItems[1].setState(zauberregelModel.kausal());
testItems[2].setState(zauberregelModel.final());
testItems[3].setState(zauberregelModel.relativ1());
testItems[4].setState(zauberregelModel.temporal2());
testItems[5].setState(zauberregelModel.relativ2());
}
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
2018-12-02 17:26:22 +00:00
unsigned int VerbEndModel::getCausalPoints() const
{
unsigned int points = 0;
for (const auto &test : m_tests)
{
for (const auto &item : test.items())
{
if (item.getText() == "Kausal")
{
points += item.points();
}
}
}
return points;
}
void VerbEndModel::modelChanged()
{
emit causalPointsChanged(getCausalPoints());
}
2018-12-08 20:02:35 +00:00
std::string VerbEndModel::getName() const
2018-12-02 17:26:22 +00:00
{
2018-12-08 20:02:35 +00:00
return "Subtest 2: Verbendstellungsregel (VE)";
};
2018-12-12 20:40:26 +00:00
void VerbEndModel::printSummaryTo(QTextCursor &cursor) const
{
2018-12-15 15:12:20 +00:00
QTextTableFormat tableFormat = defaultTableFormat();
2018-12-12 20:40:26 +00:00
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 46),
QTextLength(QTextLength::PercentageLength, 25),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 20),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3)});
QTextTable *table = cursor.insertTable(1, 8, tableFormat);
setCellText(*table, 0, 1, "Rohwertpunkte Kausalsätze:");
setCellNumber(*table, 0, 3, getCausalPoints());
setCellText(*table, 0, 5, "Rohwertpunkte Total:");
setCellNumber(*table, 0, 7, getPoints());
}