Ported late skills to protobuf, added changed-messages

This commit is contained in:
Michael Mandl 2018-11-18 21:29:43 +01:00
parent 87c9b0e74a
commit f6b283b3a1
14 changed files with 222 additions and 36 deletions

View file

@ -9,6 +9,8 @@ import "GenusModel.proto";
import "AkkusativModel.proto"; import "AkkusativModel.proto";
import "DativModel.proto"; import "DativModel.proto";
import "PluralModel.proto"; import "PluralModel.proto";
import "LateSkillsGenitivModel.proto";
import "LateSkillsPassivModel.proto";
message DataModel message DataModel
{ {
@ -19,4 +21,6 @@ message DataModel
AkkusativModel Akkusativ = 5; AkkusativModel Akkusativ = 5;
DativModel Dativ = 6; DativModel Dativ = 6;
PluralModel Plural = 7; PluralModel Plural = 7;
LateSkillsGenitivModel LateSkillsGenitiv = 8;
LateSkillsPassivModel LateSkillsPassiv = 9;
} }

View file

@ -0,0 +1,33 @@
syntax = "proto3";
package ESGRAF48;
message LateSkillsGenitivModel
{
message PraepositionenModel
{
bool anstelle1 = 1;
bool anstelle2 = 2;
bool ausserhalb1 = 3;
bool ausserhalb2 = 4;
bool mithilfe1 = 5;
bool mithilfe2 = 6;
}
message AttributierungModel
{
bool Schuhe1 = 1;
bool Schuhe2 = 2;
bool Zauberstab1 = 3;
bool Zauberstab2 = 4;
bool Hut1 = 5;
bool Hut2 = 6;
bool Brille1 = 7;
bool Brille2 = 8;
bool Guertel1 = 9;
bool Guertel2 = 10;
}
PraepositionenModel Praepositionen = 1;
AttributierungModel Attributierung = 2;
}

View file

@ -0,0 +1,17 @@
syntax = "proto3";
package ESGRAF48;
message LateSkillsPassivModel
{
bool Elefant1 = 1;
bool Elefant2 = 2;
bool Pferde1 = 3;
bool Pferde2 = 4;
bool Baelle1 = 5;
bool Baelle2 = 6;
bool Ball1 = 7;
bool Ball2 = 8;
bool Fleisch1 = 9;
bool Fleisch2 = 10;
}

View file

@ -26,6 +26,8 @@ set(DataModel_PROTO_FILES
../proto/AkkusativModel.proto ../proto/AkkusativModel.proto
../proto/DativModel.proto ../proto/DativModel.proto
../proto/PluralModel.proto ../proto/PluralModel.proto
../proto/LateSkillsPassivModel.proto
../proto/LateSkillsGenitivModel.proto
) )
protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS

View file

@ -38,6 +38,8 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const
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()); m_plural.write(*dataModel.mutable_plural());
m_genitiv.write(*dataModel.mutable_lateskillsgenitiv());
m_passiv.write(*dataModel.mutable_lateskillspassiv());
dataModel.SerializeToOstream(&outStream); dataModel.SerializeToOstream(&outStream);
} }
@ -54,6 +56,8 @@ void DataModel::readProtoBuf(std::istream &inStream)
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()); m_plural.read(dataModel.plural());
m_genitiv.read(dataModel.lateskillsgenitiv());
m_passiv.read(dataModel.lateskillspassiv());
} }
std::string DataModel::toHtml() const std::string DataModel::toHtml() const

View file

@ -54,6 +54,8 @@ void AkkusativModel::read(const ESGRAF48::AkkusativModel &model)
testItems[6].setState(futterModel.honig()); testItems[6].setState(futterModel.honig());
testItems[7].setState(futterModel.zucker()); testItems[7].setState(futterModel.zucker());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const

View file

