From f8c3dc35fdc53821c5db7b375ec5c6899c6d3f45 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 3 Nov 2018 22:29:38 +0100 Subject: [PATCH 01/14] Print a (unfinished) meta-data table --- source/DataModel.cpp | 87 +++++++++++++++++++------------ source/DataModel.h | 2 + source/MetaData/MetaDataModel.cpp | 37 +++++++++++-- source/MetaData/MetaDataModel.h | 2 + source/mainwindow.cpp | 12 ++--- 5 files changed, 98 insertions(+), 42 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index d96b868..f5fbeb4 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -2,37 +2,30 @@ #include +#include + DataModel::DataModel(QObject *parent) - : QObject(parent) - , m_metaData(this) - , m_verbEnd(this) - , m_genus(this) - , m_plural(this) - , m_results(this) - , m_akkusativ(this) - , m_dativ(this) - , m_v2Svk(this) + : QObject(parent) + , m_metaData(this) + , m_verbEnd(this) + , m_genus(this) + , m_plural(this) + , m_results(this) + , m_akkusativ(this) + , m_dativ(this) + , m_v2Svk(this) , m_passiv(this) , m_genitiv(this) { - connect(&m_plural, &PluralModel::dataChanged, this, - &DataModel::pluralModelChanged); - connect(&m_metaData, &MetaDataModel::dataChanged, this, - &DataModel::metaDataChanged); - connect(&m_genus, &GenusModel::dataChanged, this, - &DataModel::genusModelChanged); - connect(&m_verbEnd, &VerbEndModel::dataChanged, this, - &DataModel::verbEndModelChanged); - connect(&m_akkusativ, &AkkusativModel::dataChanged, this, - &DataModel::akkusativModelChanged); - connect(&m_dativ, &DativModel::dataChanged, this, - &DataModel::dativModelChanged); - connect(&m_v2Svk, &V2SvkModel::dataChanged, this, - &DataModel::v2SvkModelChanged); - connect(&m_passiv, &PassivModel::dataChanged, this, - &DataModel::passivModelChanged); - connect(&m_genitiv, &GenitivModel::dataChanged, this, - &DataModel::genitivModelChanged); + connect(&m_plural, &PluralModel::dataChanged, this, &DataModel::pluralModelChanged); + connect(&m_metaData, &MetaDataModel::dataChanged, this, &DataModel::metaDataChanged); + connect(&m_genus, &GenusModel::dataChanged, this, &DataModel::genusModelChanged); + connect(&m_verbEnd, &VerbEndModel::dataChanged, this, &DataModel::verbEndModelChanged); + connect(&m_akkusativ, &AkkusativModel::dataChanged, this, &DataModel::akkusativModelChanged); + connect(&m_dativ, &DativModel::dataChanged, this, &DataModel::dativModelChanged); + connect(&m_v2Svk, &V2SvkModel::dataChanged, this, &DataModel::v2SvkModelChanged); + connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged); + connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); } void DataModel::write(QJsonObject &target) const @@ -44,8 +37,8 @@ void DataModel::write(QJsonObject &target) const write(m_akkusativ, target, "Akkusativ"); write(m_dativ, target, "Dativ"); write(m_v2Svk, target, "V2Svk"); - write(m_passiv, target, "Passiv"); - write(m_genitiv, target, "Genitiv"); + write(m_passiv, target, "Passiv"); + write(m_genitiv, target, "Genitiv"); } void DataModel::read(const QJsonObject &source) @@ -57,8 +50,36 @@ void DataModel::read(const QJsonObject &source) read(m_akkusativ, source, "Akkusativ"); read(m_dativ, source, "Dativ"); read(m_v2Svk, source, "V2Svk"); - read(m_passiv, source, "Passiv"); - read(m_genitiv, source, "Genitiv"); + read(m_passiv, source, "Passiv"); + read(m_genitiv, source, "Genitiv"); +} + +std::string DataModel::toHtml() const +{ + std::stringstream out; + + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "

ESGRAF 4-8 Auswertungsbogen

" << std::endl; + out << "

" << std::endl; + out << m_metaData.toHtml(); + out << "

" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + + return out.str(); } void DataModel::pluralModelChanged() @@ -113,14 +134,14 @@ void DataModel::v2SvkModelChanged() void DataModel::passivModelChanged() { - m_results.setPassivResult(m_passiv.getPoints()); + m_results.setPassivResult(m_passiv.getPoints()); emit modelChanged(); } void DataModel::genitivModelChanged() { - m_results.setGenitivResult(m_genitiv.getPoints()); + m_results.setGenitivResult(m_genitiv.getPoints()); emit modelChanged(); } diff --git a/source/DataModel.h b/source/DataModel.h index 20d1b31..b2d6f13 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -37,6 +37,8 @@ public: void write(QJsonObject &target) const; void read(const QJsonObject &source); + std::string toHtml() const; + signals: void modelChanged(); diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 3d797a9..822834d 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -2,8 +2,10 @@ #include +#include + MetaDataModel::MetaDataModel(QObject *parent) - : QAbstractTableModel(parent) + : QAbstractTableModel(parent) { m_dateOfBirth = QDate::currentDate().addYears(-9); m_dateOfTest = QDate::currentDate(); @@ -50,8 +52,7 @@ Qt::ItemFlags MetaDataModel::flags(const QModelIndex &modelIndex) const return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable; } -bool MetaDataModel::setData( - const QModelIndex &modelIndex, const QVariant &value, int role) +bool MetaDataModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role) { if (role != Qt::EditRole) { @@ -128,3 +129,33 @@ void MetaDataModel::read(const QJsonObject &json) setData(index(0, 3), json["date of test"].toVariant(), Qt::EditRole); setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole); } + +std::string MetaDataModel::toHtml() const +{ + std::ostringstream out; + + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "
Name, Vorname" << m_participant.toStdString() << "Untersucher(in)" << m_instructor.toStdString() << "
GeburtsdatumBemerkungen
Untersuchungsdatum
Alter am Testtag
" << std::endl; + + return out.str(); +} diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 8d5f614..6c81f8a 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -31,6 +31,8 @@ public: void write(QJsonObject &json) const; void read(const QJsonObject &json); + std::string toHtml() const; + Age getAge() const { return { m_dateOfBirth, m_dateOfTest }; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index ce4e36f..1f3242b 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -16,6 +16,8 @@ #include +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -135,6 +137,9 @@ void MainWindow::closeFile() void MainWindow::print() const { + std::ofstream htmlfile("print.html"); + htmlfile << m_dataModel->toHtml(); + QPrinter printer; QPrintDialog dialog(&printer); @@ -144,12 +149,7 @@ void MainWindow::print() const } QTextDocument printDoc; - printDoc.setHtml( - "" - "" - "

Hello World

