Ported Plural model to protobuf
This commit is contained in:
parent
843164a3bf
commit
87c9b0e74a
7 changed files with 74 additions and 9 deletions
|
@ -8,6 +8,7 @@ import "VerbEndModel.proto";
|
||||||
import "GenusModel.proto";
|
import "GenusModel.proto";
|
||||||
import "AkkusativModel.proto";
|
import "AkkusativModel.proto";
|
||||||
import "DativModel.proto";
|
import "DativModel.proto";
|
||||||
|
import "PluralModel.proto";
|
||||||
|
|
||||||
message DataModel
|
message DataModel
|
||||||
{
|
{
|
||||||
|
@ -17,4 +18,5 @@ message DataModel
|
||||||
GenusModel Genus = 4;
|
GenusModel Genus = 4;
|
||||||
AkkusativModel Akkusativ = 5;
|
AkkusativModel Akkusativ = 5;
|
||||||
DativModel Dativ = 6;
|
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/GenusModel.proto
|
||||||
../proto/AkkusativModel.proto
|
../proto/AkkusativModel.proto
|
||||||
../proto/DativModel.proto
|
../proto/DativModel.proto
|
||||||
|
../proto/PluralModel.proto
|
||||||
)
|
)
|
||||||
|
|
||||||
protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS
|
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_genus.writeProtoBuf(*dataModel.mutable_genus());
|
||||||
m_akkusativ.write(*dataModel.mutable_akkusativ());
|
m_akkusativ.write(*dataModel.mutable_akkusativ());
|
||||||
m_dativ.write(*dataModel.mutable_dativ());
|
m_dativ.write(*dataModel.mutable_dativ());
|
||||||
|
m_plural.write(*dataModel.mutable_plural());
|
||||||
|
|
||||||
dataModel.SerializeToOstream(&outStream);
|
dataModel.SerializeToOstream(&outStream);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +53,7 @@ void DataModel::readProtoBuf(std::istream &inStream)
|
||||||
m_genus.readProtoBuf(dataModel.genus());
|
m_genus.readProtoBuf(dataModel.genus());
|
||||||
m_akkusativ.read(dataModel.akkusativ());
|
m_akkusativ.read(dataModel.akkusativ());
|
||||||
m_dativ.read(dataModel.dativ());
|
m_dativ.read(dataModel.dativ());
|
||||||
|
m_plural.read(dataModel.plural());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DataModel::toHtml() const
|
std::string DataModel::toHtml() const
|
||||||
|
|
|
@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6)
|
||||||
project(Plural LANGUAGES CXX)
|
project(Plural 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
|
||||||
PluralWidget.ui
|
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}
|
add_library(${PROJECT_NAME}
|
||||||
PluralWidget.cpp
|
PluralWidget.cpp
|
||||||
PluralModel.cpp
|
PluralModel.cpp
|
||||||
${UI_HEADERS}
|
${UI_HEADERS}
|
||||||
|
${Plural_PROTO_SRCS}
|
||||||
|
${Plural_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}
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,20 +3,49 @@
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
|
||||||
PluralModel::PluralModel(QObject *parent)
|
PluralModel::PluralModel(QObject *parent)
|
||||||
: CheckableTestModel(parent)
|
: CheckableTestModel(parent)
|
||||||
{
|
{
|
||||||
m_tests = { { "",
|
m_tests = {{"",
|
||||||
{ "Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/",
|
{"Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/",
|
||||||
"Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML" } } };
|
"Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML"}}};
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant PluralModel::data(const QModelIndex &index, int role) const
|
QVariant PluralModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (role == Qt::SizeHintRole)
|
if (role == Qt::SizeHintRole)
|
||||||
{
|
{
|
||||||
return QSize(180, 0);
|
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());
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CheckableTestModel.h"
|
#include "CheckableTestModel.h"
|
||||||
|
#include "PluralModel.pb.h"
|
||||||
|
|
||||||
class PluralModel : public CheckableTestModel
|
class PluralModel : public CheckableTestModel
|
||||||
{
|
{
|
||||||
|
@ -11,4 +12,7 @@ public:
|
||||||
|
|
||||||
QVariant data(
|
QVariant data(
|
||||||
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
void read(const ESGRAF48::PluralModel &model);
|
||||||
|
void write(ESGRAF48::PluralModel &model) const;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue