From a09e9a53514dba640728ead4547c10374798bc22 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 30 Jan 2019 23:07:11 +0100 Subject: [PATCH] Split subtest 1 into four widgets, extracted TPeModel --- source/DataModel.cpp | 8 ++- source/DataModel.h | 4 ++ source/SubTests/V2Svk/CMakeLists.txt | 1 + source/SubTests/V2Svk/TPeModel.cpp | 95 +++++++++++++++++++++++++++ source/SubTests/V2Svk/TPeModel.h | 18 +++++ source/SubTests/V2Svk/V2SvkModel.cpp | 21 +----- source/SubTests/V2Svk/V2SvkWidget.cpp | 11 +++- source/SubTests/V2Svk/V2SvkWidget.h | 2 + source/SubTests/V2Svk/V2SvkWidget.ui | 11 +++- source/mainwindow.cpp | 1 + 10 files changed, 148 insertions(+), 24 deletions(-) create mode 100644 source/SubTests/V2Svk/TPeModel.cpp create mode 100644 source/SubTests/V2Svk/TPeModel.h diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 0b94963..6f4dee1 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -15,6 +15,7 @@ DataModel::DataModel(QObject *parent) , m_akkusativ(this) , m_dativ(this) , m_v2Svk(this) + , m_tPeModel(this) , m_passiv(this) , m_genitiv(this) { @@ -25,6 +26,7 @@ DataModel::DataModel(QObject *parent) connect(&m_akkusativ, &AkkusativModel::dataChanged, this, &DataModel::akkusativModelChanged); connect(&m_dativ, &DativModel::dataChanged, this, &DataModel::dativModelChanged); connect(&m_v2Svk, &V2SvkModel::dataChanged, this, &DataModel::v2SvkModelChanged); + connect(&m_tPeModel, &TPeModel::dataChanged, this, &DataModel::v2SvkModelChanged); connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged); connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); } @@ -35,6 +37,7 @@ void DataModel::write(const QString &filename) const m_metaData.write(*dataModel.mutable_metadata()); m_v2Svk.write(*dataModel.mutable_v2svk()); + m_tPeModel.write(*dataModel.mutable_v2svk()); m_verbEnd.write(*dataModel.mutable_verbend()); m_genus.write(*dataModel.mutable_genus()); m_akkusativ.write(*dataModel.mutable_akkusativ()); @@ -73,6 +76,7 @@ void DataModel::read(const QString &filename) m_metaData.read(dataModel.metadata()); m_v2Svk.read(dataModel.v2svk()); + m_tPeModel.read(dataModel.v2svk()); m_verbEnd.read(dataModel.verbend()); m_genus.read(dataModel.genus()); m_akkusativ.read(dataModel.akkusativ()); @@ -149,8 +153,8 @@ void DataModel::dativModelChanged() void DataModel::v2SvkModelChanged() { - m_results.setV2Result(m_v2Svk.getV2Points()); - m_results.setSvkResult(m_v2Svk.getSvkPoints()); + m_results.setV2Result(m_v2Svk.getV2Points() + m_tPeModel.getV2Points()); + m_results.setSvkResult(m_v2Svk.getSvkPoints() + m_tPeModel.getSvkPoints()); emit modelChanged(); } diff --git a/source/DataModel.h b/source/DataModel.h index 42b5294..61037a3 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -7,6 +7,7 @@ #include "AkkusativModel.h" #include "DativModel.h" #include "V2SvkModel.h" +#include "TPeModel.h" #include "PassivModel.h" #include "GenitivModel.h" @@ -25,7 +26,10 @@ public: PluralModel m_plural; AkkusativModel m_akkusativ; DativModel m_dativ; + V2SvkModel m_v2Svk; + TPeModel m_tPeModel; + PassivModel m_passiv; GenitivModel m_genitiv; diff --git a/source/SubTests/V2Svk/CMakeLists.txt b/source/SubTests/V2Svk/CMakeLists.txt index caf6c8c..0269a26 100644 --- a/source/SubTests/V2Svk/CMakeLists.txt +++ b/source/SubTests/V2Svk/CMakeLists.txt @@ -20,6 +20,7 @@ protobuf_generate_cpp(V2Svk_PROTO_SRCS V2Svk_PROTO_HDRS ${V2Svk_PROTO_FILES}) add_library(${PROJECT_NAME} V2SvkWidget.cpp V2SvkModel.cpp + TPeModel.cpp ${UI_HEADERS} ${V2Svk_PROTO_SRCS} ${V2Svk_PROTO_HDRS} diff --git a/source/SubTests/V2Svk/TPeModel.cpp b/source/SubTests/V2Svk/TPeModel.cpp new file mode 100644 index 0000000..2c17da3 --- /dev/null +++ b/source/SubTests/V2Svk/TPeModel.cpp @@ -0,0 +1,95 @@ +#include "TPeModel.h" + +TPeModel::TPeModel(QObject *parent) + : CheckableTestModel(parent) +{ + m_tests = { + {"Temporaladverb Perfekt", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + {"Verbtrennung", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + {"SVK: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + {"Partizip", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + }; +} + +unsigned int TPeModel::getV2Points() +{ + unsigned int points = 0; + + for (auto testIndex : {0, 1}) + { + const auto &test = m_tests.at(testIndex); + + for (const auto &item : test.items()) + { + if (item.isChecked()) + { + points++; + } + } + } + + return points; +} + +unsigned int TPeModel::getSvkPoints() +{ + unsigned int points = 0; + + for (auto testIndex : {2, 3}) + { + const auto &test = m_tests.at(testIndex); + + for (const auto &item : test.items()) + { + if (item.isChecked()) + { + points++; + } + } + } + + return points; +} + +void TPeModel::write(ESGRAF48::V2SvkModel &model) const +{ + auto writeTwoVals = [&](ESGRAF48::V2SvkModel::TwoEach *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_schwein1(testItems[2].isChecked()); + modelData->set_schwein2(testItems[3].isChecked()); + modelData->set_gans1(testItems[4].isChecked()); + modelData->set_gans2(testItems[5].isChecked()); + } + }; + + writeTwoVals(model.mutable_tempperf(), 0); + writeTwoVals(model.mutable_verbtrennung2(), 1); + writeTwoVals(model.mutable_svke2(), 2); + writeTwoVals(model.mutable_partizip(), 3); +} + +void TPeModel::read(const ESGRAF48::V2SvkModel &model) +{ + auto readTwoVals = [&](const ESGRAF48::V2SvkModel::TwoEach &modelData, int testIndex) { + auto &testItems = m_tests.at(testIndex).items(); + + testItems[0].setState(modelData.affe1()); + testItems[1].setState(modelData.affe2()); + testItems[2].setState(modelData.schwein1()); + testItems[3].setState(modelData.schwein2()); + testItems[4].setState(modelData.gans1()); + testItems[5].setState(modelData.gans2()); + }; + + readTwoVals(model.tempperf(), 0); + readTwoVals(model.verbtrennung2(), 1); + readTwoVals(model.svke2(), 2); + readTwoVals(model.partizip(), 3); + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} diff --git a/source/SubTests/V2Svk/TPeModel.h b/source/SubTests/V2Svk/TPeModel.h new file mode 100644 index 0000000..19a1c12 --- /dev/null +++ b/source/SubTests/V2Svk/TPeModel.h @@ -0,0 +1,18 @@ +#pragma once + +#include "CheckableTestModel.h" +#include "V2SvkModel.pb.h" + +class TPeModel : public CheckableTestModel +{ + Q_OBJECT + +public: + TPeModel(QObject *parent); + + unsigned int getV2Points(); + unsigned int getSvkPoints(); + + void write(ESGRAF48::V2SvkModel &model) const; + void read(const ESGRAF48::V2SvkModel &model); +}; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 2196ba4..716f1d4 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -21,11 +21,6 @@ V2SvkModel::V2SvkModel(QObject *parent) {"Temporaladverb Präsens", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, {"SKV: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, - - {"Temporaladverb Perfekt", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, - {"Verbtrennung", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, - {"SVK: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, - {"Partizip", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, }; } @@ -33,7 +28,7 @@ unsigned int V2SvkModel::getV2Points() { unsigned int points = 0; - for (auto testIndex : {0, 1, 3, 5, 7, 8}) + for (auto testIndex : {0, 1, 3, 5}) { const auto &test = m_tests.at(testIndex); @@ -53,7 +48,7 @@ unsigned int V2SvkModel::getSvkPoints() { unsigned int points = 0; - for (auto testIndex : {2, 4, 6, 9, 10}) + for (auto testIndex : {2, 4, 6}) { const auto &test = m_tests.at(testIndex); @@ -77,10 +72,6 @@ bool V2SvkModel::isValidIndex(const QModelIndex &index) const return index.column() == 1 || index.column() == 7 || index.column() == 10; case 5: case 6: - case 7: - case 8: - case 9: - case 10: return index.column() < 6; default: return CheckableTestModel::isValidIndex(index); @@ -141,10 +132,6 @@ void V2SvkModel::write(ESGRAF48::V2SvkModel &model) const writeFourVals(model.mutable_svkstamm(), 4); writeTwoVals(model.mutable_temppraes(), 5); writeTwoVals(model.mutable_svke1(), 6); - writeTwoVals(model.mutable_tempperf(), 7); - writeTwoVals(model.mutable_verbtrennung2(), 8); - writeTwoVals(model.mutable_svke2(), 9); - writeTwoVals(model.mutable_partizip(), 10); } void V2SvkModel::read(const ESGRAF48::V2SvkModel &model) @@ -192,10 +179,6 @@ void V2SvkModel::read(const ESGRAF48::V2SvkModel &model) readFourVals(model.svkstamm(), 4); readTwoVals(model.temppraes(), 5); readTwoVals(model.svke1(), 6); - readTwoVals(model.tempperf(), 7); - readTwoVals(model.verbtrennung2(), 8); - readTwoVals(model.svke2(), 9); - readTwoVals(model.partizip(), 10); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } diff --git a/source/SubTests/V2Svk/V2SvkWidget.cpp b/source/SubTests/V2Svk/V2SvkWidget.cpp index d6fe544..10d79b4 100644 --- a/source/SubTests/V2Svk/V2SvkWidget.cpp +++ b/source/SubTests/V2Svk/V2SvkWidget.cpp @@ -2,13 +2,15 @@ #include "ui_V2SvkWidget.h" #include "V2SvkModel.h" +#include "TPeModel.h" V2SvkWidget::V2SvkWidget(QWidget *parent) : QWidget(parent) , ui(new Ui::V2SvkWidget) { ui->setupUi(this); - ui->v2SvkTableView->horizontalHeader()->hide(); + ui->wfTableView->horizontalHeader()->hide(); + ui->tpeTableView->horizontalHeader()->hide(); } V2SvkWidget::~V2SvkWidget() @@ -18,5 +20,10 @@ V2SvkWidget::~V2SvkWidget() void V2SvkWidget::setV2SvkModel(V2SvkModel *model) { - ui->v2SvkTableView->setModel(model); + ui->wfTableView->setModel(model); +} + +void V2SvkWidget::setTPeModel(TPeModel *model) +{ + ui->tpeTableView->setModel(model); } diff --git a/source/SubTests/V2Svk/V2SvkWidget.h b/source/SubTests/V2Svk/V2SvkWidget.h index e23cac5..6256e77 100644 --- a/source/SubTests/V2Svk/V2SvkWidget.h +++ b/source/SubTests/V2Svk/V2SvkWidget.h @@ -3,6 +3,7 @@ #include class V2SvkModel; +class TPeModel; namespace Ui { class V2SvkWidget; @@ -20,4 +21,5 @@ public: ~V2SvkWidget(); void setV2SvkModel(V2SvkModel *model); + void setTPeModel(TPeModel *model); }; diff --git a/source/SubTests/V2Svk/V2SvkWidget.ui b/source/SubTests/V2Svk/V2SvkWidget.ui index 73ee028..83a3b71 100644 --- a/source/SubTests/V2Svk/V2SvkWidget.ui +++ b/source/SubTests/V2Svk/V2SvkWidget.ui @@ -15,7 +15,16 @@ - + + + + + + + + + + diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index d5f425a..cadf73e 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -49,6 +49,7 @@ void MainWindow::setupUi() ui->akkusativDativWidget->setAkkusativModel(&m_dataModel.m_akkusativ); ui->akkusativDativWidget->setDativModel(&m_dataModel.m_dativ); ui->v2SvkWidget->setV2SvkModel(&m_dataModel.m_v2Svk); + ui->v2SvkWidget->setTPeModel(&m_dataModel.m_tPeModel); ui->lateSkillsWidget->setPassivModel(&m_dataModel.m_passiv); ui->lateSkillsWidget->setGenitivModel(&m_dataModel.m_genitiv); ui->resultWidget->setModel(&m_dataModel.m_results);