@ -54,6 +54,8 @@ void DativModel::read(const ESGRAF48::DativModel &model)
testItems[6].setState(futterModel.honig()); testItems[6].setState(futterModel.honig());
testItems[7].setState(futterModel.zucker()); testItems[7].setState(futterModel.zucker());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void DativModel::write(ESGRAF48::DativModel &model) const void DativModel::write(ESGRAF48::DativModel &model) const

View file

@ -48,6 +48,8 @@ void GenusModel::readProtoBuf(const ESGRAF48::GenusModel &model)
testItems[2].setState(zirkusModel.vorhang()); testItems[2].setState(zirkusModel.vorhang());
testItems[3].setState(zirkusModel.baum()); testItems[3].setState(zirkusModel.baum());
} }
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void GenusModel::writeProtoBuf(ESGRAF48::GenusModel &model) const void GenusModel::writeProtoBuf(ESGRAF48::GenusModel &model) const

View file

@ -3,18 +3,30 @@ cmake_minimum_required(VERSION 3.6)
project(LateSkills LANGUAGES CXX) project(LateSkills LANGUAGES CXX)
find_package(Qt5Widgets REQUIRED) find_package(Qt5Widgets REQUIRED)
find_package(Protobuf REQUIRED)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
qt5_wrap_ui(UI_HEADERS qt5_wrap_ui(UI_HEADERS
LateSkillsWidget.ui LateSkillsWidget.ui
)
set(LateSkills_PROTO_FILES
../../../proto/LateSkillsGenitivModel.proto
../../../proto/LateSkillsPassivModel.proto
)
protobuf_generate_cpp(LateSkills_PROTO_SRCS LateSkills_PROTO_HDRS
${LateSkills_PROTO_FILES}
) )
add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}
LateSkillsWidget.cpp LateSkillsWidget.cpp
PassivModel.cpp PassivModel.cpp
GenitivModel.cpp GenitivModel.cpp
${UI_HEADERS} ${UI_HEADERS}
${LateSkills_PROTO_SRCS}
${LateSkills_PROTO_HDRS}
) )
set_target_properties(${PROJECT_NAME} set_target_properties(${PROJECT_NAME}
@ -23,15 +35,17 @@ set_target_properties(${PROJECT_NAME}
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PUBLIC PUBLIC
${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}
PRIVATE PRIVATE
CheckableItem CheckableItem
CheckableTest CheckableTest
CheckableTestModel CheckableTestModel
Qt5::Widgets Qt5::Widgets
${Protobuf_LIBRARIES}
) )

View file

@ -1,45 +1,109 @@
#include "GenitivModel.h" #include "GenitivModel.h"
GenitivModel::GenitivModel(QObject *parent) GenitivModel::GenitivModel(QObject *parent)
: CheckableTestModel(parent) : CheckableTestModel(parent)
{ {
m_tests = { m_tests = {
{ "Genitiv Präpositionen", {"Genitiv Präpositionen",
{ "anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", {"anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", "mithilfe (1)",
"mithilfe (1)", "mithilfe (2)" } }, "mithilfe (2)"}},
{ "Attributierung", {"Attributierung",
{ "Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", {"Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", "Hut (1)", "Hut (2)",
"Hut (1)", "Hut (2)", "Brille (1)", "Brille (2)", "Gürtel (1)", "Brille (1)", "Brille (2)", "Gürtel (1)", "Gürtel (2)"}},
"Gürtel (2)" } },
}; };
for (auto index : { 1, 3, 5 }) for (auto index : {1, 3, 5})
{ {
m_tests[0].items()[index].setValue(2); m_tests[0].items()[index].setValue(2);
} }
for (auto index : { 1, 3, 5, 7, 9 }) for (auto index : {1, 3, 5, 7, 9})
{ {
m_tests[1].items()[index].setValue(2); m_tests[1].items()[index].setValue(2);
} }
} }
bool GenitivModel::setData( bool GenitivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
const QModelIndex &modelIndex, const QVariant &value, int role)
{ {
if (role == Qt::CheckStateRole && value.toBool() == true) if (role == Qt::CheckStateRole && value.toBool() == true)
{ {
if (modelIndex.column() % 2 == 0) if (modelIndex.column() % 2 == 0)
{ {
CheckableTestModel::setData( CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false,
index(modelIndex.row(), modelIndex.column() + 1), false, role); role);
} }
else else
{ {
CheckableTestModel::setData( CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false,
index(modelIndex.row(), modelIndex.column() - 1), false, role); role);
} }
} }
return CheckableTestModel::setData(modelIndex, value, role); return CheckableTestModel::setData(modelIndex, value, role);
} }
void GenitivModel::read(const ESGRAF48::LateSkillsGenitivModel &model)
{
const auto &praepositionenModel = model.praepositionen();
{
auto &testItems = m_tests.at(0).items();
testItems[0].setState(praepositionenModel.anstelle1());
testItems[1].setState(praepositionenModel.anstelle2());
testItems[2].setState(praepositionenModel.ausserhalb1());
testItems[3].setState(praepositionenModel.ausserhalb2());
testItems[4].setState(praepositionenModel.mithilfe1());
testItems[5].setState(praepositionenModel.mithilfe2());
}
const auto &attributierungModel = model.attributierung();
{
auto &testItems = m_tests.at(1).items();
testItems[0].setState(attributierungModel.schuhe1());
testItems[1].setState(attributierungModel.schuhe2());
testItems[2].setState(attributierungModel.zauberstab1());
testItems[3].setState(attributierungModel.zauberstab2());
testItems[4].setState(attributierungModel.hut1());
testItems[5].setState(attributierungModel.hut2());
testItems[6].setState(attributierungModel.brille1());
testItems[7].setState(attributierungModel.brille2());
testItems[8].setState(attributierungModel.guertel1());
testItems[9].setState(attributierungModel.guertel2());
}
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel &model) const
{
auto *praepositionenModel = model.mutable_praepositionen();
if (praepositionenModel != nullptr)
{
const auto &testItems = m_tests.at(0).items();
praepositionenModel->set_anstelle1(testItems[0].isChecked());
praepositionenModel->set_anstelle2(testItems[1].isChecked());
praepositionenModel->set_ausserhalb1(testItems[2].isChecked());
praepositionenModel->set_ausserhalb2(testItems[3].isChecked());
praepositionenModel->set_mithilfe1(testItems[4].isChecked());
praepositionenModel->set_mithilfe2(testItems[5].isChecked());
}
auto *attributierungModel = model.mutable_attributierung();
if (attributierungModel != nullptr)
{
const auto &testItems = m_tests.at(1).items();
attributierungModel->set_schuhe1(testItems[0].isChecked());
attributierungModel->set_schuhe2(testItems[1].isChecked());
attributierungModel->set_zauberstab1(testItems[2].isChecked());
attributierungModel->set_zauberstab2(testItems[3].isChecked());
attributierungModel->set_hut1(testItems[4].isChecked());
attributierungModel->set_hut2(testItems[5].isChecked());
attributierungModel->set_brille1(testItems[6].isChecked());
attributierungModel->set_brille2(testItems[7].isChecked());
attributierungModel->set_guertel1(testItems[8].isChecked());
attributierungModel->set_guertel2(testItems[9].isChecked());
}
}

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "CheckableTestModel.h" #include "CheckableTestModel.h"
#include "LateSkillsGenitivModel.pb.h"
class GenitivModel : public CheckableTestModel class GenitivModel : public CheckableTestModel
{ {
@ -10,4 +11,7 @@ public:
GenitivModel(QObject *parent); GenitivModel(QObject *parent);
bool setData(const QModelIndex &index, const QVariant &value, bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override; int role = Qt::EditRole) override;
void read(const ESGRAF48::LateSkillsGenitivModel &model);
void write(ESGRAF48::LateSkillsGenitivModel &model) const;
}; };

