Ported MetaDataModel to protobuf

This commit is contained in:
Michael Mandl 2018-11-16 23:21:02 +01:00
parent e77990a86a
commit 56ca796df0
7 changed files with 54 additions and 6 deletions

View file

@ -2,9 +2,11 @@ syntax = "proto3";
package ESGRAF48; package ESGRAF48;
import "MetaDataModel.proto";
import "V2SvkModel.proto"; import "V2SvkModel.proto";
message DataModel message DataModel
{ {
MetaDataModel MetaData = 1;
V2SvkModel V2Svk = 2; V2SvkModel V2Svk = 2;
} }

12
proto/MetaDataModel.proto Normal file
View file

@ -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;
}

View file

@ -19,6 +19,7 @@ qt5_add_resources(LOGO_TEST_QRC
set(DataModel_PROTO_FILES set(DataModel_PROTO_FILES
../proto/DataModel.proto ../proto/DataModel.proto
../proto/MetaDataModel.proto
../proto/V2SvkModel.proto ../proto/V2SvkModel.proto
) )

View file

@ -3,8 +3,6 @@
#include "DataModel.pb.h" #include "DataModel.pb.h"
#include <QDebug> #include <QDebug>
#include <google/protobuf/text_format.h>
#include <sstream> #include <sstream>
DataModel::DataModel(QObject *parent) DataModel::DataModel(QObject *parent)
@ -60,8 +58,10 @@ void DataModel::read(const QJsonObject &source)
void DataModel::writeProtoBuf(std::ostream &outStream) const void DataModel::writeProtoBuf(std::ostream &outStream) const
{ {
ESGRAF48::DataModel dataModel; ESGRAF48::DataModel dataModel;
//m_metaData.writeProtoBuf(dataModel.mutable_metadata);
m_metaData.writeProtoBuf(*dataModel.mutable_metadata());
m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk());
dataModel.SerializeToOstream(&outStream); dataModel.SerializeToOstream(&outStream);
} }
@ -70,6 +70,7 @@ void DataModel::readProtoBuf(std::istream &inStream)
ESGRAF48::DataModel dataModel; ESGRAF48::DataModel dataModel;
dataModel.ParseFromIstream(&inStream); dataModel.ParseFromIstream(&inStream);
m_metaData.readProtoBuf(dataModel.metadata());
m_v2Svk.readProtoBuf(dataModel.v2svk()); m_v2Svk.readProtoBuf(dataModel.v2svk());
} }

View file

@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6)
project(MetaData LANGUAGES CXX) project(MetaData LANGUAGES CXX)
find_package(Qt5Widgets REQUIRED) find_package(Qt5Widgets REQUIRED)
find_package(Protobuf REQUIRED)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
@ -10,10 +11,20 @@ qt5_wrap_ui(META_DATA_UI
MetaDataWidget.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} add_library(${PROJECT_NAME}
MetaDataModel.cpp MetaDataModel.cpp
MetaDataWidget.cpp MetaDataWidget.cpp
${META_DATA_UI} ${META_DATA_UI}
${MetaDataModel_PROTO_SRCS}
${MetaDataModel_PROTO_HDRS}
) )
set_target_properties(${PROJECT_NAME} set_target_properties(${PROJECT_NAME}
@ -23,6 +34,7 @@ set_target_properties(${PROJECT_NAME}
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PRIVATE PRIVATE
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${Protobuf_INCLUDE_DIRS}
INTERFACE INTERFACE
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
@ -30,4 +42,5 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PRIVATE PRIVATE
Qt5::Widgets Qt5::Widgets
${Protobuf_LIBRARIES}
) )

View file

@ -130,9 +130,23 @@ void MetaDataModel::read(const QJsonObject &json)
setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole); 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 std::string MetaDataModel::toHtml() const
{ {

View file

@ -2,6 +2,8 @@
#include "../Age.h" #include "../Age.h"
#include "MetaDataModel.pb.h"
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QString> #include <QString>
#include <QDate> #include <QDate>
@ -31,6 +33,9 @@ public:
void write(QJsonObject &json) const; void write(QJsonObject &json) const;
void read(const QJsonObject &json); void read(const QJsonObject &json);
void readProtoBuf(const ESGRAF48::MetaDataModel &model);
void writeProtoBuf(ESGRAF48::MetaDataModel &model) const;
std::string toHtml() const; std::string toHtml() const;
Age getAge() const Age getAge() const