Very basic subtest 2 print output

This commit is contained in:
Michael Mandl 2018-12-02 18:26:22 +01:00
parent bcd0b17caa
commit b06e717575
16 changed files with 272 additions and 130 deletions

View file

@ -34,24 +34,3 @@ unsigned int CheckableItem::points() const
{
return m_checked ? m_value : 0;
}
void CheckableItem::write(QJsonObject &json) const
{
json["text"] = m_text.c_str();
json["checked"] = m_checked;
}
void CheckableItem::read(const QJsonObject &json)
{
const auto &text = json["text"];
if (text.isString())
{
m_text = text.toString().toStdString();
}
const auto &checked = json["checked"];
if (checked.isBool())
{
m_checked = checked.toBool();
}
}

View file

@ -24,7 +24,4 @@ public:
void setValue(unsigned int value);
unsigned int points() const;
void write(QJsonObject &json) const;
void read(const QJsonObject &json);
};

View file

@ -2,6 +2,8 @@
#include <QJsonArray>
#include <numeric>
CheckableItems::CheckableItems(std::initializer_list<std::string> itemNames)
{
for (const auto &itemName : itemNames)
@ -10,27 +12,9 @@ CheckableItems::CheckableItems(std::initializer_list<std::string> itemNames)
}
}
void CheckableItems::write(QJsonArray &json) const
unsigned int CheckableItems::getPoints() const
{
for (const auto &item : *this)
{
QJsonObject itemObject;
item.write(itemObject);
json.append(itemObject);
}
}
void CheckableItems::read(const QJsonArray &json)
{
clear();
for (const auto &itemObject : json)
{
if (itemObject.isObject())
{
CheckableItem item;
item.read(itemObject.toObject());
emplace_back(item);
}
}
return std::accumulate(begin(), end(), 0, [](int base, const CheckableItem &item) {
return base + item.points();
});
}

View file

@ -10,6 +10,5 @@ class CheckableItems : public std::vector<CheckableItem>
public:
CheckableItems(std::initializer_list<std::string> itemNames);
void write(QJsonArray &json) const;
void read(const QJsonArray &json);
unsigned int getPoints() const;
};

View file

@ -1,5 +1,7 @@
#include "CheckableTest.h"
#include <numeric>
CheckableTest::CheckableTest(
const char *name, std::initializer_list<std::string> items)
: m_name(name)
@ -26,3 +28,8 @@ CheckableItems &CheckableTest::items()
{
return m_items;
}
unsigned int CheckableTest::getPoints() const
{
return m_items.getPoints();
}

View file

@ -17,6 +17,8 @@ public:
const QString &name() const;
const CheckableItems &items() const;
CheckableItems &items();
unsigned int getPoints() const;
};
using CheckableTests = std::vector<CheckableTest>;

View file