View file

@ -1,35 +1,67 @@
#include "PassivModel.h" #include "PassivModel.h"
PassivModel::PassivModel(QObject *parent) PassivModel::PassivModel(QObject *parent)
: CheckableTestModel(parent) : CheckableTestModel(parent)
{ {
m_tests = { { "Passiv", m_tests = {{"Passiv",
{ "Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", {"Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", "Bälle (2)",
"Bälle (2)", "Ball (1)", "Ball (2)", "Fleisch (1)", "Ball (1)", "Ball (2)", "Fleisch (1)", "Fleisch (2)"}}};
"Fleisch (2)" } } };
for (auto index : { 1, 3, 5, 7, 9 }) for (auto index : {1, 3, 5, 7, 9})
{ {
m_tests[0].items()[index].setValue(2); m_tests[0].items()[index].setValue(2);
} }
} }
bool PassivModel::setData( bool PassivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
const QModelIndex &modelIndex, const QVariant &value, int role)
{ {
if (role == Qt::CheckStateRole && value.toBool() == true) if (role == Qt::CheckStateRole && value.toBool() == true)
{ {
if (modelIndex.column() % 2 == 0) if (modelIndex.column() % 2 == 0)
{ {
CheckableTestModel::setData( CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false,
index(modelIndex.row(), modelIndex.column() + 1), false, role); role);
} }
else else
{ {
CheckableTestModel::setData( CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false,
index(modelIndex.row(), modelIndex.column() - 1), false, role); role);
} }
} }
return CheckableTestModel::setData(modelIndex, value, role); return CheckableTestModel::setData(modelIndex, value, role);
} }
void PassivModel::read(const ESGRAF48::LateSkillsPassivModel &model)
{
auto &testItems = m_tests.at(0).items();
testItems[0].setState(model.elefant1());
testItems[1].setState(model.elefant2());
testItems[2].setState(model.pferde1());
testItems[3].setState(model.pferde2());
testItems[4].setState(model.baelle1());
testItems[5].setState(model.baelle2());
testItems[6].setState(model.ball1());
testItems[7].setState(model.ball2());
testItems[8].setState(model.fleisch1());
testItems[9].setState(model.fleisch2());
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void PassivModel::write(ESGRAF48::LateSkillsPassivModel &model) const
{
const auto &testItems = m_tests.at(0).items();
model.set_elefant1(testItems[0].isChecked());
model.set_elefant2(testItems[1].isChecked());
model.set_pferde1(testItems[2].isChecked());
model.set_pferde2(testItems[3].isChecked());
model.set_baelle1(testItems[4].isChecked());
model.set_baelle2(testItems[5].isChecked());
model.set_ball1(testItems[6].isChecked());
model.set_ball2(testItems[7].isChecked());
model.set_fleisch1(testItems[8].isChecked());
model.set_fleisch2(testItems[9].isChecked());
}

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "CheckableTestModel.h" #include "CheckableTestModel.h"
#include "LateSkillsPassivModel.pb.h"
class PassivModel : public CheckableTestModel class PassivModel : public CheckableTestModel
{ {
@ -10,4 +11,7 @@ public:
PassivModel(QObject *parent); PassivModel(QObject *parent);
bool setData(const QModelIndex &index, const QVariant &value, bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override; int role = Qt::EditRole) override;
void read(const ESGRAF48::LateSkillsPassivModel &model);
void write(ESGRAF48::LateSkillsPassivModel &model) const;
}; };

View file

@ -33,6 +33,8 @@ void PluralModel::read(const ESGRAF48::PluralModel &model)
testItems[6].setState(model.nuss()); testItems[6].setState(model.nuss());
testItems[7].setState(model.baer()); testItems[7].setState(model.baer());
testItems[8].setState(model.apfel()); testItems[8].setState(model.apfel());
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
} }
void PluralModel::write(ESGRAF48::PluralModel &model) const void PluralModel::write(ESGRAF48::PluralModel &model) const