Ported GenusModel from json to protobuf
This commit is contained in:
parent
62a90d5636
commit
ef54685bce
@ -5,10 +5,12 @@ package ESGRAF48;
|
|||||||
import "MetaDataModel.proto";
|
import "MetaDataModel.proto";
|
||||||
import "V2SvkModel.proto";
|
import "V2SvkModel.proto";
|
||||||
import "VerbEndModel.proto";
|
import "VerbEndModel.proto";
|
||||||
|
import "GenusModel.proto";
|
||||||
|
|
||||||
message DataModel
|
message DataModel
|
||||||
{
|
{
|
||||||
MetaDataModel MetaData = 1;
|
MetaDataModel MetaData = 1;
|
||||||
V2SvkModel V2Svk = 2;
|
V2SvkModel V2Svk = 2;
|
||||||
VerbEndModel VerbEnd = 3;
|
VerbEndModel VerbEnd = 3;
|
||||||
|
GenusModel Genus = 4;
|
||||||
}
|
}
|
||||||
|
42
proto/GenusModel.proto
Normal file
42
proto/GenusModel.proto
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package ESGRAF48;
|
||||||
|
|
||||||
|
message GenusModel
|
||||||
|
{
|
||||||
|
message TiereModel
|
||||||
|
{
|
||||||
|
bool Tiger = 1;
|
||||||
|
bool Baer = 2;
|
||||||
|
bool Katze = 3;
|
||||||
|
bool Pferd = 4;
|
||||||
|
bool Gans = 5;
|
||||||
|
bool Elefant = 6;
|
||||||
|
bool Affe = 7;
|
||||||
|
bool Hund = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ZirkusModel
|
||||||
|
{
|
||||||
|
bool Kiste = 1;
|
||||||
|
bool Holz = 2;
|
||||||
|
bool Vorhang = 3;
|
||||||
|
bool Baum = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
TiereModel Tiere = 1;
|
||||||
|
FutterModel Futter = 2;
|
||||||
|
ZirkusModel Zirkus = 3;
|
||||||
|
}
|
@ -22,6 +22,7 @@ set(DataModel_PROTO_FILES
|
|||||||
../proto/MetaDataModel.proto
|
../proto/MetaDataModel.proto
|
||||||
../proto/V2SvkModel.proto
|
../proto/V2SvkModel.proto
|
||||||
../proto/VerbEndModel.proto
|
../proto/VerbEndModel.proto
|
||||||
|
../proto/GenusModel.proto
|
||||||
)
|
)
|
||||||
|
|
||||||
protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS
|
protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include "DataModel.h"
|
#include "DataModel.h"
|
||||||
|
|
||||||
#include "DataModel.pb.h"
|
#include "DataModel.pb.h"
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -36,6 +34,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());
|
m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend());
|
||||||
|
m_genus.writeProtoBuf(*dataModel.mutable_genus());
|
||||||
|
|
||||||
dataModel.SerializeToOstream(&outStream);
|
dataModel.SerializeToOstream(&outStream);
|
||||||
}
|
}
|
||||||
@ -48,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());
|
m_verbEnd.readProtoBuf(dataModel.verbend());
|
||||||
|
m_genus.readProtoBuf(dataModel.genus());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DataModel::toHtml() const
|
std::string DataModel::toHtml() const
|
||||||
|
@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6)
|
|||||||
project(Genus LANGUAGES CXX)
|
project(Genus 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,19 @@ qt5_wrap_ui(GENUS_UI
|
|||||||
GenusWidget.ui
|
GenusWidget.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
set(Genus_PROTO_FILES
|
||||||
|
../../../proto/GenusModel.proto
|
||||||
|
)
|
||||||
|
|
||||||
|
protobuf_generate_cpp(Genus_PROTO_SRCS Genus_PROTO_HDRS ${Genus_PROTO_FILES})
|
||||||
|
|
||||||
add_library(${PROJECT_NAME}
|
add_library(${PROJECT_NAME}
|
||||||
GenusWidget.cpp
|
GenusWidget.cpp
|
||||||
GenusModel.cpp
|
GenusModel.cpp
|
||||||
${GENUS_UI}
|
${GENUS_UI}
|
||||||
|
${Genus_PROTO_SRCS}
|
||||||
|
${Genus_PROTO_HDRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(${PROJECT_NAME}
|
set_target_properties(${PROJECT_NAME}
|
||||||
@ -25,6 +35,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 +44,5 @@ target_link_libraries(${PROJECT_NAME}
|
|||||||
CheckableTest
|
CheckableTest
|
||||||
CheckableTestModel
|
CheckableTestModel
|
||||||
Qt5::Widgets
|
Qt5::Widgets
|
||||||
|
${Protobuf_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
@ -1,11 +1,95 @@
|
|||||||
#include "GenusModel.h"
|
#include "GenusModel.h"
|
||||||
|
|
||||||
GenusModel::GenusModel(QObject *parent)
|
GenusModel::GenusModel(QObject *parent)
|
||||||
: CheckableTestModel(parent)
|
: CheckableTestModel(parent)
|
||||||
{
|
{
|
||||||
m_tests = { { "Tiere", { "Tiger", "Bär", "Katze", "Pferd", "Gans",
|
m_tests = {{"Tiere", {"Tiger", "Bär", "Katze", "Pferd", "Gans", "Elefant", "Affe", "Hund"}},
|
||||||
"Elefant", "Affe", "Hund" } },
|
{"Futter",
|
||||||
{ "Futter", { "Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte",
|
{"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}},
|
||||||
"Honig", "Zucker" } },
|
{"Zirkus", {"Kiste", "Holz", "Vorhang", "Baum"}}};
|
||||||
{ "Zirkus", { "Kiste", "Holz", "Vorhang", "Baum" } } };
|
}
|
||||||
|
|
||||||
|
void GenusModel::readProtoBuf(const ESGRAF48::GenusModel &model)
|
||||||
|
{
|
||||||
|
const auto &tiereModel = model.tiere();
|
||||||
|
{
|
||||||
|
auto &testItems = m_tests.at(0).items();
|
||||||
|
|
||||||
|
testItems[0].setState(tiereModel.tiger());
|
||||||
|
testItems[1].setState(tiereModel.baer());
|
||||||
|
testItems[2].setState(tiereModel.katze());
|
||||||
|
testItems[3].setState(tiereModel.pferd());
|
||||||
|
testItems[4].setState(tiereModel.gans());
|
||||||
|
testItems[5].setState(tiereModel.elefant());
|
||||||
|
testItems[6].setState(tiereModel.affe());
|
||||||
|
testItems[7].setState(tiereModel.hund());
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &futterModel = model.futter();
|
||||||
|
{
|
||||||
|
auto &testItems = m_tests.at(1).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());
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &zirkusModel = model.zirkus();
|
||||||
|
{
|
||||||
|
auto &testItems = m_tests.at(2).items();
|
||||||
|
|
||||||
|
testItems[0].setState(zirkusModel.kiste());
|
||||||
|
testItems[1].setState(zirkusModel.holz());
|
||||||
|
testItems[2].setState(zirkusModel.vorhang());
|
||||||
|
testItems[3].setState(zirkusModel.baum());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenusModel::writeProtoBuf(ESGRAF48::GenusModel &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_baer(testItems[1].isChecked());
|
||||||
|
tiereModel->set_katze(testItems[2].isChecked());
|
||||||
|
tiereModel->set_pferd(testItems[3].isChecked());
|
||||||
|
tiereModel->set_gans(testItems[4].isChecked());
|
||||||
|
tiereModel->set_elefant(testItems[5].isChecked());
|
||||||
|
tiereModel->set_affe(testItems[6].isChecked());
|
||||||
|
tiereModel->set_hund(testItems[7].isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *futterModel = model.mutable_futter();
|
||||||
|
if (futterModel != nullptr)
|
||||||
|
{
|
||||||
|
const auto &testItems = m_tests.at(1).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());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *zirkusModel = model.mutable_zirkus();
|
||||||
|
if (zirkusModel != nullptr)
|
||||||
|
{
|
||||||
|
const auto &testItems = m_tests.at(2).items();
|
||||||
|
|
||||||
|
zirkusModel->set_kiste(testItems[0].isChecked());
|
||||||
|
zirkusModel->set_holz(testItems[1].isChecked());
|
||||||
|
zirkusModel->set_vorhang(testItems[2].isChecked());
|
||||||
|
zirkusModel->set_baum(testItems[3].isChecked());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CheckableTestModel.h"
|
#include "CheckableTestModel.h"
|
||||||
|
#include "GenusModel.pb.h"
|
||||||
|
|
||||||
class GenusModel : public CheckableTestModel
|
class GenusModel : public CheckableTestModel
|
||||||
{
|
{
|
||||||
@ -8,4 +9,7 @@ class GenusModel : public CheckableTestModel
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
GenusModel(QObject *parent);
|
GenusModel(QObject *parent);
|
||||||
|
|
||||||
|
void readProtoBuf(const ESGRAF48::GenusModel &model);
|
||||||
|
void writeProtoBuf(ESGRAF48::GenusModel &model) const;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user