@ -107,30 +107,6 @@ QVariant CheckableTestModel::headerData(
return QAbstractTableModel::headerData(section, orientation, role);
}
void CheckableTestModel::write(QJsonObject &json) const
{
for (const auto &test : m_tests)
{
QJsonArray testData;
test.items().write(testData);
json[test.name()] = testData;
}
}
void CheckableTestModel::read(const QJsonObject &json)
{
for (auto &test : m_tests)
{
auto testData = json[test.name()];
if (testData.isArray())
{
test.items().read(testData.toArray());
}
}
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
bool CheckableTestModel::isValidIndex(const QModelIndex &index) const
{
if (index.row() < m_tests.size())
@ -190,10 +166,7 @@ unsigned int CheckableTestModel::getPoints() const
for (const auto &test : m_tests)
{
for (const auto &item : test.items())
{
points += item.points();
}
points += test.getPoints();
}
return points;

View file

@ -25,9 +25,6 @@ public:
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
void write(QJsonObject &json) const;
void read(const QJsonObject &json);
unsigned int getPoints() const;
protected:

View file

@ -64,12 +64,21 @@ void DataModel::printTo(QTextCursor &cursor) const
{
QTextCharFormat titleFormat;
titleFormat.setFontPointSize(18);
cursor.insertText("ESGRAF 4-8 Auswertungsbogen", titleFormat);
cursor.insertText("\n", titleFormat);
m_metaData.printTo(cursor);
cursor.insertText("\n", titleFormat);
m_v2Svk.printTo(cursor);
cursor.insertText("\n", titleFormat);
m_verbEnd.printTo(cursor);
cursor.insertText("\n", titleFormat);
//m_results.printTo(cursor);
//cursor.insertText("\n", titleFormat);
}
void DataModel::pluralModelChanged()

View file

@ -12,6 +12,7 @@ qt5_wrap_ui(GENUS_UI
add_library(${PROJECT_NAME}
ResultWidget.cpp
TestResult.cpp
ResultModel.cpp
PRMap.cpp
${GENUS_UI}

View file

@ -210,3 +210,23 @@ void ResultModel::setGenitivResult(unsigned int points)
emit dataChanged(index(0, 7), index(4, 7));
}
}
void ResultModel::printTo(QTextCursor &cursor) const
{
cursor.insertBlock();
QTextCharFormat headerFormat;
headerFormat.setFontPointSize(12);
cursor.insertText(
"Prozentränge (PR)",
headerFormat);
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
QTextTable *table = cursor.insertTable(1, 1, tableFormat);
cursor.movePosition(QTextCursor::NextBlock);
}

View file

@ -1,46 +1,11 @@
#pragma once
#include "Age.h"
#include "TestResult.h"
#include <QAbstractTableModel>
#include <QTextCursor>
class TestResult
{
private:
QString m_name;
size_t m_points = 0;
size_t m_pr = 0;
public:
TestResult(const char *name)
: m_name(name)
{
}
void setPoints(const size_t &points)
{
m_points = points;
}
void setPR(const unsigned int &pr)
{
m_pr = pr;
}
const QString &name() const
{
return m_name;
}
const size_t points() const
{
return m_points;
}
const size_t pr() const
{
return m_pr;
}
};
class ResultModel : public QAbstractTableModel
{
@ -56,8 +21,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(
const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
@ -72,4 +36,6 @@ public:
void setSvkResult(unsigned int points);
void setPassivResult(unsigned int points);
void setGenitivResult(unsigned int points);
void printTo(QTextCursor &cursor) const;
};

View file

@ -0,0 +1,31 @@
#include "TestResult.h"
TestResult::TestResult(const char *name)
: m_name(name)
{
}
void TestResult::setPoints(const size_t &points)
{
m_points = points;
}
void TestResult::setPR(const unsigned int &pr)
{
m_pr = pr;
}
QString TestResult::name() const
{
return m_name;
}
size_t TestResult::points() const
{
return m_points;
}
size_t TestResult::pr() const
{
return m_pr;
}

View file

@ -0,0 +1,22 @@
#pragma once
#include <QString>
class TestResult
{
private:
QString m_name;
size_t m_points = 0;
size_t m_pr = 0;
public:
TestResult(const char *name);
void setPoints(const size_t &points);
void setPR(const unsigned int &pr);
QString name() const;
size_t points() const;
size_t pr() const;
};

View file

@ -1,15 +1,14 @@
#include "VerbEndModel.h"
#include <QTextTable>
VerbEndModel::VerbEndModel(QObject *parent)
: CheckableTestModel(parent)
{
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" } } };
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"}}};
}
void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const
@ -98,3 +97,155 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model)
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void VerbEndModel::printTo(QTextCursor &cursor) const
{
cursor.insertBlock();
QTextCharFormat headerFormat;
headerFormat.setFontPointSize(12);
cursor.insertText("Subtest 2: Verbendstellungsregel (VE)", headerFormat);
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 15),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 2),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 5)});
QTextTable *table = cursor.insertTable(6, 13, tableFormat);
table->mergeCells(0, 0, 2, 1);
table->mergeCells(2, 0, 2, 1);
table->mergeCells(4, 0, 2, 1);
const char *emptyBox = "\u2610";
//const char *checkBox = "\u2611";
const char *checkBox = "x";
cursor.insertText("Telefonat");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextRow);
const auto &telTestItems = m_tests.at(0).items();
cursor.insertText(telTestItems[0].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[1].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[2].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[3].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[4].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[5].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[6].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(QString::number(m_tests.at(0).getPoints()));
cursor.movePosition(QTextCursor::NextRow);
cursor.insertText("Zaubertrick");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextRow);
const auto &trickTestItems = m_tests.at(1).items();
cursor.insertText(trickTestItems[0].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[1].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[2].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[3].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[4].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[5].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[6].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(QString::number(m_tests.at(1).getPoints()));
cursor.movePosition(QTextCursor::NextRow);
cursor.insertText("Zauberregel");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextRow);
const auto &regelTestItems = m_tests.at(2).items();
cursor.insertText(regelTestItems[0].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[1].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[2].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[3].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[4].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[5].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(QString::number(m_tests.at(2).getPoints()));
cursor.movePosition(QTextCursor::NextBlock);
}

View file

@ -3,6 +3,8 @@
#include "CheckableTestModel.h"
#include "VerbEndModel.pb.h"
#include <QTextCursor>
class VerbEndModel : public CheckableTestModel
{
Q_OBJECT
@ -12,4 +14,6 @@ public:
void write(ESGRAF48::VerbEndModel &model) const;
void read(const ESGRAF48::VerbEndModel &model);
void printTo(QTextCursor &cursor) const;
};