From f6b283b3a156483477dce73fcdc48a4b1f888193 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 18 Nov 2018 21:29:43 +0100 Subject: [PATCH] Ported late skills to protobuf, added changed-messages --- proto/DataModel.proto | 4 + proto/LateSkillsGenitivModel.proto | 33 +++++++ proto/LateSkillsPassivModel.proto | 17 ++++ source/CMakeLists.txt | 2 + source/DataModel.cpp | 4 + .../AkkusativDativ/AkkusativModel.cpp | 2 + source/SubTests/AkkusativDativ/DativModel.cpp | 2 + source/SubTests/Genus/GenusModel.cpp | 2 + source/SubTests/LateSkills/CMakeLists.txt | 30 ++++-- source/SubTests/LateSkills/GenitivModel.cpp | 96 +++++++++++++++---- source/SubTests/LateSkills/GenitivModel.h | 4 + source/SubTests/LateSkills/PassivModel.cpp | 56 ++++++++--- source/SubTests/LateSkills/PassivModel.h | 4 + source/SubTests/Plural/PluralModel.cpp | 2 + 14 files changed, 222 insertions(+), 36 deletions(-) create mode 100644 proto/LateSkillsGenitivModel.proto create mode 100644 proto/LateSkillsPassivModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto index d6e6e17..d0f53a3 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -9,6 +9,8 @@ import "GenusModel.proto"; import "AkkusativModel.proto"; import "DativModel.proto"; import "PluralModel.proto"; +import "LateSkillsGenitivModel.proto"; +import "LateSkillsPassivModel.proto"; message DataModel { @@ -19,4 +21,6 @@ message DataModel AkkusativModel Akkusativ = 5; DativModel Dativ = 6; PluralModel Plural = 7; + LateSkillsGenitivModel LateSkillsGenitiv = 8; + LateSkillsPassivModel LateSkillsPassiv = 9; } diff --git a/proto/LateSkillsGenitivModel.proto b/proto/LateSkillsGenitivModel.proto new file mode 100644 index 0000000..b672ed6 --- /dev/null +++ b/proto/LateSkillsGenitivModel.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; + +package ESGRAF48; + +message LateSkillsGenitivModel +{ + message PraepositionenModel + { + bool anstelle1 = 1; + bool anstelle2 = 2; + bool ausserhalb1 = 3; + bool ausserhalb2 = 4; + bool mithilfe1 = 5; + bool mithilfe2 = 6; + } + + message AttributierungModel + { + bool Schuhe1 = 1; + bool Schuhe2 = 2; + bool Zauberstab1 = 3; + bool Zauberstab2 = 4; + bool Hut1 = 5; + bool Hut2 = 6; + bool Brille1 = 7; + bool Brille2 = 8; + bool Guertel1 = 9; + bool Guertel2 = 10; + } + + PraepositionenModel Praepositionen = 1; + AttributierungModel Attributierung = 2; +} diff --git a/proto/LateSkillsPassivModel.proto b/proto/LateSkillsPassivModel.proto new file mode 100644 index 0000000..b4244fb --- /dev/null +++ b/proto/LateSkillsPassivModel.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package ESGRAF48; + +message LateSkillsPassivModel +{ + bool Elefant1 = 1; + bool Elefant2 = 2; + bool Pferde1 = 3; + bool Pferde2 = 4; + bool Baelle1 = 5; + bool Baelle2 = 6; + bool Ball1 = 7; + bool Ball2 = 8; + bool Fleisch1 = 9; + bool Fleisch2 = 10; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 85e1c57..ab95560 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -26,6 +26,8 @@ set(DataModel_PROTO_FILES ../proto/AkkusativModel.proto ../proto/DativModel.proto ../proto/PluralModel.proto + ../proto/LateSkillsPassivModel.proto + ../proto/LateSkillsGenitivModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index e33b1c1..d979a39 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -38,6 +38,8 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_akkusativ.write(*dataModel.mutable_akkusativ()); m_dativ.write(*dataModel.mutable_dativ()); m_plural.write(*dataModel.mutable_plural()); + m_genitiv.write(*dataModel.mutable_lateskillsgenitiv()); + m_passiv.write(*dataModel.mutable_lateskillspassiv()); dataModel.SerializeToOstream(&outStream); } @@ -54,6 +56,8 @@ void DataModel::readProtoBuf(std::istream &inStream) m_akkusativ.read(dataModel.akkusativ()); m_dativ.read(dataModel.dativ()); m_plural.read(dataModel.plural()); + m_genitiv.read(dataModel.lateskillsgenitiv()); + m_passiv.read(dataModel.lateskillspassiv()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.cpp b/source/SubTests/AkkusativDativ/AkkusativModel.cpp index 68d8f04..79d2c31 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.cpp +++ b/source/SubTests/AkkusativDativ/AkkusativModel.cpp @@ -54,6 +54,8 @@ void AkkusativModel::read(const ESGRAF48::AkkusativModel &model) testItems[6].setState(futterModel.honig()); testItems[7].setState(futterModel.zucker()); } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const diff --git a/source/SubTests/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index c295348..081dfdb 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -54,6 +54,8 @@ void DativModel::read(const ESGRAF48::DativModel &model) testItems[6].setState(futterModel.honig()); testItems[7].setState(futterModel.zucker()); } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void DativModel::write(ESGRAF48::DativModel &model) const diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index 0977ce9..24e5c36 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -48,6 +48,8 @@ void GenusModel::readProtoBuf(const ESGRAF48::GenusModel &model) testItems[2].setState(zirkusModel.vorhang()); testItems[3].setState(zirkusModel.baum()); } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void GenusModel::writeProtoBuf(ESGRAF48::GenusModel &model) const diff --git a/source/SubTests/LateSkills/CMakeLists.txt b/source/SubTests/LateSkills/CMakeLists.txt index a570f42..7fef071 100644 --- a/source/SubTests/LateSkills/CMakeLists.txt +++ b/source/SubTests/LateSkills/CMakeLists.txt @@ -3,18 +3,30 @@ cmake_minimum_required(VERSION 3.6) project(LateSkills LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) qt5_wrap_ui(UI_HEADERS - LateSkillsWidget.ui + LateSkillsWidget.ui +) + +set(LateSkills_PROTO_FILES + ../../../proto/LateSkillsGenitivModel.proto + ../../../proto/LateSkillsPassivModel.proto +) + +protobuf_generate_cpp(LateSkills_PROTO_SRCS LateSkills_PROTO_HDRS + ${LateSkills_PROTO_FILES} ) add_library(${PROJECT_NAME} - LateSkillsWidget.cpp + LateSkillsWidget.cpp PassivModel.cpp GenitivModel.cpp ${UI_HEADERS} + ${LateSkills_PROTO_SRCS} + ${LateSkills_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -23,15 +35,17 @@ set_target_properties(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} ) target_link_libraries(${PROJECT_NAME} PRIVATE - CheckableItem - CheckableTest - CheckableTestModel - Qt5::Widgets + CheckableItem + CheckableTest + CheckableTestModel + Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/LateSkills/GenitivModel.cpp b/source/SubTests/LateSkills/GenitivModel.cpp index af69325..9ebf423 100644 --- a/source/SubTests/LateSkills/GenitivModel.cpp +++ b/source/SubTests/LateSkills/GenitivModel.cpp @@ -1,45 +1,109 @@ #include "GenitivModel.h" GenitivModel::GenitivModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { m_tests = { - { "Genitiv Präpositionen", - { "anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", - "mithilfe (1)", "mithilfe (2)" } }, - { "Attributierung", - { "Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", - "Hut (1)", "Hut (2)", "Brille (1)", "Brille (2)", "Gürtel (1)", - "Gürtel (2)" } }, + {"Genitiv Präpositionen", + {"anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", "mithilfe (1)", + "mithilfe (2)"}}, + {"Attributierung", + {"Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", "Hut (1)", "Hut (2)", + "Brille (1)", "Brille (2)", "Gürtel (1)", "Gürtel (2)"}}, }; - for (auto index : { 1, 3, 5 }) + for (auto index : {1, 3, 5}) { m_tests[0].items()[index].setValue(2); } - for (auto index : { 1, 3, 5, 7, 9 }) + for (auto index : {1, 3, 5, 7, 9}) { m_tests[1].items()[index].setValue(2); } } -bool GenitivModel::setData( - const QModelIndex &modelIndex, const QVariant &value, int role) +bool GenitivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role) { if (role == Qt::CheckStateRole && value.toBool() == true) { if (modelIndex.column() % 2 == 0) { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() + 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false, + role); } else { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() - 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false, + role); } } return CheckableTestModel::setData(modelIndex, value, role); } + +void GenitivModel::read(const ESGRAF48::LateSkillsGenitivModel &model) +{ + const auto &praepositionenModel = model.praepositionen(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(praepositionenModel.anstelle1()); + testItems[1].setState(praepositionenModel.anstelle2()); + testItems[2].setState(praepositionenModel.ausserhalb1()); + testItems[3].setState(praepositionenModel.ausserhalb2()); + testItems[4].setState(praepositionenModel.mithilfe1()); + testItems[5].setState(praepositionenModel.mithilfe2()); + } + + const auto &attributierungModel = model.attributierung(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[0].setState(attributierungModel.schuhe1()); + testItems[1].setState(attributierungModel.schuhe2()); + testItems[2].setState(attributierungModel.zauberstab1()); + testItems[3].setState(attributierungModel.zauberstab2()); + testItems[4].setState(attributierungModel.hut1()); + testItems[5].setState(attributierungModel.hut2()); + testItems[6].setState(attributierungModel.brille1()); + testItems[7].setState(attributierungModel.brille2()); + testItems[8].setState(attributierungModel.guertel1()); + testItems[9].setState(attributierungModel.guertel2()); + } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} + +void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel &model) const +{ + auto *praepositionenModel = model.mutable_praepositionen(); + if (praepositionenModel != nullptr) + { + const auto &testItems = m_tests.at(0).items(); + + praepositionenModel->set_anstelle1(testItems[0].isChecked()); + praepositionenModel->set_anstelle2(testItems[1].isChecked()); + praepositionenModel->set_ausserhalb1(testItems[2].isChecked()); + praepositionenModel->set_ausserhalb2(testItems[3].isChecked()); + praepositionenModel->set_mithilfe1(testItems[4].isChecked()); + praepositionenModel->set_mithilfe2(testItems[5].isChecked()); + } + + auto *attributierungModel = model.mutable_attributierung(); + if (attributierungModel != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + attributierungModel->set_schuhe1(testItems[0].isChecked()); + attributierungModel->set_schuhe2(testItems[1].isChecked()); + attributierungModel->set_zauberstab1(testItems[2].isChecked()); + attributierungModel->set_zauberstab2(testItems[3].isChecked()); + attributierungModel->set_hut1(testItems[4].isChecked()); + attributierungModel->set_hut2(testItems[5].isChecked()); + attributierungModel->set_brille1(testItems[6].isChecked()); + attributierungModel->set_brille2(testItems[7].isChecked()); + attributierungModel->set_guertel1(testItems[8].isChecked()); + attributierungModel->set_guertel2(testItems[9].isChecked()); + } +} diff --git a/source/SubTests/LateSkills/GenitivModel.h b/source/SubTests/LateSkills/GenitivModel.h index 4f6687a..2346e94 100644 --- a/source/SubTests/LateSkills/GenitivModel.h +++ b/source/SubTests/LateSkills/GenitivModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "LateSkillsGenitivModel.pb.h" class GenitivModel : public CheckableTestModel { @@ -10,4 +11,7 @@ public: GenitivModel(QObject *parent); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + + void read(const ESGRAF48::LateSkillsGenitivModel &model); + void write(ESGRAF48::LateSkillsGenitivModel &model) const; }; diff --git a/source/SubTests/LateSkills/PassivModel.cpp b/source/SubTests/LateSkills/PassivModel.cpp index 2f82c2e..6f1d3a8 100644 --- a/source/SubTests/LateSkills/PassivModel.cpp +++ b/source/SubTests/LateSkills/PassivModel.cpp @@ -1,35 +1,67 @@ #include "PassivModel.h" PassivModel::PassivModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { { "Passiv", - { "Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", - "Bälle (2)", "Ball (1)", "Ball (2)", "Fleisch (1)", - "Fleisch (2)" } } }; + m_tests = {{"Passiv", + {"Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", "Bälle (2)", + "Ball (1)", "Ball (2)", "Fleisch (1)", "Fleisch (2)"}}}; - for (auto index : { 1, 3, 5, 7, 9 }) + for (auto index : {1, 3, 5, 7, 9}) { m_tests[0].items()[index].setValue(2); } } -bool PassivModel::setData( - const QModelIndex &modelIndex, const QVariant &value, int role) +bool PassivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role) { if (role == Qt::CheckStateRole && value.toBool() == true) { if (modelIndex.column() % 2 == 0) { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() + 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false, + role); } else { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() - 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false, + role); } } return CheckableTestModel::setData(modelIndex, value, role); } + +void PassivModel::read(const ESGRAF48::LateSkillsPassivModel &model) +{ + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(model.elefant1()); + testItems[1].setState(model.elefant2()); + testItems[2].setState(model.pferde1()); + testItems[3].setState(model.pferde2()); + testItems[4].setState(model.baelle1()); + testItems[5].setState(model.baelle2()); + testItems[6].setState(model.ball1()); + testItems[7].setState(model.ball2()); + testItems[8].setState(model.fleisch1()); + testItems[9].setState(model.fleisch2()); + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} + +void PassivModel::write(ESGRAF48::LateSkillsPassivModel &model) const +{ + const auto &testItems = m_tests.at(0).items(); + + model.set_elefant1(testItems[0].isChecked()); + model.set_elefant2(testItems[1].isChecked()); + model.set_pferde1(testItems[2].isChecked()); + model.set_pferde2(testItems[3].isChecked()); + model.set_baelle1(testItems[4].isChecked()); + model.set_baelle2(testItems[5].isChecked()); + model.set_ball1(testItems[6].isChecked()); + model.set_ball2(testItems[7].isChecked()); + model.set_fleisch1(testItems[8].isChecked()); + model.set_fleisch2(testItems[9].isChecked()); +} diff --git a/source/SubTests/LateSkills/PassivModel.h b/source/SubTests/LateSkills/PassivModel.h index 159ccba..e0671bb 100644 --- a/source/SubTests/LateSkills/PassivModel.h +++ b/source/SubTests/LateSkills/PassivModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "LateSkillsPassivModel.pb.h" class PassivModel : public CheckableTestModel { @@ -10,4 +11,7 @@ public: PassivModel(QObject *parent); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + + void read(const ESGRAF48::LateSkillsPassivModel &model); + void write(ESGRAF48::LateSkillsPassivModel &model) const; }; diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index a1a208e..0ade859 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -33,6 +33,8 @@ void PluralModel::read(const ESGRAF48::PluralModel &model) testItems[6].setState(model.nuss()); testItems[7].setState(model.baer()); testItems[8].setState(model.apfel()); + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void PluralModel::write(ESGRAF48::PluralModel &model) const