Ported Plural model to protobuf
This commit is contained in:
parent
843164a3bf
commit
87c9b0e74a
@ -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;
|
||||
}
|
||||
|
16
proto/PluralModel.proto
Normal file
16
proto/PluralModel.proto
Normal file
@ -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;
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
)
|
||||
|
@ -5,9 +5,9 @@
|
||||
PluralModel::PluralModel(QObject *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
|
||||
@ -20,3 +20,32 @@ QVariant PluralModel::data(const QModelIndex &index, int role) const
|
||||
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());
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user