Converted VerbEndModel to protobuf serialization

This commit is contained in:
Michael Mandl 2018-11-17 15:55:40 +01:00
parent 09d811ee25
commit 62a90d5636
7 changed files with 149 additions and 0 deletions

View file

@ -4,9 +4,11 @@ package ESGRAF48;
import "MetaDataModel.proto"; import "MetaDataModel.proto";
import "V2SvkModel.proto"; import "V2SvkModel.proto";
import "VerbEndModel.proto";
message DataModel message DataModel
{ {
MetaDataModel MetaData = 1; MetaDataModel MetaData = 1;
V2SvkModel V2Svk = 2; V2SvkModel V2Svk = 2;
VerbEndModel VerbEnd = 3;
} }

42
proto/VerbEndModel.proto Normal file
View file

@ -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;
}

View file

@ -21,6 +21,7 @@ set(DataModel_PROTO_FILES
../proto/DataModel.proto ../proto/DataModel.proto
../proto/MetaDataModel.proto ../proto/MetaDataModel.proto
../proto/V2SvkModel.proto ../proto/V2SvkModel.proto
../proto/VerbEndModel.proto
) )
protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS

View file

@ -35,6 +35,7 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const
m_metaData.writeProtoBuf(*dataModel.mutable_metadata()); m_metaData.writeProtoBuf(*dataModel.mutable_metadata());
m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk());
m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend());
dataModel.SerializeToOstream(&outStream); dataModel.SerializeToOstream(&outStream);
} }
@ -46,6 +47,7 @@ void DataModel::readProtoBuf(std::istream &inStream)
m_metaData.readProtoBuf(dataModel.metadata()); m_metaData.readProtoBuf(dataModel.metadata());
m_v2Svk.readProtoBuf(dataModel.v2svk()); m_v2Svk.readProtoBuf(dataModel.v2svk());
m_verbEnd.readProtoBuf(dataModel.verbend());
} }
std::string DataModel::toHtml() const std::string DataModel::toHtml() const

View file

@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6)
project(VerbEnd LANGUAGES CXX) project(VerbEnd LANGUAGES CXX)
find_package(Qt5Widgets REQUIRED) find_package(Qt5Widgets REQUIRED)
find_package(Protobuf REQUIRED)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
@ -10,10 +11,18 @@ qt5_wrap_ui(UI_HEADERS
VerbEndWidget.ui 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} add_library(${PROJECT_NAME}
VerbEndWidget.cpp VerbEndWidget.cpp
VerbEndModel.cpp VerbEndModel.cpp
${UI_HEADERS} ${UI_HEADERS}
${VerbEnd_PROTO_SRCS}
${VerbEnd_PROTO_HDRS}
) )
set_target_properties(${PROJECT_NAME} set_target_properties(${PROJECT_NAME}
@ -25,6 +34,7 @@ target_include_directories(${PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE PRIVATE
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${Protobuf_INCLUDE_DIRS}
) )
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
@ -33,4 +43,5 @@ target_link_libraries(${PROJECT_NAME}
CheckableTest CheckableTest
CheckableTestModel CheckableTestModel
Qt5::Widgets Qt5::Widgets
${Protobuf_LIBRARIES}
) )

View file

@ -11,3 +11,90 @@ VerbEndModel::VerbEndModel(QObject *parent)
{ "Zauberregel", { "Temporal", "Kausal", "Final", "Relativ", { "Zauberregel", { "Temporal", "Kausal", "Final", "Relativ",
"Temporal", "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));
}

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "CheckableTestModel.h" #include "CheckableTestModel.h"
#include "VerbEndModel.pb.h"
class VerbEndModel : public CheckableTestModel class VerbEndModel : public CheckableTestModel
{ {
@ -8,4 +9,7 @@ class VerbEndModel : public CheckableTestModel
public: public:
VerbEndModel(QObject *parent); VerbEndModel(QObject *parent);
void writeProtoBuf(ESGRAF48::VerbEndModel &model) const;
void readProtoBuf(const ESGRAF48::VerbEndModel &model);
}; };