From 62a90d56363323e5e3d538c30592b21f365e6b72 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 17 Nov 2018 15:55:40 +0100 Subject: [PATCH] Converted VerbEndModel to protobuf serialization --- proto/DataModel.proto | 2 + proto/VerbEndModel.proto | 42 ++++++++++++ source/CMakeLists.txt | 1 + source/DataModel.cpp | 2 + source/SubTests/VerbEnd/CMakeLists.txt | 11 +++ source/SubTests/VerbEnd/VerbEndModel.cpp | 87 ++++++++++++++++++++++++ source/SubTests/VerbEnd/VerbEndModel.h | 4 ++ 7 files changed, 149 insertions(+) create mode 100644 proto/VerbEndModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto index bd21edb..a0b0128 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -4,9 +4,11 @@ package ESGRAF48; import "MetaDataModel.proto"; import "V2SvkModel.proto"; +import "VerbEndModel.proto"; message DataModel { MetaDataModel MetaData = 1; V2SvkModel V2Svk = 2; + VerbEndModel VerbEnd = 3; } diff --git a/proto/VerbEndModel.proto b/proto/VerbEndModel.proto new file mode 100644 index 0000000..84dfa96 --- /dev/null +++ b/proto/VerbEndModel.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package ESGRAF48; + +message VerbEndModel +{ + message TelefonatModel + { + bool Kausal1 = 1; + bool Kausal2 = 2; + bool Relativ = 3; + bool Kausal3 = 4; + bool Final = 5; + bool Temporal1 = 6; + bool Temporal2 = 7; + } + + message ZaubertrickModel + { + bool Relativ = 1; + bool Final1 = 2; + bool Kausal1 = 3; + bool Final2 = 4; + bool Temporal1 = 5; + bool Kausal2 = 6; + bool Temporal2 = 7; + } + + message ZauberregelModel + { + bool Temporal1 = 1; + bool Kausal = 2; + bool Final = 3; + bool Relativ1 = 4; + bool Temporal2 = 5; + bool Relativ2 = 6; + } + + TelefonatModel Telefonat = 1; + ZaubertrickModel Zaubertrick = 2; + ZauberregelModel Zauberregel = 3; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 410e0fe..61e5d50 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -21,6 +21,7 @@ set(DataModel_PROTO_FILES ../proto/DataModel.proto ../proto/MetaDataModel.proto ../proto/V2SvkModel.proto + ../proto/VerbEndModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index ba97a59..d0119e7 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -35,6 +35,7 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_metaData.writeProtoBuf(*dataModel.mutable_metadata()); m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); + m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend()); dataModel.SerializeToOstream(&outStream); } @@ -46,6 +47,7 @@ void DataModel::readProtoBuf(std::istream &inStream) m_metaData.readProtoBuf(dataModel.metadata()); m_v2Svk.readProtoBuf(dataModel.v2svk()); + m_verbEnd.readProtoBuf(dataModel.verbend()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/VerbEnd/CMakeLists.txt b/source/SubTests/VerbEnd/CMakeLists.txt index c65fca1..1302223 100644 --- a/source/SubTests/VerbEnd/CMakeLists.txt +++ b/source/SubTests/VerbEnd/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(VerbEnd LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,10 +11,18 @@ qt5_wrap_ui(UI_HEADERS VerbEndWidget.ui ) +set(VerbEnd_PROTO_FILES + ../../../proto/VerbEndModel.proto +) + +protobuf_generate_cpp(VerbEnd_PROTO_SRCS VerbEnd_PROTO_HDRS ${VerbEnd_PROTO_FILES}) + add_library(${PROJECT_NAME} VerbEndWidget.cpp VerbEndModel.cpp ${UI_HEADERS} + ${VerbEnd_PROTO_SRCS} + ${VerbEnd_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -25,6 +34,7 @@ target_include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} ) target_link_libraries(${PROJECT_NAME} @@ -33,4 +43,5 @@ target_link_libraries(${PROJECT_NAME} CheckableTest CheckableTestModel Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index bbda111..9df5e5d 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -11,3 +11,90 @@ VerbEndModel::VerbEndModel(QObject *parent) { "Zauberregel", { "Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ" } } }; } + +void VerbEndModel::writeProtoBuf(ESGRAF48::VerbEndModel &model) const +{ + auto *telefonatModel = model.mutable_telefonat(); + if (telefonatModel != nullptr) + { + const auto &testItems = m_tests.at(0).items(); + + telefonatModel->set_kausal1(testItems[0].isChecked()); + telefonatModel->set_kausal2(testItems[1].isChecked()); + telefonatModel->set_relativ(testItems[2].isChecked()); + telefonatModel->set_kausal3(testItems[3].isChecked()); + telefonatModel->set_final(testItems[4].isChecked()); + telefonatModel->set_temporal1(testItems[5].isChecked()); + telefonatModel->set_temporal2(testItems[6].isChecked()); + } + + auto *zaubertrickModel = model.mutable_zaubertrick(); + if (zaubertrickModel != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + zaubertrickModel->set_relativ(testItems[0].isChecked()); + zaubertrickModel->set_final1(testItems[1].isChecked()); + zaubertrickModel->set_kausal1(testItems[2].isChecked()); + zaubertrickModel->set_final2(testItems[3].isChecked()); + zaubertrickModel->set_temporal1(testItems[4].isChecked()); + zaubertrickModel->set_kausal2(testItems[5].isChecked()); + zaubertrickModel->set_temporal2(testItems[6].isChecked()); + } + + auto *zauberregelModel = model.mutable_zauberregel(); + if (zauberregelModel != nullptr) + { + const auto &testItems = m_tests.at(2).items(); + + zauberregelModel->set_temporal1(testItems[0].isChecked()); + zauberregelModel->set_kausal(testItems[1].isChecked()); + zauberregelModel->set_final(testItems[2].isChecked()); + zauberregelModel->set_relativ1(testItems[3].isChecked()); + zauberregelModel->set_temporal2(testItems[4].isChecked()); + zauberregelModel->set_relativ2(testItems[5].isChecked()); + } +} + +void VerbEndModel::readProtoBuf(const ESGRAF48::VerbEndModel &model) +{ + const auto &telefonatModel = model.telefonat(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(telefonatModel.kausal1()); + testItems[1].setState(telefonatModel.kausal2()); + testItems[2].setState(telefonatModel.relativ()); + testItems[3].setState(telefonatModel.kausal3()); + testItems[4].setState(telefonatModel.final()); + testItems[5].setState(telefonatModel.temporal1()); + testItems[6].setState(telefonatModel.temporal2()); + } + + const auto &zaubertrickModel = model.zaubertrick(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[0].setState(zaubertrickModel.relativ()); + testItems[1].setState(zaubertrickModel.final1()); + testItems[2].setState(zaubertrickModel.kausal1()); + testItems[3].setState(zaubertrickModel.final2()); + testItems[4].setState(zaubertrickModel.temporal1()); + testItems[5].setState(zaubertrickModel.kausal2()); + testItems[6].setState(zaubertrickModel.temporal2()); + } + + const auto &zauberregelModel = model.zauberregel(); + { + auto &testItems = m_tests.at(2).items(); + + testItems[0].setState(zauberregelModel.temporal1()); + testItems[1].setState(zauberregelModel.kausal()); + testItems[2].setState(zauberregelModel.final()); + testItems[3].setState(zauberregelModel.relativ1()); + testItems[4].setState(zauberregelModel.temporal2()); + testItems[5].setState(zauberregelModel.relativ2()); + } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index 42ac7d4..ea729fc 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "VerbEndModel.pb.h" class VerbEndModel : public CheckableTestModel { @@ -8,4 +9,7 @@ class VerbEndModel : public CheckableTestModel public: VerbEndModel(QObject *parent); + + void writeProtoBuf(ESGRAF48::VerbEndModel &model) const; + void readProtoBuf(const ESGRAF48::VerbEndModel &model); };