From 843164a3bf24804861582061e5ad88f4ee6fd89e Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 18 Nov 2018 17:12:03 +0100 Subject: [PATCH] Ported Akkusativ and Dativ model to protobuf --- proto/AkkusativModel.proto | 46 ++++++++ proto/DataModel.proto | 4 + proto/DativModel.proto | 46 ++++++++ source/CMakeLists.txt | 2 + source/DataModel.cpp | 4 + .../AkkusativDativ/AkkusativModel.cpp | 110 ++++++++++++++++-- .../SubTests/AkkusativDativ/AkkusativModel.h | 4 + source/SubTests/AkkusativDativ/CMakeLists.txt | 14 +++ source/SubTests/AkkusativDativ/DativModel.cpp | 110 ++++++++++++++++-- source/SubTests/AkkusativDativ/DativModel.h | 4 + source/SubTests/Genus/CMakeLists.txt | 1 - 11 files changed, 324 insertions(+), 21 deletions(-) create mode 100644 proto/AkkusativModel.proto create mode 100644 proto/DativModel.proto diff --git a/proto/AkkusativModel.proto b/proto/AkkusativModel.proto new file mode 100644 index 0000000..930160d --- /dev/null +++ b/proto/AkkusativModel.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; + +package ESGRAF48; + +message AkkusativModel +{ + message TiereModel + { + bool Tiger = 1; + bool Katze = 2; + bool Affe = 3; + bool Gans = 4; + bool Baer = 5; + bool Pferd = 6; + bool Hund = 7; + bool Elefant = 8; + } + + message VersteckeModel + { + bool Vorhang1 = 1; + bool Kiste1 = 2; + bool Holz1 = 3; + bool Kiste2 = 4; + bool Baum1 = 5; + bool Vorhang2 = 6; + bool Holz2 = 7; + bool Baum2 = 8; + } + + message FutterModel + { + bool Salat = 1; + bool Fleisch = 2; + bool Knochen = 3; + bool Banane = 4; + bool Apfel = 5; + bool Karotte = 6; + bool Honig = 7; + bool Zucker = 8; + } + + TiereModel Tiere = 1; + VersteckeModel Verstecke = 2; + FutterModel Futter = 3; +} diff --git a/proto/DataModel.proto b/proto/DataModel.proto index c5df198..c04f473 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -6,6 +6,8 @@ import "MetaDataModel.proto"; import "V2SvkModel.proto"; import "VerbEndModel.proto"; import "GenusModel.proto"; +import "AkkusativModel.proto"; +import "DativModel.proto"; message DataModel { @@ -13,4 +15,6 @@ message DataModel V2SvkModel V2Svk = 2; VerbEndModel VerbEnd = 3; GenusModel Genus = 4; + AkkusativModel Akkusativ = 5; + DativModel Dativ = 6; } diff --git a/proto/DativModel.proto b/proto/DativModel.proto new file mode 100644 index 0000000..b3bb021 --- /dev/null +++ b/proto/DativModel.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; + +package ESGRAF48; + +message DativModel +{ + message TiereModel + { + bool Tiger = 1; + bool Katze = 2; + bool Affe = 3; + bool Gans = 4; + bool Baer = 5; + bool Pferd = 6; + bool Hund = 7; + bool Elefant = 8; + } + + message VersteckeModel + { + bool Vorhang1 = 1; + bool Kiste1 = 2; + bool Holz1 = 3; + bool Kiste2 = 4; + bool Baum1 = 5; + bool Vorhang2 = 6; + bool Holz2 = 7; + bool Baum2 = 8; + } + + message FutterModel + { + bool Salat = 1; + bool Fleisch = 2; + bool Knochen = 3; + bool Banane = 4; + bool Apfel = 5; + bool Karotte = 6; + bool Honig = 7; + bool Zucker = 8; + } + + TiereModel Tiere = 1; + VersteckeModel Verstecke = 2; + FutterModel Futter = 3; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 33df521..6180070 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -23,6 +23,8 @@ set(DataModel_PROTO_FILES ../proto/V2SvkModel.proto ../proto/VerbEndModel.proto ../proto/GenusModel.proto + ../proto/AkkusativModel.proto + ../proto/DativModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 7c346e4..08bf4bc 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -35,6 +35,8 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend()); m_genus.writeProtoBuf(*dataModel.mutable_genus()); + m_akkusativ.write(*dataModel.mutable_akkusativ()); + m_dativ.write(*dataModel.mutable_dativ()); dataModel.SerializeToOstream(&outStream); } @@ -48,6 +50,8 @@ void DataModel::readProtoBuf(std::istream &inStream) m_v2Svk.readProtoBuf(dataModel.v2svk()); m_verbEnd.readProtoBuf(dataModel.verbend()); m_genus.readProtoBuf(dataModel.genus()); + m_akkusativ.read(dataModel.akkusativ()); + m_dativ.read(dataModel.dativ()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.cpp b/source/SubTests/AkkusativDativ/AkkusativModel.cpp index dd387f1..68d8f04 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.cpp +++ b/source/SubTests/AkkusativDativ/AkkusativModel.cpp @@ -1,15 +1,105 @@ #include "AkkusativModel.h" AkkusativModel::AkkusativModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { - { "Akkusativ Nominalphrase", { "Tiger", "Katze", "Affe", "Gans", "Bär", - "Pferd", "Hund", "Elefant" } }, - { "Präpositionalphrase (Verstecke)", - { "Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", - "Baum" } }, - { "Nominalphrase (Futter)", { "Salat", "Fleisch", "Knochen", "Banane", - "Apfel", "Karotte", "Honig", "Zucker" } } - }; + m_tests = {{"Akkusativ Nominalphrase", + {"Tiger", "Katze", "Affe", "Gans", "Bär", "Pferd", "Hund", "Elefant"}}, + {"Präpositionalphrase (Verstecke)", + {"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}}, + {"Nominalphrase (Futter)", + {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}}; +} + +void AkkusativModel::read(const ESGRAF48::AkkusativModel &model) +{ + const auto &tiereModel = model.tiere(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(tiereModel.tiger()); + testItems[1].setState(tiereModel.katze()); + testItems[2].setState(tiereModel.affe()); + testItems[3].setState(tiereModel.gans()); + testItems[4].setState(tiereModel.baer()); + testItems[5].setState(tiereModel.pferd()); + testItems[6].setState(tiereModel.hund()); + testItems[7].setState(tiereModel.elefant()); + } + + const auto &versteckeModel = model.verstecke(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[0].setState(versteckeModel.vorhang1()); + testItems[1].setState(versteckeModel.kiste1()); + testItems[2].setState(versteckeModel.holz1()); + testItems[3].setState(versteckeModel.kiste2()); + testItems[4].setState(versteckeModel.baum1()); + testItems[5].setState(versteckeModel.vorhang2()); + testItems[6].setState(versteckeModel.holz2()); + testItems[7].setState(versteckeModel.baum2()); + } + + const auto &futterModel = model.futter(); + { + auto &testItems = m_tests.at(2).items(); + + testItems[0].setState(futterModel.salat()); + testItems[1].setState(futterModel.fleisch()); + testItems[2].setState(futterModel.knochen()); + testItems[3].setState(futterModel.banane()); + testItems[4].setState(futterModel.apfel()); + testItems[5].setState(futterModel.karotte()); + testItems[6].setState(futterModel.honig()); + testItems[7].setState(futterModel.zucker()); + } +} + +void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const +{ + auto *tiereModel = model.mutable_tiere(); + if (tiereModel != nullptr) + { + const auto &testItems = m_tests.at(0).items(); + + tiereModel->set_tiger(testItems[0].isChecked()); + tiereModel->set_katze(testItems[1].isChecked()); + tiereModel->set_affe(testItems[2].isChecked()); + tiereModel->set_gans(testItems[3].isChecked()); + tiereModel->set_baer(testItems[4].isChecked()); + tiereModel->set_pferd(testItems[5].isChecked()); + tiereModel->set_hund(testItems[6].isChecked()); + tiereModel->set_elefant(testItems[7].isChecked()); + } + + auto *versteckeModel = model.mutable_verstecke(); + if (versteckeModel != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + versteckeModel->set_vorhang1(testItems[0].isChecked()); + versteckeModel->set_kiste1(testItems[1].isChecked()); + versteckeModel->set_holz1(testItems[2].isChecked()); + versteckeModel->set_kiste2(testItems[3].isChecked()); + versteckeModel->set_baum1(testItems[4].isChecked()); + versteckeModel->set_vorhang2(testItems[5].isChecked()); + versteckeModel->set_holz2(testItems[6].isChecked()); + versteckeModel->set_baum2(testItems[7].isChecked()); + } + + auto *futterModel = model.mutable_futter(); + if (futterModel != nullptr) + { + const auto &testItems = m_tests.at(2).items(); + + futterModel->set_salat(testItems[0].isChecked()); + futterModel->set_fleisch(testItems[1].isChecked()); + futterModel->set_knochen(testItems[2].isChecked()); + futterModel->set_banane(testItems[3].isChecked()); + futterModel->set_apfel(testItems[4].isChecked()); + futterModel->set_karotte(testItems[5].isChecked()); + futterModel->set_honig(testItems[6].isChecked()); + futterModel->set_zucker(testItems[7].isChecked()); + } } diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.h b/source/SubTests/AkkusativDativ/AkkusativModel.h index 9ec74fd..43a4881 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.h +++ b/source/SubTests/AkkusativDativ/AkkusativModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "AkkusativModel.pb.h" class AkkusativModel : public CheckableTestModel { @@ -8,4 +9,7 @@ class AkkusativModel : public CheckableTestModel public: AkkusativModel(QObject *parent); + + void read(const ESGRAF48::AkkusativModel &model); + void write(ESGRAF48::AkkusativModel &model) const; }; diff --git a/source/SubTests/AkkusativDativ/CMakeLists.txt b/source/SubTests/AkkusativDativ/CMakeLists.txt index 05deb13..a543ee7 100644 --- a/source/SubTests/AkkusativDativ/CMakeLists.txt +++ b/source/SubTests/AkkusativDativ/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(AkkusativDativ LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,11 +11,22 @@ qt5_wrap_ui(UI_HEADERS AkkusativDativWidget.ui ) +set(AkkusativDativ_PROTO_FILES + ../../../proto/AkkusativModel.proto + ../../../proto/DativModel.proto +) + +protobuf_generate_cpp(AkkusativDativ_PROTO_SRCS AkkusativDativ_PROTO_HDRS + ${AkkusativDativ_PROTO_FILES} +) + add_library(${PROJECT_NAME} AkkusativDativWidget.cpp AkkusativModel.cpp DativModel.cpp ${UI_HEADERS} + ${AkkusativDativ_PROTO_SRCS} + ${AkkusativDativ_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -26,6 +38,7 @@ target_include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} ) target_link_libraries(${PROJECT_NAME} @@ -34,4 +47,5 @@ target_link_libraries(${PROJECT_NAME} CheckableTest CheckableTestModel Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index 8252cf6..c295348 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -1,15 +1,105 @@ #include "DativModel.h" DativModel::DativModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { - { "Dativ Nominalphrase", { "Tiger", "Katze", "Affe", "Gans", "Bär", - "Pferd", "Hund", "Elefant" } }, - { "Präpositionalphrase (Verstecke)", - { "Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", - "Baum" } }, - { "Nominalphrase (Tiere)", { "Salat", "Fleisch", "Knochen", "Banane", - "Apfel", "Karotte", "Honig", "Zucker" } } - }; + m_tests = {{"Dativ Nominalphrase", + {"Tiger", "Katze", "Affe", "Gans", "Bär", "Pferd", "Hund", "Elefant"}}, + {"Präpositionalphrase (Verstecke)", + {"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}}, + {"Nominalphrase (Tiere)", + {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}}; +} + +void DativModel::read(const ESGRAF48::DativModel &model) +{ + const auto &tiereModel = model.tiere(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(tiereModel.tiger()); + testItems[1].setState(tiereModel.katze()); + testItems[2].setState(tiereModel.affe()); + testItems[3].setState(tiereModel.gans()); + testItems[4].setState(tiereModel.baer()); + testItems[5].setState(tiereModel.pferd()); + testItems[6].setState(tiereModel.hund()); + testItems[7].setState(tiereModel.elefant()); + } + + const auto &versteckeModel = model.verstecke(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[0].setState(versteckeModel.vorhang1()); + testItems[1].setState(versteckeModel.kiste1()); + testItems[2].setState(versteckeModel.holz1()); + testItems[3].setState(versteckeModel.kiste2()); + testItems[4].setState(versteckeModel.baum1()); + testItems[5].setState(versteckeModel.vorhang2()); + testItems[6].setState(versteckeModel.holz2()); + testItems[7].setState(versteckeModel.baum2()); + } + + const auto &futterModel = model.futter(); + { + auto &testItems = m_tests.at(2).items(); + + testItems[0].setState(futterModel.salat()); + testItems[1].setState(futterModel.fleisch()); + testItems[2].setState(futterModel.knochen()); + testItems[3].setState(futterModel.banane()); + testItems[4].setState(futterModel.apfel()); + testItems[5].setState(futterModel.karotte()); + testItems[6].setState(futterModel.honig()); + testItems[7].setState(futterModel.zucker()); + } +} + +void DativModel::write(ESGRAF48::DativModel &model) const +{ + auto *tiereModel = model.mutable_tiere(); + if (tiereModel != nullptr) + { + const auto &testItems = m_tests.at(0).items(); + + tiereModel->set_tiger(testItems[0].isChecked()); + tiereModel->set_katze(testItems[1].isChecked()); + tiereModel->set_affe(testItems[2].isChecked()); + tiereModel->set_gans(testItems[3].isChecked()); + tiereModel->set_baer(testItems[4].isChecked()); + tiereModel->set_pferd(testItems[5].isChecked()); + tiereModel->set_hund(testItems[6].isChecked()); + tiereModel->set_elefant(testItems[7].isChecked()); + } + + auto *versteckeModel = model.mutable_verstecke(); + if (versteckeModel != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + versteckeModel->set_vorhang1(testItems[0].isChecked()); + versteckeModel->set_kiste1(testItems[1].isChecked()); + versteckeModel->set_holz1(testItems[2].isChecked()); + versteckeModel->set_kiste2(testItems[3].isChecked()); + versteckeModel->set_baum1(testItems[4].isChecked()); + versteckeModel->set_vorhang2(testItems[5].isChecked()); + versteckeModel->set_holz2(testItems[6].isChecked()); + versteckeModel->set_baum2(testItems[7].isChecked()); + } + + auto *futterModel = model.mutable_futter(); + if (futterModel != nullptr) + { + const auto &testItems = m_tests.at(2).items(); + + futterModel->set_salat(testItems[0].isChecked()); + futterModel->set_fleisch(testItems[1].isChecked()); + futterModel->set_knochen(testItems[2].isChecked()); + futterModel->set_banane(testItems[3].isChecked()); + futterModel->set_apfel(testItems[4].isChecked()); + futterModel->set_karotte(testItems[5].isChecked()); + futterModel->set_honig(testItems[6].isChecked()); + futterModel->set_zucker(testItems[7].isChecked()); + } } diff --git a/source/SubTests/AkkusativDativ/DativModel.h b/source/SubTests/AkkusativDativ/DativModel.h index 306c8ce..6a9a323 100644 --- a/source/SubTests/AkkusativDativ/DativModel.h +++ b/source/SubTests/AkkusativDativ/DativModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "DativModel.pb.h" class DativModel : public CheckableTestModel { @@ -8,4 +9,7 @@ class DativModel : public CheckableTestModel public: DativModel(QObject *parent); + + void read(const ESGRAF48::DativModel &model); + void write(ESGRAF48::DativModel &model) const; }; diff --git a/source/SubTests/Genus/CMakeLists.txt b/source/SubTests/Genus/CMakeLists.txt index 28fe2ef..5b29b68 100644 --- a/source/SubTests/Genus/CMakeLists.txt +++ b/source/SubTests/Genus/CMakeLists.txt @@ -11,7 +11,6 @@ qt5_wrap_ui(GENUS_UI GenusWidget.ui ) - set(Genus_PROTO_FILES ../../../proto/GenusModel.proto )