diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index b4ae54a..e962874 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -178,3 +178,21 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const throw std::runtime_error("invalid index"); } + +unsigned int CheckableTestModel::getPoints() const +{ + size_t points = 0; + + for (const auto &test : m_tests) + { + for (const auto &item : test.items()) + { + if (item.isChecked()) + { + points++; + } + } + } + + return points; +} diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index 9061a27..ee67c7b 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -28,6 +28,8 @@ public: void write(QJsonObject &json) const; void read(const QJsonObject &json); + unsigned int getPoints() const; + private: bool isValidIndex(const QModelIndex &index) const; diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 7cde0b9..05e8db2 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -10,11 +10,14 @@ DataModel::DataModel(QObject *parent) , m_plural(this) , m_results(this) { - connect(&m_plural, &PluralModel::dataChanged, - this, &DataModel::pluralModelChanged); + connect(&m_plural, &PluralModel::dataChanged, this, + &DataModel::pluralModelChanged); - connect(&m_metaData, &PluralModel::dataChanged, - this, &DataModel::metaDataChanged); + connect(&m_metaData, &PluralModel::dataChanged, this, + &DataModel::metaDataChanged); + + connect(&m_genus, &GenusModel::dataChanged, this, + &DataModel::genusModelChanged); } void DataModel::write(QJsonObject &target) const @@ -32,7 +35,7 @@ void DataModel::read(const QJsonObject &source) read(m_genus, source, "Genus"); read(m_plural, source, "Plural"); } - + void DataModel::pluralModelChanged() { m_results.setPluralResult(m_plural.getPoints()); @@ -42,3 +45,8 @@ void DataModel::metaDataChanged() { m_results.setAge(m_metaData.getAge()); } + +void DataModel::genusModelChanged() +{ + m_results.setGenusResult(m_genus.getPoints()); +} diff --git a/source/DataModel.h b/source/DataModel.h index 295eede..7566c5b 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -51,4 +51,5 @@ private: private slots: void pluralModelChanged(); void metaDataChanged(); + void genusModelChanged(); }; diff --git a/source/ResultWidget/GenusPR.h b/source/ResultWidget/GenusPR.h new file mode 100644 index 0000000..eb620e4 --- /dev/null +++ b/source/ResultWidget/GenusPR.h @@ -0,0 +1,46 @@ +#pragma once + +#include "PRMap.h" + +class GenusPR : public PRMap +{ +public: + GenusPR() + { + // clang-format off + m_ages = { + { 4, 0 }, + { 5, 0 }, + { 6, 0 }, + { 7, 0 }, + { 8, 0 }, + { 9, 0 } + }; + + m_PRs = { + { 1, 0, 0, 0, 0 }, + { 1, 0, 0, 0, 0 }, + { 2, 1, 0, 0, 0 }, + { 3, 1, 1, 0, 0 }, + { 9, 1, 1, 0, 0 }, + { 13, 3, 2, 0, 0 }, + { 14, 5, 2, 1, 0 }, + { 19, 7, 2, 1, 0 }, + { 22, 8, 3, 1, 0 }, + { 27, 10, 4, 2, 0 }, + { 31, 13, 5, 2, 0 }, + { 35, 17, 7, 2, 0 }, + { 39, 18, 7, 2, 0 }, + { 46, 20, 8, 2, 0 }, + { 51, 23, 9, 2, 1 }, + { 56, 26, 11, 2, 1 }, + { 62, 34, 17, 4, 1 }, + { 71, 47, 22, 8, 4 }, + { 81, 57, 29, 17, 9 }, + { 94, 75, 49, 37, 27 }, + { 100, 100, 100, 100, 100 }, + }; + // clang-format on + } +}; + diff --git a/source/ResultWidget/PluralPR.h b/source/ResultWidget/PluralPR.h new file mode 100644 index 0000000..404cfcc --- /dev/null +++ b/source/ResultWidget/PluralPR.h @@ -0,0 +1,32 @@ +#pragma once + +#include "PRMap.h" + +class PluralPR : public PRMap +{ +public: + PluralPR() + { + // clang-format off + m_ages = { + { 4, 0 }, + { 4, 6 }, + { 5, 6 }, + { 9, 0 } + }; + + m_PRs = { + { 0, 0, 0 }, + { 0, 1, 0 }, + { 0, 1, 0 }, + { 1, 1, 0 }, + { 7, 2, 1 }, + { 10, 4, 1}, + { 26, 10, 2 }, + { 57, 25, 7 }, + { 79, 56, 27 }, + { 100, 100, 100 } + }; + // clang-format on + } +}; diff --git a/source/ResultWidget/ResultModel.cpp b/source/ResultWidget/ResultModel.cpp index a320691..0e6ad4b 100644 --- a/source/ResultWidget/ResultModel.cpp +++ b/source/ResultWidget/ResultModel.cpp @@ -1,5 +1,8 @@ #include "ResultModel.h" +#include "PluralPR.h" +#include "GenusPR.h" + #include ResultModel::ResultModel(QObject *parent) @@ -114,7 +117,7 @@ void ResultModel::setAge(const Age &age) emit dataChanged(index(1, 0), index(4, 8)); } -void ResultModel::setPluralResult(size_t points) +void ResultModel::setPluralResult(unsigned int points) { if (m_results[8].points() != points) { @@ -124,3 +127,12 @@ void ResultModel::setPluralResult(size_t points) } } +void ResultModel::setGenusResult(unsigned int points) +{ + if (m_results[4].points() != points) + { + m_results[4].setPoints(points); + m_results[4].setPR(GenusPR().lookup(m_age, points)); + emit dataChanged(index(0, 4), index(4, 4)); + } +} diff --git a/source/ResultWidget/ResultModel.h b/source/ResultWidget/ResultModel.h index c88f4af..9b6f3c9 100644 --- a/source/ResultWidget/ResultModel.h +++ b/source/ResultWidget/ResultModel.h @@ -1,38 +1,8 @@ #pragma once #include "../Age.h" -#include "PRMap.h" #include -class PluralPR : public PRMap -{ -public: - PluralPR() - { - // clang-format off - m_ages = { - { 4, 0 }, - { 4, 6 }, - { 5, 6 }, - { 9, 0 } - }; - - m_PRs = { - { 0, 0, 0 }, - { 0, 1, 0 }, - { 0, 1, 0 }, - { 1, 1, 0 }, - { 7, 2, 1 }, - { 10, 4, 1}, - { 26, 10, 2 }, - { 57, 25, 7 }, - { 79, 56, 27 }, - { 100, 100, 100 } - }; - // clang-format on - } -}; - class TestResult { private: @@ -93,5 +63,6 @@ public: int role = Qt::DisplayRole) const override; void setAge(const Age &age); - void setPluralResult(size_t points); + void setPluralResult(unsigned int points); + void setGenusResult(unsigned int points); }; diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index f1a284f..ec941ba 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -4,8 +4,8 @@ GenusModel::GenusModel(QObject *parent) : CheckableTestModel(parent) { m_tests = { { "Tiere", { "Tiger", "Bär", "Katze", "Pferd", "Gans", - "Elefant", "Katze", "Hund" } }, - { "Futter", { "Salat", "Fleisch", "Knocken", "Banane", "Apfel", "Möhre", + "Elefant", "Affe", "Hund" } }, + { "Futter", { "Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Möhre", "Honig", "Zucker" } }, { "Zirkus", { "Kiste", "Holz", "Vorhang", "Baum" } } }; } diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index d5bb899..38f881a 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -8,20 +8,3 @@ PluralModel::PluralModel(QObject *parent) "Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML" } } }; } -size_t PluralModel::getPoints() const -{ - size_t points = 0; - - for (const auto &test : m_tests) - { - for (const auto &item : test.items()) - { - if (item.isChecked()) - { - points++; - } - } - } - - return points; -} diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index 5d7273d..60427c0 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -8,9 +8,4 @@ class PluralModel : public CheckableTestModel public: PluralModel(QObject *parent); - - size_t getPoints() const; - -signals: - void resultChanged(size_t result) const; };