" - "" - ""); + printDoc.setHtml(QString::fromStdString(m_dataModel->toHtml())); printDoc.print(&printer); } From fcbe356f75a03924add0fc07f5d797de911d28a8 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 4 Nov 2018 13:57:35 +0100 Subject: [PATCH 02/14] Print metadata table --- source/DataModel.cpp | 5 ----- source/MetaData/MetaDataModel.cpp | 25 ++++++++++++++++--------- source/mainwindow.cpp | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index f5fbeb4..f5fc181 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -64,11 +64,6 @@ std::string DataModel::toHtml() const out << "body {" << std::endl; out << "font-family:sans-serif;" << std::endl; out << "}" << std::endl; - out << "table, th, td {" << std::endl; - out << "border: 1px solid black;" << std::endl; - out << "border-collapse: collapse;" << std::endl; - out << "padding: 5px;" << std::endl; - out << "}" << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 822834d..7219715 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -134,26 +134,33 @@ std::string MetaDataModel::toHtml() const { std::ostringstream out; - out << "" << std::endl; + out << "
" + << std::endl; out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; + out << "" << std::endl; + out << "" + << std::endl; + out << "" << std::endl; + out << "" + << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; - out << "" << std::endl; + out << "" + << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; + out << "" + << std::endl; + out << "" + << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; - out << "" << std::endl; + out << "" << std::endl; out << "" << std::endl; out << "
Name, Vorname" << m_participant.toStdString() << "Untersucher(in)" << m_instructor.toStdString() << "Name, Vorname" << m_participant.toHtmlEscaped().toStdString() << "Untersucher(in)" << m_instructor.toHtmlEscaped().toStdString() << "
Geburtsdatum" << m_dateOfBirth.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "Bemerkungen
Untersuchungsdatum" << m_dateOfTest.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "" + << m_remarks.trimmed().toHtmlEscaped().replace("\n", "
").toStdString() << "
Alter am Testtag" << getAge().toString() << "
" << std::endl; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 1f3242b..12bc99f 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -137,8 +137,8 @@ void MainWindow::closeFile() void MainWindow::print() const { - std::ofstream htmlfile("print.html"); - htmlfile << m_dataModel->toHtml(); + //std::ofstream htmlfile("print.html"); + //htmlfile << m_dataModel->toHtml(); QPrinter printer; From 7b02a34cf3aa03406ff8b655436550b38c37b5c4 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 12 Nov 2018 22:15:42 +0100 Subject: [PATCH 03/14] Integrated protobuf, added some empty messages --- proto/DataModel.proto | 12 ++++++++++++ proto/MetaDataModel.proto | 8 ++++++++ proto/V2SvkModel.proto | 8 ++++++++ source/CMakeLists.txt | 14 ++++++++++++++ source/SubTests/V2Svk/CMakeLists.txt | 11 +++++++++++ 5 files changed, 53 insertions(+) create mode 100644 proto/DataModel.proto create mode 100644 proto/MetaDataModel.proto create mode 100644 proto/V2SvkModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto new file mode 100644 index 0000000..bd21edb --- /dev/null +++ b/proto/DataModel.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package ESGRAF48; + +import "MetaDataModel.proto"; +import "V2SvkModel.proto"; + +message DataModel +{ + MetaDataModel MetaData = 1; + V2SvkModel V2Svk = 2; +} diff --git a/proto/MetaDataModel.proto b/proto/MetaDataModel.proto new file mode 100644 index 0000000..1b75c36 --- /dev/null +++ b/proto/MetaDataModel.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +package ESGRAF48; + +message MetaDataModel +{ + string dummy = 1; +} diff --git a/proto/V2SvkModel.proto b/proto/V2SvkModel.proto new file mode 100644 index 0000000..9f63d8c --- /dev/null +++ b/proto/V2SvkModel.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +package ESGRAF48; + +message V2SvkModel +{ + string dummy = 1; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 2bb2e79..5bdd8f2 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -4,6 +4,7 @@ project(ESGRAF48 LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) find_package(Qt5PrintSupport REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) @@ -16,6 +17,15 @@ qt5_add_resources(LOGO_TEST_QRC mainwindow.qrc ) +set(DataModel_PROTO_FILES + ../proto/DataModel.proto + ../proto/MetaDataModel.proto + ../proto/V2SvkModel.proto +) + +protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS + ${DataModel_PROTO_FILES}) + add_executable(${PROJECT_NAME} WIN32 LogoTest.cpp DataModel.cpp @@ -23,6 +33,8 @@ add_executable(${PROJECT_NAME} WIN32 Age.cpp ${LOGO_TEST_UI} ${LOGO_TEST_QRC} + ${PROTO_SRCS} + ${PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -33,6 +45,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} ) target_link_libraries(${PROJECT_NAME} @@ -50,6 +63,7 @@ target_link_libraries(${PROJECT_NAME} ResultWidget Qt5::Widgets Qt5::PrintSupport + ${Protobuf_LIBRARIES} ) add_subdirectory(CheckableItem) diff --git a/source/SubTests/V2Svk/CMakeLists.txt b/source/SubTests/V2Svk/CMakeLists.txt index 495e5ca..fdd3fe6 100644 --- a/source/SubTests/V2Svk/CMakeLists.txt +++ b/source/SubTests/V2Svk/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(V2Svk LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,10 +11,18 @@ qt5_wrap_ui(UI_HEADERS V2SvkWidget.ui ) +set(V2Svk_PROTO_FILES + ../../../proto/V2SvkModel.proto +) + +protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${V2Svk_PROTO_FILES}) + add_library(${PROJECT_NAME} V2SvkWidget.cpp V2SvkModel.cpp ${UI_HEADERS} + ${PROTO_SRCS} + ${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} ) From 221368b3ca6958bb93a855f7a045f62d777ac098 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 14 Nov 2018 00:17:29 +0100 Subject: [PATCH 04/14] Read and write some protobuf data --- proto/V2SvkModel.proto | 45 ++++++++++++++++++- source/CMakeLists.txt | 6 +-- source/DataModel.cpp | 23 ++++++++++ source/DataModel.h | 3 ++ source/MetaData/CMakeLists.txt | 13 ++++++ source/MetaData/MetaDataModel.cpp | 4 ++ source/MetaData/MetaDataModel.h | 4 ++ source/SubTests/V2Svk/CMakeLists.txt | 6 +-- source/SubTests/V2Svk/V2SvkModel.cpp | 64 ++++++++++++++++++++++++++++ source/SubTests/V2Svk/V2SvkModel.h | 4 ++ source/mainwindow.cpp | 46 +++++++++++++------- 11 files changed, 196 insertions(+), 22 deletions(-) diff --git a/proto/V2SvkModel.proto b/proto/V2SvkModel.proto index 9f63d8c..8a8c268 100644 --- a/proto/V2SvkModel.proto +++ b/proto/V2SvkModel.proto @@ -4,5 +4,48 @@ package ESGRAF48; message V2SvkModel { - string dummy = 1; + message OneEach + { + bool Affe = 1; + bool Schwein = 2; + bool Gans = 3; + } + + message TwoEach + { + bool Affe1 = 1; + bool Affe2 = 2; + bool Schwein1 = 3; + bool Schwein2 = 4; + bool Gans1 = 5; + bool Gans2 = 6; + } + + message FourEach + { + bool Affe1 = 1; + bool Affe2 = 2; + bool Affe3 = 3; + bool Affe4 = 4; + bool Schwein1 = 5; + bool Schwein2 = 6; + bool Schwein3 = 7; + bool Schwein4 = 8; + bool Gans1 = 9; + bool Gans2 = 10; + bool Gans3 = 11; + bool Gans4 = 12; + } + + FourEach WFrage = 1; + OneEach Verbtrennung1 = 2; + FourEach SvkSt = 3; + FourEach ObjTop = 4; + FourEach SvkStamm = 5; + TwoEach TempPraes = 6; + TwoEach SvkE1 = 7; + TwoEach TempPerf = 8; + TwoEach Verbtrennung2 = 9; + TwoEach SvkE2 = 10; + TwoEach Partizip = 11; } diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 5bdd8f2..410e0fe 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -23,7 +23,7 @@ set(DataModel_PROTO_FILES ../proto/V2SvkModel.proto ) -protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS +protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS ${DataModel_PROTO_FILES}) add_executable(${PROJECT_NAME} WIN32 @@ -33,8 +33,8 @@ add_executable(${PROJECT_NAME} WIN32 Age.cpp ${LOGO_TEST_UI} ${LOGO_TEST_QRC} - ${PROTO_SRCS} - ${PROTO_HDRS} + ${DataModel_PROTO_SRCS} + ${DataModel_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} diff --git a/source/DataModel.cpp b/source/DataModel.cpp index f5fc181..2f571c1 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -1,7 +1,10 @@ #include "DataModel.h" +#include "DataModel.pb.h" #include +#include + #include DataModel::DataModel(QObject *parent) @@ -54,6 +57,26 @@ void DataModel::read(const QJsonObject &source) read(m_genitiv, source, "Genitiv"); } +void DataModel::writeProtoBuf(std::ostream &outStream) const +{ + ESGRAF48::DataModel dataModel; + //m_metaData.writeProtoBuf(dataModel.mutable_metadata); + m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); + dataModel.SerializeToOstream(&outStream); + + std::string saveData; + google::protobuf::TextFormat::PrintToString(dataModel, &saveData); + qDebug() << "Wrote:" << QString::fromStdString(saveData); +} + +void DataModel::readProtoBuf(std::istream &inStream) +{ + ESGRAF48::DataModel dataModel; + dataModel.ParseFromIstream(&inStream); + + m_v2Svk.readProtoBuf(dataModel.v2svk()); +} + std::string DataModel::toHtml() const { std::stringstream out; diff --git a/source/DataModel.h b/source/DataModel.h index b2d6f13..2ac876d 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -39,6 +39,9 @@ public: std::string toHtml() const; + void writeProtoBuf(std::ostream &outStream) const; + void readProtoBuf(std::istream &inStream); + signals: void modelChanged(); diff --git a/source/MetaData/CMakeLists.txt b/source/MetaData/CMakeLists.txt index 01aa53f..d8a6379 100644 --- a/source/MetaData/CMakeLists.txt +++ b/source/MetaData/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(MetaData LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,10 +11,20 @@ qt5_wrap_ui(META_DATA_UI MetaDataWidget.ui ) +set(MetaDataModel_PROTO_FILES + ../../proto/MetaDataModel.proto +) + +protobuf_generate_cpp(MetaDataModel_PROTO_SRCS MetaDataModel_PROTO_HDRS + ${MetaDataModel_PROTO_FILES} +) + add_library(${PROJECT_NAME} MetaDataModel.cpp MetaDataWidget.cpp ${META_DATA_UI} + ${MetaDateModel_PROTO_SRCS} + ${MetaDateModel_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -23,6 +34,7 @@ set_target_properties(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -30,4 +42,5 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 7219715..1877777 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -130,6 +130,10 @@ void MetaDataModel::read(const QJsonObject &json) setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole); } +//void MetaDataModel::writeProtoBuf(ESGRAF48::MetaDataModel &model) const +//{ +//} + std::string MetaDataModel::toHtml() const { std::ostringstream out; diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 6c81f8a..1de7a0f 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -2,6 +2,8 @@ #include "../Age.h" +//#include "MetaDataModel.pb.h" + #include #include #include @@ -31,6 +33,8 @@ public: void write(QJsonObject &json) const; void read(const QJsonObject &json); + //void writeProtoBuf(ESGRAF48::MetaDataModel &model) const; + std::string toHtml() const; Age getAge() const diff --git a/source/SubTests/V2Svk/CMakeLists.txt b/source/SubTests/V2Svk/CMakeLists.txt index fdd3fe6..caf6c8c 100644 --- a/source/SubTests/V2Svk/CMakeLists.txt +++ b/source/SubTests/V2Svk/CMakeLists.txt @@ -15,14 +15,14 @@ set(V2Svk_PROTO_FILES ../../../proto/V2SvkModel.proto ) -protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${V2Svk_PROTO_FILES}) +protobuf_generate_cpp(V2Svk_PROTO_SRCS V2Svk_PROTO_HDRS ${V2Svk_PROTO_FILES}) add_library(${PROJECT_NAME} V2SvkWidget.cpp V2SvkModel.cpp ${UI_HEADERS} - ${PROTO_SRCS} - ${PROTO_HDRS} + ${V2Svk_PROTO_SRCS} + ${V2Svk_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 249fe91..b86cef9 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -75,3 +75,67 @@ unsigned int V2SvkModel::getSvkPoints() return points; } + +void V2SvkModel::writeProtoBuf(ESGRAF48::V2SvkModel &model) const +{ + auto *wfrage = model.mutable_wfrage(); + if (wfrage != nullptr) + { + const auto &items = m_tests.at(0).items(); + + wfrage->set_affe1(items[0].isChecked()); + wfrage->set_affe2(items[1].isChecked()); + wfrage->set_affe3(items[2].isChecked()); + wfrage->set_affe4(items[3].isChecked()); + wfrage->set_schwein1(items[4].isChecked()); + wfrage->set_schwein2(items[5].isChecked()); + wfrage->set_schwein3(items[6].isChecked()); + wfrage->set_schwein4(items[7].isChecked()); + wfrage->set_gans1(items[8].isChecked()); + wfrage->set_gans2(items[9].isChecked()); + wfrage->set_gans3(items[10].isChecked()); + wfrage->set_gans4(items[11].isChecked()); + } + + auto *verbtrennung = model.mutable_verbtrennung1(); + if (verbtrennung != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + verbtrennung->set_affe(testItems[1].isChecked()); + verbtrennung->set_schwein(testItems[7].isChecked()); + verbtrennung->set_gans(testItems[10].isChecked()); + } +} + +void V2SvkModel::readProtoBuf(const ESGRAF48::V2SvkModel &model) +{ + const auto &wfrage = model.wfrage(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(wfrage.affe1()); + testItems[1].setState(wfrage.affe2()); + testItems[2].setState(wfrage.affe3()); + testItems[3].setState(wfrage.affe4()); + testItems[4].setState(wfrage.schwein1()); + testItems[5].setState(wfrage.schwein2()); + testItems[6].setState(wfrage.schwein3()); + testItems[7].setState(wfrage.schwein4()); + testItems[8].setState(wfrage.gans1()); + testItems[9].setState(wfrage.gans2()); + testItems[10].setState(wfrage.gans3()); + testItems[11].setState(wfrage.gans4()); + } + + const auto &verbtrennung = model.verbtrennung1(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[1].setState(verbtrennung.affe()); + testItems[7].setState(verbtrennung.schwein()); + testItems[10].setState(verbtrennung.gans()); + } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index 456c572..091e5b6 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "V2SvkModel.pb.h" class V2SvkModel : public CheckableTestModel { @@ -11,4 +12,7 @@ public: unsigned int getV2Points(); unsigned int getSvkPoints(); + + void writeProtoBuf(ESGRAF48::V2SvkModel &model) const; + void readProtoBuf(const ESGRAF48::V2SvkModel &model); }; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 12bc99f..18642ab 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -74,17 +74,25 @@ void MainWindow::openFile() closeFile(); - QFile loadFile(filename); - if (!loadFile.open(QFile::ReadOnly)) + if (true) { - qWarning("Could not open file"); - return; + std::fstream protoInFile(filename.toStdString(), std::ios::in | std::ios::binary); + m_dataModel->readProtoBuf(protoInFile); } + else + { + QFile loadFile(filename); + if (!loadFile.open(QFile::ReadOnly)) + { + qWarning("Could not open file"); + return; + } - QByteArray byteData = loadFile.readAll(); - QJsonDocument loadDoc = QJsonDocument::fromJson(byteData); + QByteArray byteData = loadFile.readAll(); + QJsonDocument loadDoc = QJsonDocument::fromJson(byteData); - m_dataModel->read(loadDoc.object()); + m_dataModel->read(loadDoc.object()); + } setWindowModified(false); setWindowTitle(filename + "[*]"); @@ -167,16 +175,24 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::saveFile(const QString &filename) { - QJsonObject saveData; - m_dataModel->write(saveData); + if (true) + { + std::fstream protoOutFile(filename.toStdString(), + std::ios::out | std::ios::trunc | std::ios::binary); + m_dataModel->writeProtoBuf(protoOutFile); + } + else + { + QJsonObject saveData; + m_dataModel->write(saveData); - QJsonDocument saveDoc(saveData); - - QFile saveFile(filename); - saveFile.open(QFile::WriteOnly); - saveFile.write(saveDoc.toJson()); - saveFile.close(); + QJsonDocument saveDoc(saveData); + QFile saveFile(filename); + saveFile.open(QFile::WriteOnly); + saveFile.write(saveDoc.toJson()); + saveFile.close(); + } qDebug() << "Wrote" << filename; setWindowTitle(filename + "[*]"); From ff615ec084b65330d7ce1ce45b502ee53b0b4e93 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 15 Nov 2018 21:44:44 +0100 Subject: [PATCH 05/14] Finished V2Svk model protobuf serialization --- source/DataModel.cpp | 4 - source/SubTests/V2Svk/V2SvkModel.cpp | 204 ++++++++++++++++----------- 2 files changed, 123 insertions(+), 85 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 2f571c1..d2e3eca 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -63,10 +63,6 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const //m_metaData.writeProtoBuf(dataModel.mutable_metadata); m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); dataModel.SerializeToOstream(&outStream); - - std::string saveData; - google::protobuf::TextFormat::PrintToString(dataModel, &saveData); - qDebug() << "Wrote:" << QString::fromStdString(saveData); } void DataModel::readProtoBuf(std::istream &inStream) diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index b86cef9..a78e5d1 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -1,46 +1,39 @@ #include "V2SvkModel.h" V2SvkModel::V2SvkModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { - { "W-Frage", - { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", - "Gans" , "Gans", "Gans", "Gans"} }, - { "Verbtrennung", - { "", "Affe", "", "", "", "", "", "Schwein", "" , "", "Gans", ""} }, - { "SVK: /-st/", - { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", - "Gans" , "Gans", "Gans", "Gans"} }, + m_tests = { + {"W-Frage", + {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", + "Gans", "Gans", "Gans"}}, + {"Verbtrennung", {"", "Affe", "", "", "", "", "", "Schwein", "", "", "Gans", ""}}, + {"SVK: /-st/", + {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", + "Gans", "Gans", "Gans"}}, - { "Objekt-Topikalisierung", - { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", - "Gans" , "Gans", "Gans", "Gans"} }, - { "SVK: Stamm", - { "Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", - "Gans" , "Gans", "Gans", "Gans"} }, + {"Objekt-Topikalisierung", + {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", + "Gans", "Gans", "Gans"}}, + {"SVK: Stamm", + {"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans", + "Gans", "Gans", "Gans"}}, - { "Temporaladverb Präsens", - { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, - { "SKV: /-e/ o. Stamm", - { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + {"Temporaladverb Präsens", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + {"SKV: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, - { "Temporaladverb Perfekt", - { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, - { "Verbtrennung", - { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, - { "SVK: /-e/ o. Stamm", - { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, - { "Partizip", - { "Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans" } }, + {"Temporaladverb Perfekt", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + {"Verbtrennung", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + {"SVK: /-e/ o. Stamm", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, + {"Partizip", {"Affe", "Affe", "Schwein", "Schwein", "Gans", "Gans"}}, }; } unsigned int V2SvkModel::getV2Points() { - unsigned int points = 0; + unsigned int points = 0; - for (auto testIndex : { 0, 1, 3, 5, 7, 8 }) + for (auto testIndex : {0, 1, 3, 5, 7, 8}) { const auto &test = m_tests.at(testIndex); @@ -58,9 +51,9 @@ unsigned int V2SvkModel::getV2Points() unsigned int V2SvkModel::getSvkPoints() { - unsigned int points = 0; + unsigned int points = 0; - for (auto testIndex : { 2, 4, 6, 9, 10 }) + for (auto testIndex : {2, 4, 6, 9, 10}) { const auto &test = m_tests.at(testIndex); @@ -78,64 +71,113 @@ unsigned int V2SvkModel::getSvkPoints() void V2SvkModel::writeProtoBuf(ESGRAF48::V2SvkModel &model) const { - auto *wfrage = model.mutable_wfrage(); - if (wfrage != nullptr) - { - const auto &items = m_tests.at(0).items(); + auto writeOneVal = [&](ESGRAF48::V2SvkModel::OneEach *modelData, int testIndex) { + if (modelData != nullptr) + { + const auto &testItems = m_tests.at(testIndex).items(); - wfrage->set_affe1(items[0].isChecked()); - wfrage->set_affe2(items[1].isChecked()); - wfrage->set_affe3(items[2].isChecked()); - wfrage->set_affe4(items[3].isChecked()); - wfrage->set_schwein1(items[4].isChecked()); - wfrage->set_schwein2(items[5].isChecked()); - wfrage->set_schwein3(items[6].isChecked()); - wfrage->set_schwein4(items[7].isChecked()); - wfrage->set_gans1(items[8].isChecked()); - wfrage->set_gans2(items[9].isChecked()); - wfrage->set_gans3(items[10].isChecked()); - wfrage->set_gans4(items[11].isChecked()); - } + modelData->set_affe(testItems[1].isChecked()); + modelData->set_schwein(testItems[7].isChecked()); + modelData->set_gans(testItems[10].isChecked()); + } + }; - auto *verbtrennung = model.mutable_verbtrennung1(); - if (verbtrennung != nullptr) - { - const auto &testItems = m_tests.at(1).items(); + auto writeTwoVals = [&](ESGRAF48::V2SvkModel::TwoEach *modelData, int testIndex) { + if (modelData != nullptr) + { + const auto &testItems = m_tests.at(testIndex).items(); - verbtrennung->set_affe(testItems[1].isChecked()); - verbtrennung->set_schwein(testItems[7].isChecked()); - verbtrennung->set_gans(testItems[10].isChecked()); - } + modelData->set_affe1(testItems[0].isChecked()); + modelData->set_affe2(testItems[1].isChecked()); + modelData->set_schwein1(testItems[2].isChecked()); + modelData->set_schwein2(testItems[3].isChecked()); + modelData->set_gans1(testItems[4].isChecked()); + modelData->set_gans2(testItems[5].isChecked()); + } + }; + + auto writeFourVals = [&](ESGRAF48::V2SvkModel::FourEach *modelData, int testIndex) { + if (modelData != nullptr) + { + const auto &testItems = m_tests.at(testIndex).items(); + + modelData->set_affe1(testItems[0].isChecked()); + modelData->set_affe2(testItems[1].isChecked()); + modelData->set_affe3(testItems[2].isChecked()); + modelData->set_affe4(testItems[3].isChecked()); + modelData->set_schwein1(testItems[4].isChecked()); + modelData->set_schwein2(testItems[5].isChecked()); + modelData->set_schwein3(testItems[6].isChecked()); + modelData->set_schwein4(testItems[7].isChecked()); + modelData->set_gans1(testItems[8].isChecked()); + modelData->set_gans2(testItems[9].isChecked()); + modelData->set_gans3(testItems[10].isChecked()); + modelData->set_gans4(testItems[11].isChecked()); + } + }; + + writeFourVals(model.mutable_wfrage(), 0); + writeOneVal(model.mutable_verbtrennung1(), 1); + writeFourVals(model.mutable_svkst(), 2); + writeFourVals(model.mutable_objtop(), 3); + writeFourVals(model.mutable_svkstamm(), 4); + writeTwoVals(model.mutable_temppraes(), 5); + writeTwoVals(model.mutable_svke1(), 6); + writeTwoVals(model.mutable_tempperf(), 7); + writeTwoVals(model.mutable_verbtrennung2(), 8); + writeTwoVals(model.mutable_svke2(), 9); + writeTwoVals(model.mutable_partizip(), 10); } - + void V2SvkModel::readProtoBuf(const ESGRAF48::V2SvkModel &model) { - const auto &wfrage = model.wfrage(); - { - auto &testItems = m_tests.at(0).items(); + auto readOneVal = [&](const ESGRAF48::V2SvkModel::OneEach &modelData, int testIndex) { + auto &testItems = m_tests.at(testIndex).items(); - testItems[0].setState(wfrage.affe1()); - testItems[1].setState(wfrage.affe2()); - testItems[2].setState(wfrage.affe3()); - testItems[3].setState(wfrage.affe4()); - testItems[4].setState(wfrage.schwein1()); - testItems[5].setState(wfrage.schwein2()); - testItems[6].setState(wfrage.schwein3()); - testItems[7].setState(wfrage.schwein4()); - testItems[8].setState(wfrage.gans1()); - testItems[9].setState(wfrage.gans2()); - testItems[10].setState(wfrage.gans3()); - testItems[11].setState(wfrage.gans4()); - } + testItems[1].setState(modelData.affe()); + testItems[7].setState(modelData.schwein()); + testItems[10].setState(modelData.gans()); + }; - const auto &verbtrennung = model.verbtrennung1(); - { - auto &testItems = m_tests.at(1).items(); + auto readTwoVals = [&](const ESGRAF48::V2SvkModel::TwoEach &modelData, int testIndex) { + auto &testItems = m_tests.at(testIndex).items(); - testItems[1].setState(verbtrennung.affe()); - testItems[7].setState(verbtrennung.schwein()); - testItems[10].setState(verbtrennung.gans()); - } + testItems[0].setState(modelData.affe1()); + testItems[1].setState(modelData.affe2()); + testItems[2].setState(modelData.schwein1()); + testItems[3].setState(modelData.schwein2()); + testItems[4].setState(modelData.gans1()); + testItems[5].setState(modelData.gans2()); + }; + + auto readFourVals = [&](const ESGRAF48::V2SvkModel::FourEach &modelData, int testIndex) { + auto &testItems = m_tests.at(testIndex).items(); + + testItems[0].setState(modelData.affe1()); + testItems[1].setState(modelData.affe2()); + testItems[2].setState(modelData.affe3()); + testItems[3].setState(modelData.affe4()); + testItems[4].setState(modelData.schwein1()); + testItems[5].setState(modelData.schwein2()); + testItems[6].setState(modelData.schwein3()); + testItems[7].setState(modelData.schwein4()); + testItems[8].setState(modelData.gans1()); + testItems[9].setState(modelData.gans2()); + testItems[10].setState(modelData.gans3()); + testItems[11].setState(modelData.gans4()); + }; + + readFourVals(model.wfrage(), 0); + readOneVal(model.verbtrennung1(), 1); + readFourVals(model.svkst(), 2); + readFourVals(model.objtop(), 3); + readFourVals(model.svkstamm(), 4); + readTwoVals(model.temppraes(), 5); + readTwoVals(model.svke1(), 6); + readTwoVals(model.tempperf(), 7); + readTwoVals(model.verbtrennung2(), 8); + readTwoVals(model.svke2(), 9); + readTwoVals(model.partizip(), 10); emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } From e77990a86a3948d8b3820c931cd96f14f85906d1 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 16 Nov 2018 22:29:41 +0100 Subject: [PATCH 06/14] Removed non-working MetaDataModel --- .gitignore | 1 + proto/DataModel.proto | 2 -- proto/MetaDataModel.proto | 8 -------- source/CMakeLists.txt | 1 - source/MetaData/CMakeLists.txt | 13 ------------- source/MetaData/MetaDataModel.h | 4 ---- 6 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 proto/MetaDataModel.proto diff --git a/.gitignore b/.gitignore index 627e015..e42f4b6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ compile_commands.json _*/ build-* *.user +tags diff --git a/proto/DataModel.proto b/proto/DataModel.proto index bd21edb..3439b4a 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -2,11 +2,9 @@ syntax = "proto3"; package ESGRAF48; -import "MetaDataModel.proto"; import "V2SvkModel.proto"; message DataModel { - MetaDataModel MetaData = 1; V2SvkModel V2Svk = 2; } diff --git a/proto/MetaDataModel.proto b/proto/MetaDataModel.proto deleted file mode 100644 index 1b75c36..0000000 --- a/proto/MetaDataModel.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -package ESGRAF48; - -message MetaDataModel -{ - string dummy = 1; -} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 410e0fe..29ceccf 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -19,7 +19,6 @@ qt5_add_resources(LOGO_TEST_QRC set(DataModel_PROTO_FILES ../proto/DataModel.proto - ../proto/MetaDataModel.proto ../proto/V2SvkModel.proto ) diff --git a/source/MetaData/CMakeLists.txt b/source/MetaData/CMakeLists.txt index d8a6379..01aa53f 100644 --- a/source/MetaData/CMakeLists.txt +++ b/source/MetaData/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.6) project(MetaData LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) -find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -11,20 +10,10 @@ qt5_wrap_ui(META_DATA_UI MetaDataWidget.ui ) -set(MetaDataModel_PROTO_FILES - ../../proto/MetaDataModel.proto -) - -protobuf_generate_cpp(MetaDataModel_PROTO_SRCS MetaDataModel_PROTO_HDRS - ${MetaDataModel_PROTO_FILES} -) - add_library(${PROJECT_NAME} MetaDataModel.cpp MetaDataWidget.cpp ${META_DATA_UI} - ${MetaDateModel_PROTO_SRCS} - ${MetaDateModel_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -34,7 +23,6 @@ set_target_properties(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} - ${Protobuf_INCLUDE_DIRS} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -42,5 +30,4 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets - ${Protobuf_LIBRARIES} ) diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 1de7a0f..6c81f8a 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -2,8 +2,6 @@ #include "../Age.h" -//#include "MetaDataModel.pb.h" - #include #include #include @@ -33,8 +31,6 @@ public: void write(QJsonObject &json) const; void read(const QJsonObject &json); - //void writeProtoBuf(ESGRAF48::MetaDataModel &model) const; - std::string toHtml() const; Age getAge() const From 56ca796df04f3dcfa9089828c31e670c36d792cd Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 16 Nov 2018 23:21:02 +0100 Subject: [PATCH 07/14] Ported MetaDataModel to protobuf --- proto/DataModel.proto | 2 ++ proto/MetaDataModel.proto | 12 ++++++++++++ source/CMakeLists.txt | 1 + source/DataModel.cpp | 7 ++++--- source/MetaData/CMakeLists.txt | 13 +++++++++++++ source/MetaData/MetaDataModel.cpp | 20 +++++++++++++++++--- source/MetaData/MetaDataModel.h | 5 +++++ 7 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 proto/MetaDataModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto index 3439b4a..bd21edb 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -2,9 +2,11 @@ syntax = "proto3"; package ESGRAF48; +import "MetaDataModel.proto"; import "V2SvkModel.proto"; message DataModel { + MetaDataModel MetaData = 1; V2SvkModel V2Svk = 2; } diff --git a/proto/MetaDataModel.proto b/proto/MetaDataModel.proto new file mode 100644 index 0000000..fba068d --- /dev/null +++ b/proto/MetaDataModel.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package ESGRAF48; + +message MetaDataModel +{ + string ParticipantName = 1; + string InstructorName = 2; + string DateOfBirth = 3; + string DateOfTest = 4; + string Remarks = 5; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 29ceccf..410e0fe 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -19,6 +19,7 @@ qt5_add_resources(LOGO_TEST_QRC set(DataModel_PROTO_FILES ../proto/DataModel.proto + ../proto/MetaDataModel.proto ../proto/V2SvkModel.proto ) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index d2e3eca..ad78dc5 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -3,8 +3,6 @@ #include "DataModel.pb.h" #include -#include - #include DataModel::DataModel(QObject *parent) @@ -60,8 +58,10 @@ void DataModel::read(const QJsonObject &source) void DataModel::writeProtoBuf(std::ostream &outStream) const { ESGRAF48::DataModel dataModel; - //m_metaData.writeProtoBuf(dataModel.mutable_metadata); + + m_metaData.writeProtoBuf(*dataModel.mutable_metadata()); m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); + dataModel.SerializeToOstream(&outStream); } @@ -70,6 +70,7 @@ void DataModel::readProtoBuf(std::istream &inStream) ESGRAF48::DataModel dataModel; dataModel.ParseFromIstream(&inStream); + m_metaData.readProtoBuf(dataModel.metadata()); m_v2Svk.readProtoBuf(dataModel.v2svk()); } diff --git a/source/MetaData/CMakeLists.txt b/source/MetaData/CMakeLists.txt index 01aa53f..b61703a 100644 --- a/source/MetaData/CMakeLists.txt +++ b/source/MetaData/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(MetaData LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,10 +11,20 @@ qt5_wrap_ui(META_DATA_UI MetaDataWidget.ui ) +set(MetaDataModel_PROTO_FILES + ../../proto/MetaDataModel.proto +) + +protobuf_generate_cpp(MetaDataModel_PROTO_SRCS MetaDataModel_PROTO_HDRS + ${MetaDataModel_PROTO_FILES} +) + add_library(${PROJECT_NAME} MetaDataModel.cpp MetaDataWidget.cpp ${META_DATA_UI} + ${MetaDataModel_PROTO_SRCS} + ${MetaDataModel_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -23,6 +34,7 @@ set_target_properties(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -30,4 +42,5 @@ target_include_directories(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 1877777..8bf51af 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -130,9 +130,23 @@ void MetaDataModel::read(const QJsonObject &json) setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole); } -//void MetaDataModel::writeProtoBuf(ESGRAF48::MetaDataModel &model) const -//{ -//} +void MetaDataModel::readProtoBuf(const ESGRAF48::MetaDataModel &model) +{ + setData(index(0, 0), QString::fromStdString(model.participantname())); + setData(index(0, 1), QString::fromStdString(model.instructorname())); + setData(index(0, 2), QString::fromStdString(model.dateofbirth())); + setData(index(0, 3), QString::fromStdString(model.dateoftest())); + setData(index(0, 4), QString::fromStdString(model.remarks())); +} + +void MetaDataModel::writeProtoBuf(ESGRAF48::MetaDataModel &model) const +{ + model.set_participantname(m_participant.toStdString()); + model.set_instructorname(m_instructor.toStdString()); + model.set_dateofbirth(m_dateOfBirth.toString(Qt::ISODate).toStdString()); + model.set_dateoftest(m_dateOfTest.toString(Qt::ISODate).toStdString()); + model.set_remarks(m_remarks.toStdString()); +} std::string MetaDataModel::toHtml() const { diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 6c81f8a..1b216d6 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -2,6 +2,8 @@ #include "../Age.h" +#include "MetaDataModel.pb.h" + #include #include #include @@ -31,6 +33,9 @@ public: void write(QJsonObject &json) const; void read(const QJsonObject &json); + void readProtoBuf(const ESGRAF48::MetaDataModel &model); + void writeProtoBuf(ESGRAF48::MetaDataModel &model) const; + std::string toHtml() const; Age getAge() const From a2c4b16eb43615ae4a661c7fd528f0b56f8162f4 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 17 Nov 2018 01:19:03 +0100 Subject: [PATCH 08/14] Made empty fields in V2Svk test uncheckable and uncountable, solves #3 --- source/CheckableTestModel/CheckableTestModel.h | 5 +++-- source/SubTests/V2Svk/V2SvkModel.cpp | 18 ++++++++++++++++++ source/SubTests/V2Svk/V2SvkModel.h | 3 +++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index ee67c7b..7b4ed9d 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -30,9 +30,10 @@ public: unsigned int getPoints() const; -private: - bool isValidIndex(const QModelIndex &index) const; +protected: + virtual bool isValidIndex(const QModelIndex &index) const; +private: CheckableItems &getItems(const QModelIndex &index); const CheckableItems &getItems(const QModelIndex &index) const; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index a78e5d1..6d7b373 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -69,6 +69,24 @@ unsigned int V2SvkModel::getSvkPoints() return points; } +bool V2SvkModel::isValidIndex(const QModelIndex &index) const +{ + switch (index.row()) + { + case 1: + return index.column() == 1 || index.column() == 7 || index.column() == 10; + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + return index.column() < 6; + default: + return CheckableTestModel::isValidIndex(index); + } +} + void V2SvkModel::writeProtoBuf(ESGRAF48::V2SvkModel &model) const { auto writeOneVal = [&](ESGRAF48::V2SvkModel::OneEach *modelData, int testIndex) { diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index 091e5b6..a574ac3 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -15,4 +15,7 @@ public: void writeProtoBuf(ESGRAF48::V2SvkModel &model) const; void readProtoBuf(const ESGRAF48::V2SvkModel &model); + +protected: + bool isValidIndex(const QModelIndex &index) const override; }; From 09d811ee252137198571df92e23f808ce03e2975 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 17 Nov 2018 11:57:59 +0100 Subject: [PATCH 09/14] Removed obsolete json read/writes --- source/DataModel.cpp | 26 -------------------- source/DataModel.h | 3 --- source/MetaData/MetaDataModel.cpp | 18 -------------- source/MetaData/MetaDataModel.h | 3 --- source/mainwindow.cpp | 41 ++++--------------------------- 5 files changed, 5 insertions(+), 86 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index ad78dc5..ba97a59 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -29,32 +29,6 @@ DataModel::DataModel(QObject *parent) connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); } -void DataModel::write(QJsonObject &target) const -{ - write(m_metaData, target, "MetaData"); - write(m_verbEnd, target, "VerbEnd"); - write(m_genus, target, "Genus"); - write(m_plural, target, "Plural"); - write(m_akkusativ, target, "Akkusativ"); - write(m_dativ, target, "Dativ"); - write(m_v2Svk, target, "V2Svk"); - write(m_passiv, target, "Passiv"); - write(m_genitiv, target, "Genitiv"); -} - -void DataModel::read(const QJsonObject &source) -{ - read(m_metaData, source, "MetaData"); - read(m_verbEnd, source, "VerbEnd"); - read(m_genus, source, "Genus"); - read(m_plural, source, "Plural"); - read(m_akkusativ, source, "Akkusativ"); - read(m_dativ, source, "Dativ"); - read(m_v2Svk, source, "V2Svk"); - read(m_passiv, source, "Passiv"); - read(m_genitiv, source, "Genitiv"); -} - void DataModel::writeProtoBuf(std::ostream &outStream) const { ESGRAF48::DataModel dataModel; diff --git a/source/DataModel.h b/source/DataModel.h index 2ac876d..4030321 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -34,9 +34,6 @@ public: public: DataModel(QObject *parent); - void write(QJsonObject &target) const; - void read(const QJsonObject &source); - std::string toHtml() const; void writeProtoBuf(std::ostream &outStream) const; diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 8bf51af..cc5dd87 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -112,24 +112,6 @@ bool MetaDataModel::setData(const QModelIndex &modelIndex, const QVariant &value return valueChanged; } -void MetaDataModel::write(QJsonObject &json) const -{ - json["participant name"] = m_participant; - json["instructor name"] = m_instructor; - json["date of birth"] = m_dateOfBirth.toString(Qt::ISODate); - json["date of test"] = m_dateOfTest.toString(Qt::ISODate); - json["remarks"] = m_remarks; -} - -void MetaDataModel::read(const QJsonObject &json) -{ - setData(index(0, 0), json["participant name"].toVariant(), Qt::EditRole); - setData(index(0, 1), json["instructor name"].toVariant(), Qt::EditRole); - setData(index(0, 2), json["date of birth"].toVariant(), Qt::EditRole); - setData(index(0, 3), json["date of test"].toVariant(), Qt::EditRole); - setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole); -} - void MetaDataModel::readProtoBuf(const ESGRAF48::MetaDataModel &model) { setData(index(0, 0), QString::fromStdString(model.participantname())); diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 1b216d6..78a9e14 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -30,9 +30,6 @@ public: bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - void write(QJsonObject &json) const; - void read(const QJsonObject &json); - void readProtoBuf(const ESGRAF48::MetaDataModel &model); void writeProtoBuf(ESGRAF48::MetaDataModel &model) const; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 18642ab..0d86a4d 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -74,25 +74,8 @@ void MainWindow::openFile() closeFile(); - if (true) - { - std::fstream protoInFile(filename.toStdString(), std::ios::in | std::ios::binary); - m_dataModel->readProtoBuf(protoInFile); - } - else - { - QFile loadFile(filename); - if (!loadFile.open(QFile::ReadOnly)) - { - qWarning("Could not open file"); - return; - } - - QByteArray byteData = loadFile.readAll(); - QJsonDocument loadDoc = QJsonDocument::fromJson(byteData); - - m_dataModel->read(loadDoc.object()); - } + std::fstream protoInFile(filename.toStdString(), std::ios::in | std::ios::binary); + m_dataModel->readProtoBuf(protoInFile); setWindowModified(false); setWindowTitle(filename + "[*]"); @@ -175,24 +158,10 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::saveFile(const QString &filename) { - if (true) - { - std::fstream protoOutFile(filename.toStdString(), - std::ios::out | std::ios::trunc | std::ios::binary); - m_dataModel->writeProtoBuf(protoOutFile); - } - else - { - QJsonObject saveData; - m_dataModel->write(saveData); + std::fstream protoOutFile(filename.toStdString(), + std::ios::out | std::ios::trunc | std::ios::binary); + m_dataModel->writeProtoBuf(protoOutFile); - QJsonDocument saveDoc(saveData); - - QFile saveFile(filename); - saveFile.open(QFile::WriteOnly); - saveFile.write(saveDoc.toJson()); - saveFile.close(); - } qDebug() << "Wrote" << filename; setWindowTitle(filename + "[*]"); From 62a90d56363323e5e3d538c30592b21f365e6b72 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 17 Nov 2018 15:55:40 +0100 Subject: [PATCH 10/14] Converted VerbEndModel to protobuf serialization --- proto/DataModel.proto | 2 + proto/VerbEndModel.proto | 42 ++++++++++++ source/CMakeLists.txt | 1 + source/DataModel.cpp | 2 + source/SubTests/VerbEnd/CMakeLists.txt | 11 +++ source/SubTests/VerbEnd/VerbEndModel.cpp | 87 ++++++++++++++++++++++++ source/SubTests/VerbEnd/VerbEndModel.h | 4 ++ 7 files changed, 149 insertions(+) create mode 100644 proto/VerbEndModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto index bd21edb..a0b0128 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -4,9 +4,11 @@ package ESGRAF48; import "MetaDataModel.proto"; import "V2SvkModel.proto"; +import "VerbEndModel.proto"; message DataModel { MetaDataModel MetaData = 1; V2SvkModel V2Svk = 2; + VerbEndModel VerbEnd = 3; } diff --git a/proto/VerbEndModel.proto b/proto/VerbEndModel.proto new file mode 100644 index 0000000..84dfa96 --- /dev/null +++ b/proto/VerbEndModel.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +package ESGRAF48; + +message VerbEndModel +{ + message TelefonatModel + { + bool Kausal1 = 1; + bool Kausal2 = 2; + bool Relativ = 3; + bool Kausal3 = 4; + bool Final = 5; + bool Temporal1 = 6; + bool Temporal2 = 7; + } + + message ZaubertrickModel + { + bool Relativ = 1; + bool Final1 = 2; + bool Kausal1 = 3; + bool Final2 = 4; + bool Temporal1 = 5; + bool Kausal2 = 6; + bool Temporal2 = 7; + } + + message ZauberregelModel + { + bool Temporal1 = 1; + bool Kausal = 2; + bool Final = 3; + bool Relativ1 = 4; + bool Temporal2 = 5; + bool Relativ2 = 6; + } + + TelefonatModel Telefonat = 1; + ZaubertrickModel Zaubertrick = 2; + ZauberregelModel Zauberregel = 3; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 410e0fe..61e5d50 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -21,6 +21,7 @@ set(DataModel_PROTO_FILES ../proto/DataModel.proto ../proto/MetaDataModel.proto ../proto/V2SvkModel.proto + ../proto/VerbEndModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index ba97a59..d0119e7 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -35,6 +35,7 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_metaData.writeProtoBuf(*dataModel.mutable_metadata()); m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); + m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend()); dataModel.SerializeToOstream(&outStream); } @@ -46,6 +47,7 @@ void DataModel::readProtoBuf(std::istream &inStream) m_metaData.readProtoBuf(dataModel.metadata()); m_v2Svk.readProtoBuf(dataModel.v2svk()); + m_verbEnd.readProtoBuf(dataModel.verbend()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/VerbEnd/CMakeLists.txt b/source/SubTests/VerbEnd/CMakeLists.txt index c65fca1..1302223 100644 --- a/source/SubTests/VerbEnd/CMakeLists.txt +++ b/source/SubTests/VerbEnd/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(VerbEnd LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,10 +11,18 @@ qt5_wrap_ui(UI_HEADERS VerbEndWidget.ui ) +set(VerbEnd_PROTO_FILES + ../../../proto/VerbEndModel.proto +) + +protobuf_generate_cpp(VerbEnd_PROTO_SRCS VerbEnd_PROTO_HDRS ${VerbEnd_PROTO_FILES}) + add_library(${PROJECT_NAME} VerbEndWidget.cpp VerbEndModel.cpp ${UI_HEADERS} + ${VerbEnd_PROTO_SRCS} + ${VerbEnd_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/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index bbda111..9df5e5d 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -11,3 +11,90 @@ VerbEndModel::VerbEndModel(QObject *parent) { "Zauberregel", { "Temporal", "Kausal", "Final", "Relativ", "Temporal", "Relativ" } } }; } + +void VerbEndModel::writeProtoBuf(ESGRAF48::VerbEndModel &model) const +{ + auto *telefonatModel = model.mutable_telefonat(); + if (telefonatModel != nullptr) + { + const auto &testItems = m_tests.at(0).items(); + + telefonatModel->set_kausal1(testItems[0].isChecked()); + telefonatModel->set_kausal2(testItems[1].isChecked()); + telefonatModel->set_relativ(testItems[2].isChecked()); + telefonatModel->set_kausal3(testItems[3].isChecked()); + telefonatModel->set_final(testItems[4].isChecked()); + telefonatModel->set_temporal1(testItems[5].isChecked()); + telefonatModel->set_temporal2(testItems[6].isChecked()); + } + + auto *zaubertrickModel = model.mutable_zaubertrick(); + if (zaubertrickModel != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + zaubertrickModel->set_relativ(testItems[0].isChecked()); + zaubertrickModel->set_final1(testItems[1].isChecked()); + zaubertrickModel->set_kausal1(testItems[2].isChecked()); + zaubertrickModel->set_final2(testItems[3].isChecked()); + zaubertrickModel->set_temporal1(testItems[4].isChecked()); + zaubertrickModel->set_kausal2(testItems[5].isChecked()); + zaubertrickModel->set_temporal2(testItems[6].isChecked()); + } + + auto *zauberregelModel = model.mutable_zauberregel(); + if (zauberregelModel != nullptr) + { + const auto &testItems = m_tests.at(2).items(); + + zauberregelModel->set_temporal1(testItems[0].isChecked()); + zauberregelModel->set_kausal(testItems[1].isChecked()); + zauberregelModel->set_final(testItems[2].isChecked()); + zauberregelModel->set_relativ1(testItems[3].isChecked()); + zauberregelModel->set_temporal2(testItems[4].isChecked()); + zauberregelModel->set_relativ2(testItems[5].isChecked()); + } +} + +void VerbEndModel::readProtoBuf(const ESGRAF48::VerbEndModel &model) +{ + const auto &telefonatModel = model.telefonat(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(telefonatModel.kausal1()); + testItems[1].setState(telefonatModel.kausal2()); + testItems[2].setState(telefonatModel.relativ()); + testItems[3].setState(telefonatModel.kausal3()); + testItems[4].setState(telefonatModel.final()); + testItems[5].setState(telefonatModel.temporal1()); + testItems[6].setState(telefonatModel.temporal2()); + } + + const auto &zaubertrickModel = model.zaubertrick(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[0].setState(zaubertrickModel.relativ()); + testItems[1].setState(zaubertrickModel.final1()); + testItems[2].setState(zaubertrickModel.kausal1()); + testItems[3].setState(zaubertrickModel.final2()); + testItems[4].setState(zaubertrickModel.temporal1()); + testItems[5].setState(zaubertrickModel.kausal2()); + testItems[6].setState(zaubertrickModel.temporal2()); + } + + const auto &zauberregelModel = model.zauberregel(); + { + auto &testItems = m_tests.at(2).items(); + + testItems[0].setState(zauberregelModel.temporal1()); + testItems[1].setState(zauberregelModel.kausal()); + testItems[2].setState(zauberregelModel.final()); + testItems[3].setState(zauberregelModel.relativ1()); + testItems[4].setState(zauberregelModel.temporal2()); + testItems[5].setState(zauberregelModel.relativ2()); + } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); +} diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index 42ac7d4..ea729fc 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "VerbEndModel.pb.h" class VerbEndModel : public CheckableTestModel { @@ -8,4 +9,7 @@ class VerbEndModel : public CheckableTestModel public: VerbEndModel(QObject *parent); + + void writeProtoBuf(ESGRAF48::VerbEndModel &model) const; + void readProtoBuf(const ESGRAF48::VerbEndModel &model); }; From ef54685bce7ee9cf7311a9c15b48c1935d0d238b Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 18 Nov 2018 15:27:00 +0100 Subject: [PATCH 11/14] Ported GenusModel from json to protobuf --- proto/DataModel.proto | 2 + proto/GenusModel.proto | 42 ++++++++++++ source/CMakeLists.txt | 1 + source/DataModel.cpp | 4 +- source/SubTests/Genus/CMakeLists.txt | 12 ++++ source/SubTests/Genus/GenusModel.cpp | 96 ++++++++++++++++++++++++++-- source/SubTests/Genus/GenusModel.h | 4 ++ 7 files changed, 153 insertions(+), 8 deletions(-) create mode 100644 proto/GenusModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto index a0b0128..c5df198 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -5,10 +5,12 @@ package ESGRAF48; import "MetaDataModel.proto"; import "V2SvkModel.proto"; import "VerbEndModel.proto"; +import "GenusModel.proto"; message DataModel { MetaDataModel MetaData = 1; V2SvkModel V2Svk = 2; VerbEndModel VerbEnd = 3; + GenusModel Genus = 4; } diff --git a/proto/GenusModel.proto b/proto/GenusModel.proto new file mode 100644 index 0000000..26c24cf --- /dev/null +++ b/proto/GenusModel.proto @@ -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; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 61e5d50..33df521 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -22,6 +22,7 @@ set(DataModel_PROTO_FILES ../proto/MetaDataModel.proto ../proto/V2SvkModel.proto ../proto/VerbEndModel.proto + ../proto/GenusModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index d0119e7..7c346e4 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -1,7 +1,5 @@ #include "DataModel.h" - #include "DataModel.pb.h" -#include #include @@ -36,6 +34,7 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_metaData.writeProtoBuf(*dataModel.mutable_metadata()); m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend()); + m_genus.writeProtoBuf(*dataModel.mutable_genus()); dataModel.SerializeToOstream(&outStream); } @@ -48,6 +47,7 @@ void DataModel::readProtoBuf(std::istream &inStream) m_metaData.readProtoBuf(dataModel.metadata()); m_v2Svk.readProtoBuf(dataModel.v2svk()); m_verbEnd.readProtoBuf(dataModel.verbend()); + m_genus.readProtoBuf(dataModel.genus()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/Genus/CMakeLists.txt b/source/SubTests/Genus/CMakeLists.txt index 96bad12..28fe2ef 100644 --- a/source/SubTests/Genus/CMakeLists.txt +++ b/source/SubTests/Genus/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(Genus LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,10 +11,19 @@ qt5_wrap_ui(GENUS_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} GenusWidget.cpp GenusModel.cpp ${GENUS_UI} + ${Genus_PROTO_SRCS} + ${Genus_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -25,6 +35,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 +44,5 @@ target_link_libraries(${PROJECT_NAME} CheckableTest CheckableTestModel Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index 797e5a1..0977ce9 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -1,11 +1,95 @@ #include "GenusModel.h" GenusModel::GenusModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { { "Tiere", { "Tiger", "Bär", "Katze", "Pferd", "Gans", - "Elefant", "Affe", "Hund" } }, - { "Futter", { "Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", - "Honig", "Zucker" } }, - { "Zirkus", { "Kiste", "Holz", "Vorhang", "Baum" } } }; + m_tests = {{"Tiere", {"Tiger", "Bär", "Katze", "Pferd", "Gans", "Elefant", "Affe", "Hund"}}, + {"Futter", + {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}, + {"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()); + } } diff --git a/source/SubTests/Genus/GenusModel.h b/source/SubTests/Genus/GenusModel.h index 24f297a..3dd8dc9 100644 --- a/source/SubTests/Genus/GenusModel.h +++ b/source/SubTests/Genus/GenusModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "GenusModel.pb.h" class GenusModel : public CheckableTestModel { @@ -8,4 +9,7 @@ class GenusModel : public CheckableTestModel public: GenusModel(QObject *parent); + + void readProtoBuf(const ESGRAF48::GenusModel &model); + void writeProtoBuf(ESGRAF48::GenusModel &model) const; }; From 843164a3bf24804861582061e5ad88f4ee6fd89e Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 18 Nov 2018 17:12:03 +0100 Subject: [PATCH 12/14] Ported Akkusativ and Dativ model to protobuf --- proto/AkkusativModel.proto | 46 ++++++++ proto/DataModel.proto | 4 + proto/DativModel.proto | 46 ++++++++ source/CMakeLists.txt | 2 + source/DataModel.cpp | 4 + .../AkkusativDativ/AkkusativModel.cpp | 110 ++++++++++++++++-- .../SubTests/AkkusativDativ/AkkusativModel.h | 4 + source/SubTests/AkkusativDativ/CMakeLists.txt | 14 +++ source/SubTests/AkkusativDativ/DativModel.cpp | 110 ++++++++++++++++-- source/SubTests/AkkusativDativ/DativModel.h | 4 + source/SubTests/Genus/CMakeLists.txt | 1 - 11 files changed, 324 insertions(+), 21 deletions(-) create mode 100644 proto/AkkusativModel.proto create mode 100644 proto/DativModel.proto diff --git a/proto/AkkusativModel.proto b/proto/AkkusativModel.proto new file mode 100644 index 0000000..930160d --- /dev/null +++ b/proto/AkkusativModel.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; + +package ESGRAF48; + +message AkkusativModel +{ + message TiereModel + { + bool Tiger = 1; + bool Katze = 2; + bool Affe = 3; + bool Gans = 4; + bool Baer = 5; + bool Pferd = 6; + bool Hund = 7; + bool Elefant = 8; + } + + message VersteckeModel + { + bool Vorhang1 = 1; + bool Kiste1 = 2; + bool Holz1 = 3; + bool Kiste2 = 4; + bool Baum1 = 5; + bool Vorhang2 = 6; + bool Holz2 = 7; + bool Baum2 = 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; + } + + TiereModel Tiere = 1; + VersteckeModel Verstecke = 2; + FutterModel Futter = 3; +} diff --git a/proto/DataModel.proto b/proto/DataModel.proto index c5df198..c04f473 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -6,6 +6,8 @@ import "MetaDataModel.proto"; import "V2SvkModel.proto"; import "VerbEndModel.proto"; import "GenusModel.proto"; +import "AkkusativModel.proto"; +import "DativModel.proto"; message DataModel { @@ -13,4 +15,6 @@ message DataModel V2SvkModel V2Svk = 2; VerbEndModel VerbEnd = 3; GenusModel Genus = 4; + AkkusativModel Akkusativ = 5; + DativModel Dativ = 6; } diff --git a/proto/DativModel.proto b/proto/DativModel.proto new file mode 100644 index 0000000..b3bb021 --- /dev/null +++ b/proto/DativModel.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; + +package ESGRAF48; + +message DativModel +{ + message TiereModel + { + bool Tiger = 1; + bool Katze = 2; + bool Affe = 3; + bool Gans = 4; + bool Baer = 5; + bool Pferd = 6; + bool Hund = 7; + bool Elefant = 8; + } + + message VersteckeModel + { + bool Vorhang1 = 1; + bool Kiste1 = 2; + bool Holz1 = 3; + bool Kiste2 = 4; + bool Baum1 = 5; + bool Vorhang2 = 6; + bool Holz2 = 7; + bool Baum2 = 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; + } + + TiereModel Tiere = 1; + VersteckeModel Verstecke = 2; + FutterModel Futter = 3; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 33df521..6180070 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -23,6 +23,8 @@ set(DataModel_PROTO_FILES ../proto/V2SvkModel.proto ../proto/VerbEndModel.proto ../proto/GenusModel.proto + ../proto/AkkusativModel.proto + ../proto/DativModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 7c346e4..08bf4bc 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -35,6 +35,8 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend()); m_genus.writeProtoBuf(*dataModel.mutable_genus()); + m_akkusativ.write(*dataModel.mutable_akkusativ()); + m_dativ.write(*dataModel.mutable_dativ()); dataModel.SerializeToOstream(&outStream); } @@ -48,6 +50,8 @@ void DataModel::readProtoBuf(std::istream &inStream) m_v2Svk.readProtoBuf(dataModel.v2svk()); m_verbEnd.readProtoBuf(dataModel.verbend()); m_genus.readProtoBuf(dataModel.genus()); + m_akkusativ.read(dataModel.akkusativ()); + m_dativ.read(dataModel.dativ()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.cpp b/source/SubTests/AkkusativDativ/AkkusativModel.cpp index dd387f1..68d8f04 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.cpp +++ b/source/SubTests/AkkusativDativ/AkkusativModel.cpp @@ -1,15 +1,105 @@ #include "AkkusativModel.h" AkkusativModel::AkkusativModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { - { "Akkusativ Nominalphrase", { "Tiger", "Katze", "Affe", "Gans", "Bär", - "Pferd", "Hund", "Elefant" } }, - { "Präpositionalphrase (Verstecke)", - { "Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", - "Baum" } }, - { "Nominalphrase (Futter)", { "Salat", "Fleisch", "Knochen", "Banane", - "Apfel", "Karotte", "Honig", "Zucker" } } - }; + m_tests = {{"Akkusativ Nominalphrase", + {"Tiger", "Katze", "Affe", "Gans", "Bär", "Pferd", "Hund", "Elefant"}}, + {"Präpositionalphrase (Verstecke)", + {"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}}, + {"Nominalphrase (Futter)", + {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}}; +} + +void AkkusativModel::read(const ESGRAF48::AkkusativModel &model) +{ + const auto &tiereModel = model.tiere(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(tiereModel.tiger()); + testItems[1].setState(tiereModel.katze()); + testItems[2].setState(tiereModel.affe()); + testItems[3].setState(tiereModel.gans()); + testItems[4].setState(tiereModel.baer()); + testItems[5].setState(tiereModel.pferd()); + testItems[6].setState(tiereModel.hund()); + testItems[7].setState(tiereModel.elefant()); + } + + const auto &versteckeModel = model.verstecke(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[0].setState(versteckeModel.vorhang1()); + testItems[1].setState(versteckeModel.kiste1()); + testItems[2].setState(versteckeModel.holz1()); + testItems[3].setState(versteckeModel.kiste2()); + testItems[4].setState(versteckeModel.baum1()); + testItems[5].setState(versteckeModel.vorhang2()); + testItems[6].setState(versteckeModel.holz2()); + testItems[7].setState(versteckeModel.baum2()); + } + + const auto &futterModel = model.futter(); + { + auto &testItems = m_tests.at(2).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()); + } +} + +void AkkusativModel::write(ESGRAF48::AkkusativModel &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_katze(testItems[1].isChecked()); + tiereModel->set_affe(testItems[2].isChecked()); + tiereModel->set_gans(testItems[3].isChecked()); + tiereModel->set_baer(testItems[4].isChecked()); + tiereModel->set_pferd(testItems[5].isChecked()); + tiereModel->set_hund(testItems[6].isChecked()); + tiereModel->set_elefant(testItems[7].isChecked()); + } + + auto *versteckeModel = model.mutable_verstecke(); + if (versteckeModel != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + versteckeModel->set_vorhang1(testItems[0].isChecked()); + versteckeModel->set_kiste1(testItems[1].isChecked()); + versteckeModel->set_holz1(testItems[2].isChecked()); + versteckeModel->set_kiste2(testItems[3].isChecked()); + versteckeModel->set_baum1(testItems[4].isChecked()); + versteckeModel->set_vorhang2(testItems[5].isChecked()); + versteckeModel->set_holz2(testItems[6].isChecked()); + versteckeModel->set_baum2(testItems[7].isChecked()); + } + + auto *futterModel = model.mutable_futter(); + if (futterModel != nullptr) + { + const auto &testItems = m_tests.at(2).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()); + } } diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.h b/source/SubTests/AkkusativDativ/AkkusativModel.h index 9ec74fd..43a4881 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.h +++ b/source/SubTests/AkkusativDativ/AkkusativModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "AkkusativModel.pb.h" class AkkusativModel : public CheckableTestModel { @@ -8,4 +9,7 @@ class AkkusativModel : public CheckableTestModel public: AkkusativModel(QObject *parent); + + void read(const ESGRAF48::AkkusativModel &model); + void write(ESGRAF48::AkkusativModel &model) const; }; diff --git a/source/SubTests/AkkusativDativ/CMakeLists.txt b/source/SubTests/AkkusativDativ/CMakeLists.txt index 05deb13..a543ee7 100644 --- a/source/SubTests/AkkusativDativ/CMakeLists.txt +++ b/source/SubTests/AkkusativDativ/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6) project(AkkusativDativ LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) @@ -10,11 +11,22 @@ qt5_wrap_ui(UI_HEADERS AkkusativDativWidget.ui ) +set(AkkusativDativ_PROTO_FILES + ../../../proto/AkkusativModel.proto + ../../../proto/DativModel.proto +) + +protobuf_generate_cpp(AkkusativDativ_PROTO_SRCS AkkusativDativ_PROTO_HDRS + ${AkkusativDativ_PROTO_FILES} +) + add_library(${PROJECT_NAME} AkkusativDativWidget.cpp AkkusativModel.cpp DativModel.cpp ${UI_HEADERS} + ${AkkusativDativ_PROTO_SRCS} + ${AkkusativDativ_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -26,6 +38,7 @@ target_include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} ) target_link_libraries(${PROJECT_NAME} @@ -34,4 +47,5 @@ target_link_libraries(${PROJECT_NAME} CheckableTest CheckableTestModel Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index 8252cf6..c295348 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -1,15 +1,105 @@ #include "DativModel.h" DativModel::DativModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { - { "Dativ Nominalphrase", { "Tiger", "Katze", "Affe", "Gans", "Bär", - "Pferd", "Hund", "Elefant" } }, - { "Präpositionalphrase (Verstecke)", - { "Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", - "Baum" } }, - { "Nominalphrase (Tiere)", { "Salat", "Fleisch", "Knochen", "Banane", - "Apfel", "Karotte", "Honig", "Zucker" } } - }; + m_tests = {{"Dativ Nominalphrase", + {"Tiger", "Katze", "Affe", "Gans", "Bär", "Pferd", "Hund", "Elefant"}}, + {"Präpositionalphrase (Verstecke)", + {"Vorhang", "Kiste", "Holz", "Kiste", "Baum", "Vorhang", "Holz", "Baum"}}, + {"Nominalphrase (Tiere)", + {"Salat", "Fleisch", "Knochen", "Banane", "Apfel", "Karotte", "Honig", "Zucker"}}}; +} + +void DativModel::read(const ESGRAF48::DativModel &model) +{ + const auto &tiereModel = model.tiere(); + { + auto &testItems = m_tests.at(0).items(); + + testItems[0].setState(tiereModel.tiger()); + testItems[1].setState(tiereModel.katze()); + testItems[2].setState(tiereModel.affe()); + testItems[3].setState(tiereModel.gans()); + testItems[4].setState(tiereModel.baer()); + testItems[5].setState(tiereModel.pferd()); + testItems[6].setState(tiereModel.hund()); + testItems[7].setState(tiereModel.elefant()); + } + + const auto &versteckeModel = model.verstecke(); + { + auto &testItems = m_tests.at(1).items(); + + testItems[0].setState(versteckeModel.vorhang1()); + testItems[1].setState(versteckeModel.kiste1()); + testItems[2].setState(versteckeModel.holz1()); + testItems[3].setState(versteckeModel.kiste2()); + testItems[4].setState(versteckeModel.baum1()); + testItems[5].setState(versteckeModel.vorhang2()); + testItems[6].setState(versteckeModel.holz2()); + testItems[7].setState(versteckeModel.baum2()); + } + + const auto &futterModel = model.futter(); + { + auto &testItems = m_tests.at(2).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()); + } +} + +void DativModel::write(ESGRAF48::DativModel &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_katze(testItems[1].isChecked()); + tiereModel->set_affe(testItems[2].isChecked()); + tiereModel->set_gans(testItems[3].isChecked()); + tiereModel->set_baer(testItems[4].isChecked()); + tiereModel->set_pferd(testItems[5].isChecked()); + tiereModel->set_hund(testItems[6].isChecked()); + tiereModel->set_elefant(testItems[7].isChecked()); + } + + auto *versteckeModel = model.mutable_verstecke(); + if (versteckeModel != nullptr) + { + const auto &testItems = m_tests.at(1).items(); + + versteckeModel->set_vorhang1(testItems[0].isChecked()); + versteckeModel->set_kiste1(testItems[1].isChecked()); + versteckeModel->set_holz1(testItems[2].isChecked()); + versteckeModel->set_kiste2(testItems[3].isChecked()); + versteckeModel->set_baum1(testItems[4].isChecked()); + versteckeModel->set_vorhang2(testItems[5].isChecked()); + versteckeModel->set_holz2(testItems[6].isChecked()); + versteckeModel->set_baum2(testItems[7].isChecked()); + } + + auto *futterModel = model.mutable_futter(); + if (futterModel != nullptr) + { + const auto &testItems = m_tests.at(2).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()); + } } diff --git a/source/SubTests/AkkusativDativ/DativModel.h b/source/SubTests/AkkusativDativ/DativModel.h index 306c8ce..6a9a323 100644 --- a/source/SubTests/AkkusativDativ/DativModel.h +++ b/source/SubTests/AkkusativDativ/DativModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "DativModel.pb.h" class DativModel : public CheckableTestModel { @@ -8,4 +9,7 @@ class DativModel : public CheckableTestModel public: DativModel(QObject *parent); + + void read(const ESGRAF48::DativModel &model); + void write(ESGRAF48::DativModel &model) const; }; diff --git a/source/SubTests/Genus/CMakeLists.txt b/source/SubTests/Genus/CMakeLists.txt index 28fe2ef..5b29b68 100644 --- a/source/SubTests/Genus/CMakeLists.txt +++ b/source/SubTests/Genus/CMakeLists.txt @@ -11,7 +11,6 @@ qt5_wrap_ui(GENUS_UI GenusWidget.ui ) - set(Genus_PROTO_FILES ../../../proto/GenusModel.proto ) From 87c9b0e74a4981ff5234957896ccd944bfebb68c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 18 Nov 2018 17:40:07 +0100 Subject: [PATCH 13/14] 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; }; From f6b283b3a156483477dce73fcdc48a4b1f888193 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 18 Nov 2018 21:29:43 +0100 Subject: [PATCH 14/14] Ported late skills to protobuf, added changed-messages --- proto/DataModel.proto | 4 + proto/LateSkillsGenitivModel.proto | 33 +++++++ proto/LateSkillsPassivModel.proto | 17 ++++ source/CMakeLists.txt | 2 + source/DataModel.cpp | 4 + .../AkkusativDativ/AkkusativModel.cpp | 2 + source/SubTests/AkkusativDativ/DativModel.cpp | 2 + source/SubTests/Genus/GenusModel.cpp | 2 + source/SubTests/LateSkills/CMakeLists.txt | 30 ++++-- source/SubTests/LateSkills/GenitivModel.cpp | 96 +++++++++++++++---- source/SubTests/LateSkills/GenitivModel.h | 4 + source/SubTests/LateSkills/PassivModel.cpp | 56 ++++++++--- source/SubTests/LateSkills/PassivModel.h | 4 + source/SubTests/Plural/PluralModel.cpp | 2 + 14 files changed, 222 insertions(+), 36 deletions(-) create mode 100644 proto/LateSkillsGenitivModel.proto create mode 100644 proto/LateSkillsPassivModel.proto diff --git a/proto/DataModel.proto b/proto/DataModel.proto index d6e6e17..d0f53a3 100644 --- a/proto/DataModel.proto +++ b/proto/DataModel.proto @@ -9,6 +9,8 @@ import "GenusModel.proto"; import "AkkusativModel.proto"; import "DativModel.proto"; import "PluralModel.proto"; +import "LateSkillsGenitivModel.proto"; +import "LateSkillsPassivModel.proto"; message DataModel { @@ -19,4 +21,6 @@ message DataModel AkkusativModel Akkusativ = 5; DativModel Dativ = 6; PluralModel Plural = 7; + LateSkillsGenitivModel LateSkillsGenitiv = 8; + LateSkillsPassivModel LateSkillsPassiv = 9; } diff --git a/proto/LateSkillsGenitivModel.proto b/proto/LateSkillsGenitivModel.proto new file mode 100644 index 0000000..b672ed6 --- /dev/null +++ b/proto/LateSkillsGenitivModel.proto @@ -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; +} diff --git a/proto/LateSkillsPassivModel.proto b/proto/LateSkillsPassivModel.proto new file mode 100644 index 0000000..b4244fb --- /dev/null +++ b/proto/LateSkillsPassivModel.proto @@ -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; +} diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 85e1c57..ab95560 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -26,6 +26,8 @@ set(DataModel_PROTO_FILES ../proto/AkkusativModel.proto ../proto/DativModel.proto ../proto/PluralModel.proto + ../proto/LateSkillsPassivModel.proto + ../proto/LateSkillsGenitivModel.proto ) protobuf_generate_cpp(DataModel_PROTO_SRCS DataModel_PROTO_HDRS diff --git a/source/DataModel.cpp b/source/DataModel.cpp index e33b1c1..d979a39 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -38,6 +38,8 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const m_akkusativ.write(*dataModel.mutable_akkusativ()); m_dativ.write(*dataModel.mutable_dativ()); m_plural.write(*dataModel.mutable_plural()); + m_genitiv.write(*dataModel.mutable_lateskillsgenitiv()); + m_passiv.write(*dataModel.mutable_lateskillspassiv()); dataModel.SerializeToOstream(&outStream); } @@ -54,6 +56,8 @@ void DataModel::readProtoBuf(std::istream &inStream) m_akkusativ.read(dataModel.akkusativ()); m_dativ.read(dataModel.dativ()); m_plural.read(dataModel.plural()); + m_genitiv.read(dataModel.lateskillsgenitiv()); + m_passiv.read(dataModel.lateskillspassiv()); } std::string DataModel::toHtml() const diff --git a/source/SubTests/AkkusativDativ/AkkusativModel.cpp b/source/SubTests/AkkusativDativ/AkkusativModel.cpp index 68d8f04..79d2c31 100644 --- a/source/SubTests/AkkusativDativ/AkkusativModel.cpp +++ b/source/SubTests/AkkusativDativ/AkkusativModel.cpp @@ -54,6 +54,8 @@ void AkkusativModel::read(const ESGRAF48::AkkusativModel &model) testItems[6].setState(futterModel.honig()); testItems[7].setState(futterModel.zucker()); } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const diff --git a/source/SubTests/AkkusativDativ/DativModel.cpp b/source/SubTests/AkkusativDativ/DativModel.cpp index c295348..081dfdb 100644 --- a/source/SubTests/AkkusativDativ/DativModel.cpp +++ b/source/SubTests/AkkusativDativ/DativModel.cpp @@ -54,6 +54,8 @@ void DativModel::read(const ESGRAF48::DativModel &model) testItems[6].setState(futterModel.honig()); testItems[7].setState(futterModel.zucker()); } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void DativModel::write(ESGRAF48::DativModel &model) const diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index 0977ce9..24e5c36 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -48,6 +48,8 @@ void GenusModel::readProtoBuf(const ESGRAF48::GenusModel &model) testItems[2].setState(zirkusModel.vorhang()); testItems[3].setState(zirkusModel.baum()); } + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void GenusModel::writeProtoBuf(ESGRAF48::GenusModel &model) const diff --git a/source/SubTests/LateSkills/CMakeLists.txt b/source/SubTests/LateSkills/CMakeLists.txt index a570f42..7fef071 100644 --- a/source/SubTests/LateSkills/CMakeLists.txt +++ b/source/SubTests/LateSkills/CMakeLists.txt @@ -3,18 +3,30 @@ cmake_minimum_required(VERSION 3.6) project(LateSkills LANGUAGES CXX) find_package(Qt5Widgets REQUIRED) +find_package(Protobuf REQUIRED) set(CMAKE_AUTOMOC ON) 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} - LateSkillsWidget.cpp + LateSkillsWidget.cpp PassivModel.cpp GenitivModel.cpp ${UI_HEADERS} + ${LateSkills_PROTO_SRCS} + ${LateSkills_PROTO_HDRS} ) set_target_properties(${PROJECT_NAME} @@ -23,15 +35,17 @@ set_target_properties(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${Protobuf_INCLUDE_DIRS} ) target_link_libraries(${PROJECT_NAME} PRIVATE - CheckableItem - CheckableTest - CheckableTestModel - Qt5::Widgets + CheckableItem + CheckableTest + CheckableTestModel + Qt5::Widgets + ${Protobuf_LIBRARIES} ) diff --git a/source/SubTests/LateSkills/GenitivModel.cpp b/source/SubTests/LateSkills/GenitivModel.cpp index af69325..9ebf423 100644 --- a/source/SubTests/LateSkills/GenitivModel.cpp +++ b/source/SubTests/LateSkills/GenitivModel.cpp @@ -1,45 +1,109 @@ #include "GenitivModel.h" GenitivModel::GenitivModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { m_tests = { - { "Genitiv Präpositionen", - { "anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", - "mithilfe (1)", "mithilfe (2)" } }, - { "Attributierung", - { "Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", - "Hut (1)", "Hut (2)", "Brille (1)", "Brille (2)", "Gürtel (1)", - "Gürtel (2)" } }, + {"Genitiv Präpositionen", + {"anstelle (1)", "anstelle (2)", "außerhalb (1)", "außerhalb (2)", "mithilfe (1)", + "mithilfe (2)"}}, + {"Attributierung", + {"Schuhe (1)", "Schuhe (2)", "Zauberstab (1)", "Zauberstab (2)", "Hut (1)", "Hut (2)", + "Brille (1)", "Brille (2)", "Gürtel (1)", "Gürtel (2)"}}, }; - for (auto index : { 1, 3, 5 }) + for (auto index : {1, 3, 5}) { 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); } } -bool GenitivModel::setData( - const QModelIndex &modelIndex, const QVariant &value, int role) +bool GenitivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role) { if (role == Qt::CheckStateRole && value.toBool() == true) { if (modelIndex.column() % 2 == 0) { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() + 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false, + role); } else { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() - 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false, + 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()); + } +} diff --git a/source/SubTests/LateSkills/GenitivModel.h b/source/SubTests/LateSkills/GenitivModel.h index 4f6687a..2346e94 100644 --- a/source/SubTests/LateSkills/GenitivModel.h +++ b/source/SubTests/LateSkills/GenitivModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "LateSkillsGenitivModel.pb.h" class GenitivModel : public CheckableTestModel { @@ -10,4 +11,7 @@ public: GenitivModel(QObject *parent); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + + void read(const ESGRAF48::LateSkillsGenitivModel &model); + void write(ESGRAF48::LateSkillsGenitivModel &model) const; }; diff --git a/source/SubTests/LateSkills/PassivModel.cpp b/source/SubTests/LateSkills/PassivModel.cpp index 2f82c2e..6f1d3a8 100644 --- a/source/SubTests/LateSkills/PassivModel.cpp +++ b/source/SubTests/LateSkills/PassivModel.cpp @@ -1,35 +1,67 @@ #include "PassivModel.h" PassivModel::PassivModel(QObject *parent) - : CheckableTestModel(parent) + : CheckableTestModel(parent) { - m_tests = { { "Passiv", - { "Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", - "Bälle (2)", "Ball (1)", "Ball (2)", "Fleisch (1)", - "Fleisch (2)" } } }; + m_tests = {{"Passiv", + {"Elefant (1)", "Elefant (2)", "Pferde (1)", "Pferde (2)", "Bälle (1)", "Bälle (2)", + "Ball (1)", "Ball (2)", "Fleisch (1)", "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); } } -bool PassivModel::setData( - const QModelIndex &modelIndex, const QVariant &value, int role) +bool PassivModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role) { if (role == Qt::CheckStateRole && value.toBool() == true) { if (modelIndex.column() % 2 == 0) { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() + 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() + 1), false, + role); } else { - CheckableTestModel::setData( - index(modelIndex.row(), modelIndex.column() - 1), false, role); + CheckableTestModel::setData(index(modelIndex.row(), modelIndex.column() - 1), false, + 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()); +} diff --git a/source/SubTests/LateSkills/PassivModel.h b/source/SubTests/LateSkills/PassivModel.h index 159ccba..e0671bb 100644 --- a/source/SubTests/LateSkills/PassivModel.h +++ b/source/SubTests/LateSkills/PassivModel.h @@ -1,6 +1,7 @@ #pragma once #include "CheckableTestModel.h" +#include "LateSkillsPassivModel.pb.h" class PassivModel : public CheckableTestModel { @@ -10,4 +11,7 @@ public: PassivModel(QObject *parent); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + + void read(const ESGRAF48::LateSkillsPassivModel &model); + void write(ESGRAF48::LateSkillsPassivModel &model) const; }; diff --git a/source/SubTests/Plural/PluralModel.cpp b/source/SubTests/Plural/PluralModel.cpp index a1a208e..0ade859 100644 --- a/source/SubTests/Plural/PluralModel.cpp +++ b/source/SubTests/Plural/PluralModel.cpp @@ -33,6 +33,8 @@ void PluralModel::read(const ESGRAF48::PluralModel &model) testItems[6].setState(model.nuss()); testItems[7].setState(model.baer()); testItems[8].setState(model.apfel()); + + emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } void PluralModel::write(ESGRAF48::PluralModel &model) const