diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 0a0f40f..147bf10 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -36,6 +36,7 @@ protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS add_executable(${PROJECT_NAME} WIN32 ESGRAF48.cpp DataModel.cpp + PrintableModel.cpp mainwindow.cpp ${LOGO_TEST_UI} ${LOGO_TEST_QRC} diff --git a/source/CheckableItem/CheckableItem.cpp b/source/CheckableItem/CheckableItem.cpp index 6d6a16a..faed665 100644 --- a/source/CheckableItem/CheckableItem.cpp +++ b/source/CheckableItem/CheckableItem.cpp @@ -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(); - } -} diff --git a/source/CheckableItem/CheckableItem.h b/source/CheckableItem/CheckableItem.h index a37086e..89feffe 100644 --- a/source/CheckableItem/CheckableItem.h +++ b/source/CheckableItem/CheckableItem.h @@ -24,7 +24,4 @@ public: void setValue(unsigned int value); unsigned int points() const; - - void write(QJsonObject &json) const; - void read(const QJsonObject &json); }; diff --git a/source/CheckableItem/CheckableItems.cpp b/source/CheckableItem/CheckableItems.cpp index 30532f3..f9b59f3 100644 --- a/source/CheckableItem/CheckableItems.cpp +++ b/source/CheckableItem/CheckableItems.cpp @@ -2,6 +2,8 @@ #include +#include + CheckableItems::CheckableItems(std::initializer_list itemNames) { for (const auto &itemName : itemNames) @@ -10,27 +12,9 @@ CheckableItems::CheckableItems(std::initializer_list 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(); + }); } diff --git a/source/CheckableItem/CheckableItems.h b/source/CheckableItem/CheckableItems.h index 164f829..b147e27 100644 --- a/source/CheckableItem/CheckableItems.h +++ b/source/CheckableItem/CheckableItems.h @@ -10,6 +10,5 @@ class CheckableItems : public std::vector public: CheckableItems(std::initializer_list itemNames); - void write(QJsonArray &json) const; - void read(const QJsonArray &json); + unsigned int getPoints() const; }; diff --git a/source/CheckableTest/CheckableTest.cpp b/source/CheckableTest/CheckableTest.cpp index 0d0cbf5..fabf0c3 100644 --- a/source/CheckableTest/CheckableTest.cpp +++ b/source/CheckableTest/CheckableTest.cpp @@ -1,5 +1,7 @@ #include "CheckableTest.h" +#include + CheckableTest::CheckableTest( const char *name, std::initializer_list items) : m_name(name) @@ -26,3 +28,8 @@ CheckableItems &CheckableTest::items() { return m_items; } + +unsigned int CheckableTest::getPoints() const +{ + return m_items.getPoints(); +} diff --git a/source/CheckableTest/CheckableTest.h b/source/CheckableTest/CheckableTest.h index 32f6da0..f4a0c20 100644 --- a/source/CheckableTest/CheckableTest.h +++ b/source/CheckableTest/CheckableTest.h @@ -17,6 +17,8 @@ public: const QString &name() const; const CheckableItems &items() const; CheckableItems &items(); + + unsigned int getPoints() const; }; using CheckableTests = std::vector; diff --git a/source/CheckableTestModel/CMakeLists.txt b/source/CheckableTestModel/CMakeLists.txt index 2ce7c3b..a9400cf 100644 --- a/source/CheckableTestModel/CMakeLists.txt +++ b/source/CheckableTestModel/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(CheckableTestModel LANGUAGES CXX) find_package(Qt5Core REQUIRED) +find_package(Qt5Gui REQUIRED) add_library(${PROJECT_NAME} CheckableTestModel.cpp @@ -22,4 +23,5 @@ target_link_libraries(${PROJECT_NAME} CheckableItem CheckableTest Qt5::Core + Qt5::Gui ) diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 493bd76..504ab98 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -2,16 +2,17 @@ #include #include +#include #include CheckableTestModel::CheckableTestModel(QObject *parent) - : QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } int CheckableTestModel::rowCount(const QModelIndex &) const { - return static_cast(m_tests.size()); + return static_cast(m_tests.size()); } int CheckableTestModel::columnCount(const QModelIndex &) const @@ -20,7 +21,7 @@ int CheckableTestModel::columnCount(const QModelIndex &) const for (const auto &test : m_tests) { - columnCount = std::max(columnCount, static_cast(test.size())); + columnCount = std::max(columnCount, static_cast(test.size())); } return columnCount; @@ -37,17 +38,17 @@ QVariant CheckableTestModel::data(const QModelIndex &index, int role) const { auto &item = getItem(index); - switch (role) - { - case Qt::DisplayRole: - { - return item.getText().c_str(); - } - case Qt::CheckStateRole: - { - return item.isChecked() ? Qt::Checked : Qt::Unchecked; - } - } + switch (role) + { + case Qt::DisplayRole: + { + return item.getText().c_str(); + } + case Qt::CheckStateRole: + { + return item.isChecked() ? Qt::Checked : Qt::Unchecked; + } + } } catch (std::runtime_error &e) { @@ -67,8 +68,7 @@ Qt::ItemFlags CheckableTestModel::flags(const QModelIndex &index) const return Qt::NoItemFlags; } -bool CheckableTestModel::setData( - const QModelIndex &index, const QVariant &value, int role) +bool CheckableTestModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!isValidIndex(index)) { @@ -93,8 +93,7 @@ bool CheckableTestModel::setData( return false; } -QVariant CheckableTestModel::headerData( - int section, Qt::Orientation orientation, int role) const +QVariant CheckableTestModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole && orientation == Qt::Vertical) { @@ -104,31 +103,7 @@ 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)); + return QAbstractTableModel::headerData(section, orientation, role); } bool CheckableTestModel::isValidIndex(const QModelIndex &index) const @@ -141,6 +116,81 @@ bool CheckableTestModel::isValidIndex(const QModelIndex &index) const return false; } +void CheckableTestModel::printTo(QTextCursor &cursor) const +{ + QTextCharFormat headerFormat; + headerFormat.setFontPointSize(10); + cursor.insertBlock(); + cursor.insertText("\n"); + cursor.insertText(getName().c_str(), headerFormat); + + printTableTo(cursor); + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + printSummaryTo(cursor); + cursor.movePosition(QTextCursor::End); +} + +void CheckableTestModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat = defaultTableFormat(); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), + 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, 1), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(m_tests.size() * 2, 13, tableFormat); + + int currentRow = 0; + for (const auto &test : m_tests) + { + table->mergeCells(currentRow, 0, 2, 1); + + int currentColumn = 0; + + setCellText(*table, currentRow, currentColumn, test.name()); + currentColumn++; + + for (const auto &item : test.items()) + { + setCellText(*table, currentRow, currentColumn, item.getText().c_str()); + setCellChecked(*table, currentRow + 1, currentColumn, item.isChecked()); + + currentColumn++; + } + + setCellNumber(*table, currentRow + 1, 12, test.getPoints()); + + currentRow += 2; + } +} + +void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat = defaultTableFormat(); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 76), + QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(1, 4, tableFormat); + + setCellText(*table, 0, 1, "Rohwertpunkte Total:"); + setCellNumber(*table, 0, 3, getPoints()); +} + CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) { if (index.row() < m_tests.size()) @@ -151,8 +201,7 @@ CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) throw std::runtime_error("invalid index"); } -const CheckableItems &CheckableTestModel::getItems( - const QModelIndex &index) const +const CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) const { if (index.row() < m_tests.size()) { @@ -186,15 +235,7 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const unsigned int CheckableTestModel::getPoints() const { - unsigned int points = 0; - - for (const auto &test : m_tests) - { - for (const auto &item : test.items()) - { - points += item.points(); - } - } - - return points; + return std::accumulate( + std::begin(m_tests), std::end(m_tests), 0, + [](int base, const CheckableTest &test) { return base + test.getPoints(); }); } diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 7b4ed9d..d30ad6b 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -1,9 +1,12 @@ #pragma once +#include "../PrintableModel.h" #include "CheckableTest.h" -#include -class CheckableTestModel : public QAbstractTableModel +#include +#include + +class CheckableTestModel : public QAbstractTableModel, protected PrintableModel { Q_OBJECT @@ -25,14 +28,18 @@ 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; + void printTo(QTextCursor &cursor) const override; + protected: virtual bool isValidIndex(const QModelIndex &index) const; + virtual std::string getName() const = 0; + + virtual void printTableTo(QTextCursor &cursor) const; + virtual void printSummaryTo(QTextCursor &cursor) const; + private: CheckableItems &getItems(const QModelIndex &index); const CheckableItems &getItems(const QModelIndex &index) const; diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 216eb8c..5ac55f8 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -60,27 +60,27 @@ void DataModel::read(std::istream &inStream) m_passiv.read(dataModel.lateskillspassiv()); } -std::string DataModel::toHtml() const +void DataModel::printTo(QTextCursor &cursor) const { - std::stringstream out; + QTextCharFormat titleFormat; + titleFormat.setFontPointSize(14); - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "

