From 87c9b0e74a4981ff5234957896ccd944bfebb68c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 18 Nov 2018 17:40:07 +0100 Subject: [PATCH] Ported Plural model to protobuf --- proto/DataModel.proto | 2 ++ proto/PluralModel.proto | 16 +++++++++ source/CMakeLists.txt | 1 + source/DataModel.cpp | 2 ++ source/SubTests/Plural/CMakeLists.txt | 11 ++++++ source/SubTests/Plural/PluralModel.cpp | 47 +++++++++++++++++++++----- source/SubTests/Plural/PluralModel.h | 4 +++ 7 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 proto/PluralModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto index c04f473..d6e6e17 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -8,6 +8,7 @@ import "VerbEndModel.proto"; import "GenusModel.proto"; import "AkkusativModel.proto"; import "DativModel.proto"; +import "PluralModel.proto"; message DataModel { @@ -17,4 +18,5 @@ message DataModel GenusModel Genus = 4; AkkusativModel Akkusativ = 5; DativModel Dativ = 6; + PluralModel Plural = 7; } diff --git a/proto/PluralModel.proto b/proto/PluralModel.proto new file mode 100644 index 0000000..78ef0b8 --- /dev/null +++ b/proto/PluralModel.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package ESGRAF48; + +message PluralModel +{ + bool Fisch = 1; + bool Banane = 2; + bool Bonbon = 3; + bool Ei = 4; + bool Eimer = 5; + bool Korn = 6; + bool Nuss = 7; + bool Baer = 8; + bool Apfel = 9; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 6180070..85e1c57 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -25,6 +25,7 @@ set(DataModel_PROTO_FILES ../proto/GenusModel.proto ../proto/AkkusativModel.proto ../proto/DativModel.proto + ../proto/PluralModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 08bf4bc..e33b1c1 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -37,6 +37,7 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_genus.writeProtoBuf(*dataModel.mutable_genus()); m_akkusativ.write(*dataModel.mutable_akkusativ()); m_dativ.write(*dataModel.mutable_dativ()); + m_plural.write(*dataModel.mutable_plural()); dataModel.SerializeToOstream(&outStream); } @@ -52,6 +53,7 @@ void DataModel::readProtoBuf(std::istream &inStream) m_genus.readProtoBuf(dataModel.genus()); m_akkusativ.read(dataModel.akkusativ()); m_dativ.read(dataModel.dativ()); + m_plural.read(dataModel.plural()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/Plural/CMakeLists.txt b/source/SubTests/Plural/CMakeLists.txt index 36245b1..7a6aa58 100644 --- a/source/SubTests/Plural/CMakeLists.txt +++ b/source/SubTests/Plural/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(Plural LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,10 +11,18 @@ qt5_wrap_ui(UI_HEADERS PluralWidget.ui ) +set(Plural_PROTO_FILES + ../../../proto/PluralModel.proto +) + +protobuf_generate_cpp(Plural_PROTO_SRCS Plural_PROTO_HDRS ${Plural_PROTO_FILES}) + add_library(${PROJECT_NAME} PluralWidget.cpp PluralModel.cpp ${UI_HEADERS} + ${Plural_PROTO_SRCS} + ${Plural_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/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index 5be047a..a1a208e 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -3,20 +3,49 @@ #include PluralModel::PluralModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { { "", - { "Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/", - "Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML" } } }; + m_tests = {{"", + {"Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/", + "Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML"}}}; } QVariant PluralModel::data(const QModelIndex &index, int role) const { - if (role == Qt::SizeHintRole) - { - return QSize(180, 0); - } + if (role == Qt::SizeHintRole) + { + return QSize(180, 0); + } - return CheckableTestModel::data(index, role); + return CheckableTestModel::data(index, role); } +void PluralModel::read(const ESGRAF48::PluralModel &model) +{ + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(model.fisch()); + testItems[1].setState(model.banane()); + testItems[2].setState(model.bonbon()); + testItems[3].setState(model.ei()); + testItems[4].setState(model.eimer()); + testItems[5].setState(model.korn()); + testItems[6].setState(model.nuss()); + testItems[7].setState(model.baer()); + testItems[8].setState(model.apfel()); +} + +void PluralModel::write(ESGRAF48::PluralModel &model) const +{ + const auto &testItems = m_tests.at(0).items(); + + model.set_fisch(testItems[0].isChecked()); + model.set_banane(testItems[1].isChecked()); + model.set_bonbon(testItems[2].isChecked()); + model.set_ei(testItems[3].isChecked()); + model.set_eimer(testItems[4].isChecked()); + model.set_korn(testItems[5].isChecked()); + model.set_nuss(testItems[6].isChecked()); + model.set_baer(testItems[7].isChecked()); + model.set_apfel(testItems[8].isChecked()); +} diff --git a/source/SubTests/Plural/PluralModel.h b/source/SubTests/Plural/PluralModel.h index 8a07a55..cadeae9 100644 --- a/source/SubTests/Plural/PluralModel.h +++ b/source/SubTests/Plural/PluralModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "PluralModel.pb.h" class PluralModel : public CheckableTestModel { @@ -11,4 +12,7 @@ public: QVariant data( const QModelIndex &index, int role = Qt::DisplayRole) const override; + + void read(const ESGRAF48::PluralModel &model); + void write(ESGRAF48::PluralModel &model) const; };