notify result widget about plural test changes
This commit is contained in:
parent
1f9a051382
commit
077efaac32
5
source/Age.h
Normal file
5
source/Age.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
class Age
|
||||
{
|
||||
};
|
@ -78,6 +78,7 @@ bool CheckableTestModel::setData(
|
||||
{
|
||||
auto &item = getItem(index);
|
||||
item.setState(value.toBool());
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "DataModel.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
DataModel::DataModel(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_metaData(this)
|
||||
@ -8,6 +10,11 @@ DataModel::DataModel(QObject *parent)
|
||||
, m_plural(this)
|
||||
, m_results(this)
|
||||
{
|
||||
connect(&m_plural, &PluralModel::dataChanged,
|
||||
this, &DataModel::pluralModelChanged);
|
||||
|
||||
connect(&m_metaData, &PluralModel::dataChanged,
|
||||
this, &DataModel::metaDataChanged);
|
||||
}
|
||||
|
||||
void DataModel::write(QJsonObject &target) const
|
||||
@ -25,3 +32,12 @@ 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());
|
||||
}
|
||||
|
||||
void DataModel::metaDataChanged()
|
||||
{
|
||||
}
|
||||
|
@ -47,4 +47,8 @@ private:
|
||||
model.read(jsonObject.toObject());
|
||||
}
|
||||
}
|
||||
|
||||
private slots:
|
||||
void pluralModelChanged();
|
||||
void metaDataChanged();
|
||||
};
|
||||
|
@ -98,6 +98,11 @@ bool MetaDataModel::setData(
|
||||
break;
|
||||
}
|
||||
|
||||
if (valueChanged)
|
||||
{
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
return valueChanged;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Age.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QString>
|
||||
#include <QDate>
|
||||
@ -28,4 +30,9 @@ public:
|
||||
|
||||
void write(QJsonObject &json) const;
|
||||
void read(const QJsonObject &json);
|
||||
|
||||
Age getAge() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
@ -5,7 +5,8 @@
|
||||
ResultModel::ResultModel(QObject *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
|
||||
@ -22,7 +23,16 @@ QVariant ResultModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return "data";
|
||||
if (index.column() < m_results.size())
|
||||
{
|
||||
size_t points = m_results[index.column()].points();
|
||||
if (points != 0)
|
||||
{
|
||||
return static_cast<uint>(points);
|
||||
}
|
||||
}
|
||||
|
||||
return "-";
|
||||
}
|
||||
|
||||
return {};
|
||||
@ -59,3 +69,17 @@ QVariant ResultModel::headerData(
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void ResultModel::setAge(const QDate &age)
|
||||
{
|
||||
m_age = age;
|
||||
}
|
||||
|
||||
void ResultModel::setPluralResult(size_t points)
|
||||
{
|
||||
if (m_results[8].points() != points)
|
||||
{
|
||||
m_results[8] = points;
|
||||
emit dataChanged(index(0, 8), index(2, 8));
|
||||
}
|
||||
}
|
||||
|
@ -2,22 +2,35 @@
|
||||
|
||||
#include <vector>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QDate>
|
||||
|
||||
class TestResult
|
||||
{
|
||||
private:
|
||||
QString m_name;
|
||||
size_t m_points;
|
||||
|
||||
public:
|
||||
TestResult(const char *name)
|
||||
: m_name(name)
|
||||
, m_points(0)
|
||||
{
|
||||
}
|
||||
|
||||
void operator=(const size_t &points)
|
||||
{
|
||||
m_points = points;
|
||||
}
|
||||
|
||||
const QString &name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
const size_t points() const
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
};
|
||||
|
||||
class ResultModel : public QAbstractTableModel
|
||||
@ -25,6 +38,7 @@ class ResultModel : public QAbstractTableModel
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QDate m_age;
|
||||
std::vector<TestResult> m_results;
|
||||
|
||||
public:
|
||||
@ -38,4 +52,7 @@ public:
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
void setAge(const QDate &age);
|
||||
void setPluralResult(size_t points);
|
||||
};
|
||||
|
@ -4,6 +4,24 @@ PluralModel::PluralModel(QObject *parent)
|
||||
: CheckableTestModel(parent)
|
||||
{
|
||||
m_tests = { { "",
|
||||
{ "Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-o/",
|
||||
{ "Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/",
|
||||
"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,4 +8,9 @@ class PluralModel : public CheckableTestModel
|
||||
|
||||
public:
|
||||
PluralModel(QObject *parent);
|
||||
|
||||
size_t getPoints() const;
|
||||
|
||||
signals:
|
||||
void resultChanged(size_t result) const;
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>905</width>
|
||||
<width>1125</width>
|
||||
<height>572</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -89,7 +89,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>905</width>
|
||||
<width>1125</width>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
Reference in New Issue
Block a user