ESGRAF 4-8 Auswertungsbogen

" << std::endl; - out << "

" << std::endl; - out << m_metaData.toHtml(); - out << "

" << std::endl; - out << "" << std::endl; - out << "" << std::endl; + cursor.insertText("ESGRAF 4-8 Auswertungsbogen", titleFormat); + cursor.insertText("\n", titleFormat); - return out.str(); + m_metaData.printTo(cursor); + + m_v2Svk.printTo(cursor); + m_verbEnd.printTo(cursor); + m_genus.printTo(cursor); + m_akkusativ.printTo(cursor); + m_dativ.printTo(cursor); + + m_plural.printTo(cursor); + m_passiv.printTo(cursor); + m_genitiv.printTo(cursor); + + m_results.printTo(cursor); } void DataModel::pluralModelChanged() diff --git a/source/DataModel.h b/source/DataModel.h index 71a9352..ce3a92a 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -13,6 +13,7 @@ #include "ResultModel.h" #include +#include class DataModel : public QObject { @@ -34,35 +35,13 @@ public: public: DataModel(QObject *parent); - std::string toHtml() const; - - void write(std::ostream &outStream) const; + void printTo(QTextCursor &cursor) const; +void write(std::ostream &outStream) const; void read(std::istream &inStream); signals: void modelChanged(); -private: - template - void write( - const ModelType &model, QJsonObject &target, const char *name) const - { - QJsonObject jsonObject; - model.write(jsonObject); - target[name] = jsonObject; - } - - template - void read( - ModelType &model, const QJsonObject &source, const char *name) const - { - const auto &jsonObject = source[name]; - if (jsonObject.isObject()) - { - model.read(jsonObject.toObject()); - } - } - private slots: void pluralModelChanged(); void metaDataChanged(); diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 94c2a62..4a8403e 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -1,5 +1,6 @@ #include "MetaDataModel.h" +#include #include #include @@ -130,39 +131,52 @@ void MetaDataModel::write(ESGRAF48::MetaDataModel &model) const model.set_remarks(m_remarks.toStdString()); } -std::string MetaDataModel::toHtml() const +void MetaDataModel::printTo(QTextCursor &cursor) const { - std::ostringstream out; + cursor.insertBlock(); - out << "" - << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" - << std::endl; - out << "" << std::endl; - out << "" - << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" - << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" - << std::endl; - out << "" - << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "
Name, Vorname" << m_participant.toHtmlEscaped().toStdString() << "Untersucher(in)" << m_instructor.toHtmlEscaped().toStdString() << "
Geburtsdatum" << m_dateOfBirth.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "Bemerkungen
Untersuchungsdatum" << m_dateOfTest.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "" - << m_remarks.trimmed().toHtmlEscaped().replace("\n", "
").toStdString() << "
Alter am Testtag" << getAge().toString() << "
" << std::endl; + QTextTableFormat tableFormat = defaultTableFormat(); + tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_None); - return out.str(); + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 25), + QTextLength(QTextLength::PercentageLength, 25), + QTextLength(QTextLength::PercentageLength, 25), + QTextLength(QTextLength::PercentageLength, 25)}); + + QTextTable *table = cursor.insertTable(4, 4, tableFormat); + table->mergeCells(1, 2, 1, 2); + table->mergeCells(2, 2, 2, 2); + + cursor.insertText("Name, Vorname"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(m_participant); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText("Untersucher(in)"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(m_instructor); + cursor.movePosition(QTextCursor::NextRow); + + cursor.insertText("Geburtsdatum"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(m_dateOfBirth.toString("dd.MM.yyyy")); + cursor.movePosition(QTextCursor::NextCell); + if (!m_remarks.trimmed().isEmpty()) + { + cursor.insertText("Bemerkungen:"); + } + cursor.movePosition(QTextCursor::NextRow); + + cursor.insertText("Untersuchungsdatum"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(m_dateOfTest.toString("dd.MM.yyyy")); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(m_remarks.trimmed()); + cursor.movePosition(QTextCursor::NextRow); + + cursor.insertText("Alter am Testtag"); + cursor.movePosition(QTextCursor::NextCell); + cursor.insertText(getAge().toString().c_str()); + + cursor.movePosition(QTextCursor::End); } + diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 0c8bbeb..c019e1a 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -1,5 +1,6 @@ #pragma once +#include "../PrintableModel.h" #include "Age.h" #include "MetaDataModel.pb.h" @@ -8,8 +9,9 @@ #include #include #include +#include -class MetaDataModel : public QAbstractTableModel +class MetaDataModel : public QAbstractTableModel, protected PrintableModel { Q_OBJECT @@ -24,19 +26,17 @@ public: MetaDataModel(QObject *parent); 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; Qt::ItemFlags flags(const QModelIndex &index) const override; - bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole) override; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; void read(const ESGRAF48::MetaDataModel &model); void write(ESGRAF48::MetaDataModel &model) const; - std::string toHtml() const; + void printTo(QTextCursor &cursor) const override; Age getAge() const { - return { m_dateOfBirth, m_dateOfTest }; + return {m_dateOfBirth, m_dateOfTest}; } }; diff --git a/source/PrintableModel.cpp b/source/PrintableModel.cpp new file mode 100644 index 0000000..c3b9d03 --- /dev/null +++ b/source/PrintableModel.cpp @@ -0,0 +1,46 @@ +#include "PrintableModel.h" + +QTextTableFormat PrintableModel::defaultTableFormat() +{ + QTextTableFormat tableFormat; + tableFormat.setCellPadding(2); + tableFormat.setCellSpacing(0); + + return tableFormat; +} + +void PrintableModel::setCellText(QTextTable &table, int row, int column, const QString &text) +{ + auto cell = table.cellAt(row, column); + auto textCursor = cell.firstCursorPosition(); + + auto blockFormat = textCursor.blockFormat(); + blockFormat.setAlignment(Qt::AlignCenter); + textCursor.setBlockFormat(blockFormat); + + auto cellFormat = cell.format(); + cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + cell.setFormat(cellFormat); + + auto charFormat = textCursor.charFormat(); + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + charFormat.setFontPointSize(8); + textCursor.setCharFormat(charFormat); + + textCursor.insertText(text); +} + +void PrintableModel::setCellChecked(QTextTable &table, int row, int column, bool check) +{ + setCellText(table, row, column, check ? "x" : "\u2610"); +} + +void PrintableModel::setCellBackground(QTextTable &table, int row, int column, const QColor &color) +{ + auto cell = table.cellAt(row, column); + + auto cellFormat = cell.format(); + cellFormat.setBackground(QBrush(color)); + cell.setFormat(cellFormat); +} + diff --git a/source/PrintableModel.h b/source/PrintableModel.h new file mode 100644 index 0000000..b3652ac --- /dev/null +++ b/source/PrintableModel.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +class PrintableModel +{ +public: + virtual void printTo(QTextCursor &cursor) const = 0; + +protected: + static QTextTableFormat defaultTableFormat(); + + static void setCellText(QTextTable &table, int row, int column, const QString &text); + static void setCellChecked(QTextTable &table, int row, int column, bool check); + static void setCellBackground(QTextTable &table, int row, int column, const QColor &color); + + template + static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number) + { + setCellText(table, row, column, QString::number(number)); + } +}; diff --git a/source/ResultWidget/CMakeLists.txt b/source/ResultWidget/CMakeLists.txt index bfdd22c..9e70573 100644 --- a/source/ResultWidget/CMakeLists.txt +++ b/source/ResultWidget/CMakeLists.txt @@ -12,6 +12,7 @@ qt5_wrap_ui(GENUS_UI add_library(${PROJECT_NAME} ResultWidget.cpp + TestResult.cpp ResultModel.cpp PRMap.cpp ${GENUS_UI} diff --git a/source/ResultWidget/ResultModel.cpp b/source/ResultWidget/ResultModel.cpp index c905346..2c9fdc9 100644 --- a/source/ResultWidget/ResultModel.cpp +++ b/source/ResultWidget/ResultModel.cpp @@ -10,13 +10,13 @@ #include "PassivPR.h" #include "GenitivPR.h" +#include #include ResultModel::ResultModel(QObject *parent) - : QAbstractTableModel(parent) + : QAbstractTableModel(parent) { - m_results = { { "V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", - "Genitiv", "Plural" } }; + m_results = {"V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural"}; } int ResultModel::rowCount(const QModelIndex &parent) const @@ -81,8 +81,7 @@ QVariant ResultModel::data(const QModelIndex &index, int role) const return {}; } -QVariant ResultModel::headerData( - int section, Qt::Orientation orientation, int role) const +QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) { @@ -102,11 +101,11 @@ QVariant ResultModel::headerData( case 0: return "RP"; case 1: - return ">= PR 84"; + return "\u2265 PR 84"; case 2: return "< PR 84"; case 3: - return "<= PR 16"; + return "\u2264 PR 16"; default: return {}; } @@ -170,7 +169,7 @@ void ResultModel::setDativResult(unsigned int points) emit dataChanged(index(0, 6), index(4, 6)); } } - + void ResultModel::setV2Result(unsigned int points) { if (m_results[0].points() != points) @@ -193,20 +192,92 @@ void ResultModel::setSvkResult(unsigned int points) void ResultModel::setPassivResult(unsigned int points) { - if (m_results[3].points() != points) - { - m_results[3].setPoints(points); - m_results[3].setPR(PassivPR().lookup(m_age, points)); - emit dataChanged(index(0, 3), index(4, 3)); - } + if (m_results[3].points() != points) + { + m_results[3].setPoints(points); + m_results[3].setPR(PassivPR().lookup(m_age, points)); + emit dataChanged(index(0, 3), index(4, 3)); + } } void ResultModel::setGenitivResult(unsigned int points) { - if (m_results[7].points() != points) - { - m_results[7].setPoints(points); - m_results[7].setPR(GenitivPR().lookup(m_age, points)); - emit dataChanged(index(0, 7), index(4, 7)); - } + if (m_results[7].points() != points) + { + m_results[7].setPoints(points); + m_results[7].setPR(GenitivPR().lookup(m_age, points)); + emit dataChanged(index(0, 7), index(4, 7)); + } } + +void ResultModel::printTo(QTextCursor &cursor) const +{ + QTextCharFormat headerFormat; + headerFormat.setFontPointSize(10); + cursor.insertBlock(); + cursor.insertText("\nProzentränge (PR)"); + + QTextTableFormat tableFormat = defaultTableFormat(); + + const unsigned int columnCount = 10; + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10)}); + + QTextTable *table = cursor.insertTable(4, columnCount, tableFormat); + + auto insertText = [&table](int row, int column, const QString &text) { + auto cell = table->cellAt(row, column); + auto textCursor = cell.firstCursorPosition(); + + auto blockFormat = textCursor.blockFormat(); + blockFormat.setAlignment(Qt::AlignCenter); + textCursor.setBlockFormat(blockFormat); + + auto cellFormat = cell.format(); + cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + + if (row == 3) + { + QBrush backgroundBrush(QColor(192, 192, 192)); + cellFormat.setBackground(backgroundBrush); + } + + cell.setFormat(cellFormat); + + auto charFormat = textCursor.charFormat(); + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + charFormat.setFontPointSize(8); + + if (row == 0 || column == 0) + { + charFormat.setFontWeight(QFont::Bold); + } + + textCursor.setCharFormat(charFormat); + + textCursor.insertText(text); + }; + + insertText(1, 0, "\u2265 PR 84"); + insertText(2, 0, "< PR 84"); + insertText(3, 0, "\u2264 PR 16"); + + for (size_t index = 0; index < m_results.size(); ++index) + { + insertText(0, index + 1, m_results[index].name()); + int pr = m_results[index].pr(); + insertText(1, index + 1, pr >= 84 ? QString::number(pr) : "-"); + insertText(2, index + 1, pr < 84 && pr > 16 ? QString::number(pr) : "-"); + insertText(3, index + 1, pr <= 16 ? QString::number(pr) : "-"); + } +} + diff --git a/source/ResultWidget/ResultModel.h b/source/ResultWidget/ResultModel.h index ae6dd78..3e58ba3 100644 --- a/source/ResultWidget/ResultModel.h +++ b/source/ResultWidget/ResultModel.h @@ -1,48 +1,13 @@ #pragma once +#include "../PrintableModel.h" #include "Age.h" +#include "TestResult.h" + #include +#include -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 +class ResultModel : public QAbstractTableModel, protected PrintableModel { Q_OBJECT @@ -56,11 +21,10 @@ 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; + int role = Qt::DisplayRole) const override; void setAge(const Age &age); void setPluralResult(unsigned int points); @@ -70,6 +34,8 @@ public: void setDativResult(unsigned int points); void setV2Result(unsigned int points); void setSvkResult(unsigned int points); - void setPassivResult(unsigned int points); - void setGenitivResult(unsigned int points); + void setPassivResult(unsigned int points); + void setGenitivResult(unsigned int points); + + void printTo(QTextCursor &cursor) const override; }; diff --git a/source/ResultWidget/TestResult.cpp b/source/ResultWidget/TestResult.cpp new file mode 100644 index 0000000..fb9800b --- /dev/null +++ b/source/ResultWidget/TestResult.cpp @@ -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; +} diff --git a/source/ResultWidget/TestResult.h b/source/ResultWidget/TestResult.h new file mode 100644 index 0000000..001e210 --- /dev/null +++ b/source/ResultWidget/TestResult.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +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; +}; + diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.cpp b/source/SubTests/AkkusativDativ/AkkusativModel.cpp index 79d2c31..b481c50 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.cpp +++ b/source/SubTests/AkkusativDativ/AkkusativModel.cpp @@ -105,3 +105,8 @@ void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const futterModel->set_zucker(testItems[7].isChecked()); } } + +std::string AkkusativModel::getName() const +{ + return "Subtest 4: Akkusativ und Dativ"; +} diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.h b/source/SubTests/AkkusativDativ/AkkusativModel.h index 43a4881..ae9d2f2 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.h +++ b/source/SubTests/AkkusativDativ/AkkusativModel.h @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::AkkusativModel &model); void write(ESGRAF48::AkkusativModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index 081dfdb..1948370 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -105,3 +105,8 @@ void DativModel::write(ESGRAF48::DativModel &model) const futterModel->set_zucker(testItems[7].isChecked()); } } + +std::string DativModel::getName() const +{ + return ""; +} diff --git a/source/SubTests/AkkusativDativ/DativModel.h b/source/SubTests/AkkusativDativ/DativModel.h index 6a9a323..97b7a59 100644 --- a/source/SubTests/AkkusativDativ/DativModel.h +++ b/source/SubTests/AkkusativDativ/DativModel.h @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::DativModel &model); void write(ESGRAF48::DativModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index 3f2278b..b708ee7 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -95,3 +95,8 @@ void GenusModel::write(ESGRAF48::GenusModel &model) const zirkusModel->set_baum(testItems[3].isChecked()); } } + +std::string GenusModel::getName() const +{ + return "Subtest 3: Genus"; +} diff --git a/source/SubTests/Genus/GenusModel.h b/source/SubTests/Genus/GenusModel.h index 8261779..590873d 100644 --- a/source/SubTests/Genus/GenusModel.h +++ b/source/SubTests/Genus/GenusModel.h @@ -12,4 +12,7 @@ public: void read(const ESGRAF48::GenusModel &model); void write(ESGRAF48::GenusModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/LateSkills/CMakeLists.txt b/source/SubTests/LateSkills/CMakeLists.txt index 7fef071..3a72146 100644 --- a/source/SubTests/LateSkills/CMakeLists.txt +++ b/source/SubTests/LateSkills/CMakeLists.txt @@ -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} diff --git a/source/SubTests/LateSkills/GenitivModel.cpp b/source/SubTests/LateSkills/GenitivModel.cpp index 9ebf423..ffff088 100644 --- a/source/SubTests/LateSkills/GenitivModel.cpp +++ b/source/SubTests/LateSkills/GenitivModel.cpp @@ -1,7 +1,7 @@ #include "GenitivModel.h" GenitivModel::GenitivModel(QObject *parent) - : CheckableTestModel(parent) + : LateSkillsModel(parent) { m_tests = { {"Genitiv Präpositionen", @@ -107,3 +107,8 @@ void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel &model) const attributierungModel->set_guertel2(testItems[9].isChecked()); } } + +std::string GenitivModel::getName() const +{ + return ""; +} diff --git a/source/SubTests/LateSkills/GenitivModel.h b/source/SubTests/LateSkills/GenitivModel.h index 2346e94..809b26e 100644 --- a/source/SubTests/LateSkills/GenitivModel.h +++ b/source/SubTests/LateSkills/GenitivModel.h @@ -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 @@ -14,4 +14,7 @@ public: void read(const ESGRAF48::LateSkillsGenitivModel &model); void write(ESGRAF48::LateSkillsGenitivModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/LateSkills/LateSkillsModel.cpp b/source/SubTests/LateSkills/LateSkillsModel.cpp new file mode 100644 index 0000000..95ab46b --- /dev/null +++ b/source/SubTests/LateSkills/LateSkillsModel.cpp @@ -0,0 +1,65 @@ +#include "LateSkillsModel.h" + +#include + +#include + +LateSkillsModel::LateSkillsModel(QObject *parent) + : CheckableTestModel(parent) +{ +} + +void LateSkillsModel::printTableTo(QTextCursor &cursor) const +{ + 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; + } +} diff --git a/source/SubTests/LateSkills/LateSkillsModel.h b/source/SubTests/LateSkills/LateSkillsModel.h new file mode 100644 index 0000000..a891813 --- /dev/null +++ b/source/SubTests/LateSkills/LateSkillsModel.h @@ -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; +}; diff --git a/source/SubTests/LateSkills/PassivModel.cpp b/source/SubTests/LateSkills/PassivModel.cpp index 6f1d3a8..ceca388 100644 --- a/source/SubTests/LateSkills/PassivModel.cpp +++ b/source/SubTests/LateSkills/PassivModel.cpp @@ -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)", @@ -65,3 +65,8 @@ void PassivModel::write(ESGRAF48::LateSkillsPassivModel &model) const model.set_fleisch1(testItems[8].isChecked()); model.set_fleisch2(testItems[9].isChecked()); } + +std::string PassivModel::getName() const +{ + return "Subtest 6: Späte Fähigkeiten (7;0 - 8;11)"; +} diff --git a/source/SubTests/LateSkills/PassivModel.h b/source/SubTests/LateSkills/PassivModel.h index e0671bb..c9fdb3f 100644 --- a/source/SubTests/LateSkills/PassivModel.h +++ b/source/SubTests/LateSkills/PassivModel.h @@ -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 @@ -14,4 +14,7 @@ public: void read(const ESGRAF48::LateSkillsPassivModel &model); void write(ESGRAF48::LateSkillsPassivModel &model) const; + +protected: + std::string getName() const override; }; diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index 0ade859..f3ccbd9 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -1,6 +1,10 @@ #include "PluralModel.h" #include +#include +#include + +#include PluralModel::PluralModel(QObject *parent) : CheckableTestModel(parent) @@ -51,3 +55,41 @@ void PluralModel::write(ESGRAF48::PluralModel &model) const model.set_baer(testItems[7].isChecked()); model.set_apfel(testItems[8].isChecked()); } + +std::string PluralModel::getName() const +{ + return "Subtest 5: Plural"; +} + +void PluralModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat = defaultTableFormat(); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10)}); + + QTextTable *table = cursor.insertTable(2, 10, tableFormat); + + const auto &test = m_tests.front(); + + int currentColumn = 0; + for (const auto &item : test.items()) + { + std::string itemName = std::regex_replace(item.getText(), std::regex("\\s"), "\n", + std::regex_constants::format_first_only); + + setCellText(*table, 0, currentColumn, itemName.c_str()); + setCellChecked(*table, 1, currentColumn, item.isChecked()); + + currentColumn++; + } +} + diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index cadeae9..cfa977f 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -15,4 +15,9 @@ public: void read(const ESGRAF48::PluralModel &model); void write(ESGRAF48::PluralModel &model) const; + +protected: + std::string getName() const override; + + void printTableTo(QTextCursor &cursor) const override; }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 2196ba4..a982b93 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -1,10 +1,12 @@ #include "V2SvkModel.h" +#include + V2SvkModel::V2SvkModel(QObject *parent) : CheckableTestModel(parent) { m_tests = { - {"W-Frage", + {"W-Fragen", {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", "Gans", "Gans", "Gans"}}, {"Verbtrennung", {"", "Affe", "", "", "", "", "", "Schwein", "", "", "Gans", ""}}, @@ -29,7 +31,7 @@ V2SvkModel::V2SvkModel(QObject *parent) }; } -unsigned int V2SvkModel::getV2Points() +unsigned int V2SvkModel::getV2Points() const { unsigned int points = 0; @@ -49,7 +51,7 @@ unsigned int V2SvkModel::getV2Points() return points; } -unsigned int V2SvkModel::getSvkPoints() +unsigned int V2SvkModel::getSvkPoints() const { unsigned int points = 0; @@ -199,3 +201,147 @@ void V2SvkModel::read(const ESGRAF48::V2SvkModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +std::string V2SvkModel::getName() const +{ + return "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)"; +} + +void V2SvkModel::printTableTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat12 = defaultTableFormat(); + + tableFormat12.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, 5), + QTextLength(QTextLength::PercentageLength, 5), + QTextLength(QTextLength::PercentageLength, 13), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTableFormat tableFormat6 = defaultTableFormat(); + + tableFormat6.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 10), + QTextLength(QTextLength::PercentageLength, 13), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + auto writeHeader = [](QTextTable *table, const CheckableTest &test, int colSpan) { + table->mergeCells(0, 0, 2, 1); + + int column = 1; + + for (auto it = std::begin(test.items()); it != std::end(test.items()); + std::advance(it, colSpan)) + { + table->mergeCells(0, column, 1, colSpan); + setCellText(*table, 0, column, it->getText().c_str()); + + column += colSpan; + } + }; + + auto writeLine = [](QTextTable *table, const CheckableTest &test, int row, int resultColumn) { + int column = 0; + + setCellText(*table, row, column, test.name()); + for (const auto item : test.items()) + { + column++; + + if (item.getText().empty()) + { + setCellBackground(*table, row, column, QColor(92, 92, 92)); + } + else + { + setCellChecked(*table, row, column, item.isChecked()); + } + } + + setCellNumber(*table, row, resultColumn, test.getPoints()); + }; + + { + QTextTable *table = cursor.insertTable(4, 17, tableFormat12); + + writeHeader(table, m_tests[0], 4); + writeLine(table, m_tests[0], 1, 14); + writeLine(table, m_tests[1], 2, 14); + writeLine(table, m_tests[2], 3, 16); + } + + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + + { + QTextTable *table = cursor.insertTable(3, 17, tableFormat12); + + writeHeader(table, m_tests[3], 4); + writeLine(table, m_tests[3], 1, 14); + writeLine(table, m_tests[4], 2, 16); + } + + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + + { + QTextTable *table = cursor.insertTable(3, 11, tableFormat6); + + writeHeader(table, m_tests[5], 2); + writeLine(table, m_tests[5], 1, 8); + writeLine(table, m_tests[6], 2, 10); + } + + cursor.movePosition(QTextCursor::End); + cursor.insertBlock(); + cursor.insertText("\n"); + + { + QTextTable *table = cursor.insertTable(5, 11, tableFormat6); + + writeHeader(table, m_tests[7], 2); + writeLine(table, m_tests[7], 1, 8); + writeLine(table, m_tests[8], 2, 8); + writeLine(table, m_tests[9], 3, 10); + writeLine(table, m_tests[10], 4, 10); + } +} + +void V2SvkModel::printSummaryTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat = defaultTableFormat(); + + tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 72), + QTextLength(QTextLength::PercentageLength, 20), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3), + QTextLength(QTextLength::PercentageLength, 1), + QTextLength(QTextLength::PercentageLength, 3)}); + + QTextTable *table = cursor.insertTable(1, 6, tableFormat); + + setCellText(*table, 0, 1, "Rohwertpunkte Total:"); + setCellNumber(*table, 0, 3, getV2Points()); + setCellNumber(*table, 0, 5, getSvkPoints()); +} + diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index 519508a..7794b7a 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -3,6 +3,8 @@ #include "CheckableTestModel.h" #include "V2SvkModel.pb.h" +#include + class V2SvkModel : public CheckableTestModel { Q_OBJECT @@ -10,12 +12,16 @@ class V2SvkModel : public CheckableTestModel public: V2SvkModel(QObject *parent); - unsigned int getV2Points(); - unsigned int getSvkPoints(); + unsigned int getV2Points() const; + unsigned int getSvkPoints() const; void write(ESGRAF48::V2SvkModel &model) const; void read(const ESGRAF48::V2SvkModel &model); protected: bool isValidIndex(const QModelIndex &index) const override; + + std::string getName() const override; + void printTableTo(QTextCursor &cursor) const override; + void printSummaryTo(QTextCursor &cursor) const override; }; diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index dea4d95..9061d23 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -1,15 +1,17 @@ #include "VerbEndModel.h" +#include +#include + VerbEndModel::VerbEndModel(QObject *parent) - : CheckableTestModel(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"}}}; + + connect(this, &VerbEndModel::dataChanged, this, &VerbEndModel::modelChanged); } void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const @@ -98,3 +100,52 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } + +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()); +} + +std::string VerbEndModel::getName() const +{ + return "Subtest 2: Verbendstellungsregel (VE)"; +}; + +void VerbEndModel::printSummaryTo(QTextCursor &cursor) const +{ + QTextTableFormat tableFormat = defaultTableFormat(); + + 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()); +} diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index cf6342a..44a3897 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -3,6 +3,8 @@ #include "CheckableTestModel.h" #include "VerbEndModel.pb.h" +#include + class VerbEndModel : public CheckableTestModel { Q_OBJECT @@ -12,4 +14,16 @@ public: void write(ESGRAF48::VerbEndModel &model) const; void read(const ESGRAF48::VerbEndModel &model); + + unsigned int getCausalPoints() const; + +protected: + std::string getName() const override; + void printSummaryTo(QTextCursor &cursor) const override; + +private slots: + void modelChanged(); + +signals: + void causalPointsChanged(unsigned int points); }; diff --git a/source/SubTests/VerbEnd/VerbEndWidget.cpp b/source/SubTests/VerbEnd/VerbEndWidget.cpp index c3ebbc5..ee3ffee 100644 --- a/source/SubTests/VerbEnd/VerbEndWidget.cpp +++ b/source/SubTests/VerbEnd/VerbEndWidget.cpp @@ -20,4 +20,11 @@ VerbEndWidget::~VerbEndWidget() void VerbEndWidget::setModel(VerbEndModel *model) { ui->verbEndTableView->setModel(model); + + connect(model, &VerbEndModel::causalPointsChanged, this, &VerbEndWidget::causalPointsChanged); +} + +void VerbEndWidget::causalPointsChanged(unsigned int points) +{ + ui->causalPointsLabel->setText(QString::number(points)); } diff --git a/source/SubTests/VerbEnd/VerbEndWidget.h b/source/SubTests/VerbEnd/VerbEndWidget.h index 95f7ef5..e3b3eaa 100644 --- a/source/SubTests/VerbEnd/VerbEndWidget.h +++ b/source/SubTests/VerbEnd/VerbEndWidget.h @@ -20,4 +20,7 @@ public: ~VerbEndWidget(); void setModel(VerbEndModel *model); + +public slots: + void causalPointsChanged(unsigned int points); }; diff --git a/source/SubTests/VerbEnd/VerbEndWidget.ui b/source/SubTests/VerbEnd/VerbEndWidget.ui index 98c9e4e..b57c1f0 100644 --- a/source/SubTests/VerbEnd/VerbEndWidget.ui +++ b/source/SubTests/VerbEnd/VerbEndWidget.ui @@ -6,8 +6,8 @@ 0 0 - 556 - 210 + 732 + 381 @@ -17,6 +17,30 @@ + + + + + + + 80 + 16777215 + + + + Kausalsätze: + + + + + + + 0 + + + + + diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index e91549a..528bcc7 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -150,10 +150,8 @@ void MainWindow::closeFile() void MainWindow::print() const { - //std::ofstream htmlfile("print.html"); - //htmlfile << m_dataModel.toHtml(); - QPrinter printer; + printer.setResolution(1200); QPrintDialog dialog(&printer); if (dialog.exec() != QDialog::Accepted) @@ -162,7 +160,8 @@ void MainWindow::print() const } QTextDocument printDoc; - printDoc.setHtml(QString::fromStdString(m_dataModel.toHtml())); + QTextCursor printCursor(&printDoc); + m_dataModel.printTo(printCursor); printDoc.print(&printer); } @@ -211,12 +210,14 @@ void MainWindow::saveFile(const QString &filename) void MainWindow::savePdf(const QString &filename) { QPrinter printer; + printer.setResolution(1200); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPaperSize(QPrinter::A4); printer.setOutputFileName(filename); QTextDocument printDoc; - printDoc.setHtml(QString::fromStdString(m_dataModel.toHtml())); + QTextCursor printCursor(&printDoc); + m_dataModel.printTo(printCursor); printDoc.print(&printer); } diff --git a/source/mainwindow.h b/source/mainwindow.h index 9675fb7..b270840 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -5,7 +5,6 @@ #include #include - class DataModel; class QDataWidgetMapper;