implemented genus test results

This commit is contained in:
Michael Mandl 2018-06-15 17:53:43 +02:00
parent 060348fdc5
commit 5bc7edabc6
11 changed files with 129 additions and 61 deletions

View file

@ -178,3 +178,21 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const
throw std::runtime_error("invalid index"); 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;
}

View file

@ -28,6 +28,8 @@ public:
void write(QJsonObject &json) const; void write(QJsonObject &json) const;
void read(const QJsonObject &json); void read(const QJsonObject &json);
unsigned int getPoints() const;
private: private:
bool isValidIndex(const QModelIndex &index) const; bool isValidIndex(const QModelIndex &index) const;

View file

@ -10,11 +10,14 @@ DataModel::DataModel(QObject *parent)
, m_plural(this) , m_plural(this)
, m_results(this) , m_results(this)
{ {
connect(&m_plural, &PluralModel::dataChanged, connect(&m_plural, &PluralModel::dataChanged, this,
this, &DataModel::pluralModelChanged); &DataModel::pluralModelChanged);
connect(&m_metaData, &PluralModel::dataChanged, connect(&m_metaData, &PluralModel::dataChanged, this,
this, &DataModel::metaDataChanged); &DataModel::metaDataChanged);
connect(&m_genus, &GenusModel::dataChanged, this,
&DataModel::genusModelChanged);
} }
void DataModel::write(QJsonObject &target) const void DataModel::write(QJsonObject &target) const
@ -32,7 +35,7 @@ void DataModel::read(const QJsonObject &source)
read(m_genus, source, "Genus"); read(m_genus, source, "Genus");
read(m_plural, source, "Plural"); read(m_plural, source, "Plural");
} }
void DataModel::pluralModelChanged() void DataModel::pluralModelChanged()
{ {
m_results.setPluralResult(m_plural.getPoints()); m_results.setPluralResult(m_plural.getPoints());
@ -42,3 +45,8 @@ void DataModel::metaDataChanged()
{ {
m_results.setAge(m_metaData.getAge()); m_results.setAge(m_metaData.getAge());
} }
void DataModel::genusModelChanged()
{
m_results.setGenusResult(m_genus.getPoints());
}

View file

@ -51,4 +51,5 @@ private:
private slots: private slots:
void pluralModelChanged(); void pluralModelChanged();
void metaDataChanged(); void metaDataChanged();
void genusModelChanged();
}; };

View file

@ -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
}
};

View file

@ -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
}
};

View file

@ -1,5 +1,8 @@
#include "ResultModel.h" #include "ResultModel.h"
#include "PluralPR.h"
#include "GenusPR.h"
#include <QDebug> #include <QDebug>
ResultModel::ResultModel(QObject *parent) ResultModel::ResultModel(QObject *parent)
@ -114,7 +117,7 @@ void ResultModel::setAge(const Age &age)
emit dataChanged(index(1, 0), index(4, 8)); 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) 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));
}
}

View file

@ -1,38 +1,8 @@
#pragma once #pragma once
#include "../Age.h" #include "../Age.h"
#include "PRMap.h"
#include <QAbstractTableModel> #include <QAbstractTableModel>
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 class TestResult
{ {
private: private:
@ -93,5 +63,6 @@ public:
int role = Qt::DisplayRole) const override; int role = Qt::DisplayRole) const override;
void setAge(const Age &age); void setAge(const Age &age);
void setPluralResult(size_t points); void setPluralResult(unsigned int points);
void setGenusResult(unsigned int points);
}; };

View file

@ -4,8 +4,8 @@ GenusModel::GenusModel(QObject *parent)
: CheckableTestModel(parent) : CheckableTestModel(parent)
{ {
m_tests = { { "Tiere", { "Tiger", "Bär", "Katze", "Pferd", "Gans", m_tests = { { "Tiere", { "Tiger", "Bär", "Katze", "Pferd", "Gans",
"Elefant", "Katze", "Hund" } }, "Elefant", "Affe", "Hund" } },
{ "Futter", { "Salat", "Fleisch", "Knocken", "Banane", "Apfel", "Möhre", { "Futter", { "Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Möhre",
"Honig", "Zucker" } }, "Honig", "Zucker" } },
{ "Zirkus", { "Kiste", "Holz", "Vorhang", "Baum" } } }; { "Zirkus", { "Kiste", "Holz", "Vorhang", "Baum" } } };
} }

View file

@ -8,20 +8,3 @@ PluralModel::PluralModel(QObject *parent)
"Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML" } } }; "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;
}

View file

@ -8,9 +8,4 @@ class PluralModel : public CheckableTestModel
public: public:
PluralModel(QObject *parent); PluralModel(QObject *parent);
size_t getPoints() const;
signals:
void resultChanged(size_t result) const;
}; };