2019-01-31 19:14:38 +00:00
|
|
|
#include "WFModel.h"
|
2018-06-25 21:04:32 +00:00
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
WFModel::WFModel(QObject *parent)
|
2018-11-15 20:44:44 +00:00
|
|
|
: CheckableTestModel(parent)
|
2018-06-25 21:04:32 +00:00
|
|
|
{
|
2018-11-15 20:44:44 +00:00
|
|
|
m_tests = {
|
|
|
|
{"W-Frage",
|
|
|
|
{"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans",
|
|
|
|
"Gans", "Gans", "Gans"}},
|
|
|
|
{"Verbtrennung", {"", "Affe", "", "", "", "", "", "Schwein", "", "", "Gans", ""}},
|
|
|
|
{"SVK: /-st/",
|
|
|
|
{"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans",
|
|
|
|
"Gans", "Gans", "Gans"}},
|
2018-06-25 21:04:32 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
unsigned int WFModel::getV2Points()
|
2018-06-25 21:04:32 +00:00
|
|
|
{
|
2018-11-15 20:44:44 +00:00
|
|
|
unsigned int points = 0;
|
2018-06-25 21:04:32 +00:00
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
for (auto testIndex : {0, 1})
|
2018-06-25 21:04:32 +00:00
|
|
|
{
|
|
|
|
const auto &test = m_tests.at(testIndex);
|
|
|
|
|
|
|
|
for (const auto &item : test.items())
|
|
|
|
{
|
|
|
|
if (item.isChecked())
|
|
|
|
{
|
|
|
|
points++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
unsigned int WFModel::getSvkPoints()
|
2018-06-25 21:04:32 +00:00
|
|
|
{
|
2018-11-15 20:44:44 +00:00
|
|
|
unsigned int points = 0;
|
2018-06-25 21:04:32 +00:00
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
for (auto testIndex : {2})
|
2018-06-25 21:04:32 +00:00
|
|
|
{
|
|
|
|
const auto &test = m_tests.at(testIndex);
|
|
|
|
|
|
|
|
for (const auto &item : test.items())
|
|
|
|
{
|
|
|
|
if (item.isChecked())
|
|
|
|
{
|
|
|
|
points++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
2018-11-13 23:17:29 +00:00
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
bool WFModel::isValidIndex(const QModelIndex &index) const
|
2018-11-17 00:19:03 +00:00
|
|
|
{
|
2019-01-31 19:14:38 +00:00
|
|
|
if (index.row() == 1)
|
2018-11-17 00:19:03 +00:00
|
|
|
{
|
2019-01-31 19:14:38 +00:00
|
|
|
return index.column() == 1 || index.column() == 7 || index.column() == 10;
|
2018-11-17 00:19:03 +00:00
|
|
|
}
|
2019-01-31 19:14:38 +00:00
|
|
|
|
|
|
|
return CheckableTestModel::isValidIndex(index);
|
2018-11-17 00:19:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
void WFModel::write(ESGRAF48::V2SvkModel &model) const
|
2018-11-13 23:17:29 +00:00
|
|
|
{
|
2018-11-15 20:44:44 +00:00
|
|
|
auto writeOneVal = [&](ESGRAF48::V2SvkModel::OneEach *modelData, int testIndex) {
|
|
|
|
if (modelData != nullptr)
|
|
|
|
{
|
|
|
|
const auto &testItems = m_tests.at(testIndex).items();
|
2018-11-13 23:17:29 +00:00
|
|
|
|
2018-11-15 20:44:44 +00:00
|
|
|
modelData->set_affe(testItems[1].isChecked());
|
|
|
|
modelData->set_schwein(testItems[7].isChecked());
|
|
|
|
modelData->set_gans(testItems[10].isChecked());
|
|
|
|
}
|
|
|
|
};
|
2018-11-13 23:17:29 +00:00
|
|
|
|
2018-11-15 20:44:44 +00:00
|
|
|
auto writeFourVals = [&](ESGRAF48::V2SvkModel::FourEach *modelData, int testIndex) {
|
|
|
|
if (modelData != nullptr)
|
|
|
|
{
|
|
|
|
const auto &testItems = m_tests.at(testIndex).items();
|
|
|
|
|
|
|
|
modelData->set_affe1(testItems[0].isChecked());
|
|
|
|
modelData->set_affe2(testItems[1].isChecked());
|
|
|
|
modelData->set_affe3(testItems[2].isChecked());
|
|
|
|
modelData->set_affe4(testItems[3].isChecked());
|
|
|
|
modelData->set_schwein1(testItems[4].isChecked());
|
|
|
|
modelData->set_schwein2(testItems[5].isChecked());
|
|
|
|
modelData->set_schwein3(testItems[6].isChecked());
|
|
|
|
modelData->set_schwein4(testItems[7].isChecked());
|
|
|
|
modelData->set_gans1(testItems[8].isChecked());
|
|
|
|
modelData->set_gans2(testItems[9].isChecked());
|
|
|
|
modelData->set_gans3(testItems[10].isChecked());
|
|
|
|
modelData->set_gans4(testItems[11].isChecked());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
writeFourVals(model.mutable_wfrage(), 0);
|
|
|
|
writeOneVal(model.mutable_verbtrennung1(), 1);
|
2018-11-13 23:17:29 +00:00
|
|
|
}
|
2018-11-15 20:44:44 +00:00
|
|
|
|
2019-01-31 19:14:38 +00:00
|
|
|
void WFModel::read(const ESGRAF48::V2SvkModel &model)
|
2018-11-13 23:17:29 +00:00
|
|
|
{
|
2018-11-15 20:44:44 +00:00
|
|
|
auto readOneVal = [&](const ESGRAF48::V2SvkModel::OneEach &modelData, int testIndex) {
|
|
|
|
auto &testItems = m_tests.at(testIndex).items();
|
2018-11-13 23:17:29 +00:00
|
|
|
|
2018-11-15 20:44:44 +00:00
|
|
|
testItems[1].setState(modelData.affe());
|
|
|
|
testItems[7].setState(modelData.schwein());
|
|
|
|
testItems[10].setState(modelData.gans());
|
|
|
|
};
|
2018-11-13 23:17:29 +00:00
|
|
|
|
2018-11-15 20:44:44 +00:00
|
|
|
auto readFourVals = [&](const ESGRAF48::V2SvkModel::FourEach &modelData, int testIndex) {
|
|
|
|
auto &testItems = m_tests.at(testIndex).items();
|
|
|
|
|
|
|
|
testItems[0].setState(modelData.affe1());
|
|
|
|
testItems[1].setState(modelData.affe2());
|
|
|
|
testItems[2].setState(modelData.affe3());
|
|
|
|
testItems[3].setState(modelData.affe4());
|
|
|
|
testItems[4].setState(modelData.schwein1());
|
|
|
|
testItems[5].setState(modelData.schwein2());
|
|
|
|
testItems[6].setState(modelData.schwein3());
|
|
|
|
testItems[7].setState(modelData.schwein4());
|
|
|
|
testItems[8].setState(modelData.gans1());
|
|
|
|
testItems[9].setState(modelData.gans2());
|
|
|
|
testItems[10].setState(modelData.gans3());
|
|
|
|
testItems[11].setState(modelData.gans4());
|
|
|
|
};
|
|
|
|
|
|
|
|
readFourVals(model.wfrage(), 0);
|
|
|
|
readOneVal(model.verbtrennung1(), 1);
|
2018-11-13 23:17:29 +00:00
|
|
|
|
|
|
|
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
|
|
|
}
|