implemented genus test results
This commit is contained in:
parent
060348fdc5
commit
5bc7edabc6
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
@ -42,3 +45,8 @@ void DataModel::metaDataChanged()
|
||||
{
|
||||
m_results.setAge(m_metaData.getAge());
|
||||
}
|
||||
|
||||
void DataModel::genusModelChanged()
|
||||
{
|
||||
m_results.setGenusResult(m_genus.getPoints());
|
||||
}
|
||||
|
@ -51,4 +51,5 @@ private:
|
||||
private slots:
|
||||
void pluralModelChanged();
|
||||
void metaDataChanged();
|
||||
void genusModelChanged();
|
||||
};
|
||||
|
46
source/ResultWidget/GenusPR.h
Normal file
46
source/ResultWidget/GenusPR.h
Normal 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
|
||||
}
|
||||
};
|
||||
|
32
source/ResultWidget/PluralPR.h
Normal file
32
source/ResultWidget/PluralPR.h
Normal 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
|
||||
}
|
||||
};
|
@ -1,5 +1,8 @@
|
||||
#include "ResultModel.h"
|
||||
|
||||
#include "PluralPR.h"
|
||||
#include "GenusPR.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Age.h"
|
||||
#include "PRMap.h"
|
||||
#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
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
@ -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" } } };
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -8,9 +8,4 @@ class PluralModel : public CheckableTestModel
|
||||
|
||||
public:
|
||||
PluralModel(QObject *parent);
|
||||
|
||||
size_t getPoints() const;
|
||||
|
||||
signals:
|
||||
void resultChanged(size_t result) const;
|
||||
};
|
||||
|
Reference in New Issue
Block a user