Ported MetaDataModel to protobuf

This commit is contained in:
mandlm 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;
import "MetaDataModel.proto";
import "V2SvkModel.proto";
message DataModel
{
MetaDataModel MetaData = 1;
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
../proto/DataModel.proto
../proto/MetaDataModel.proto
../proto/V2SvkModel.proto
)

View File

@ -3,8 +3,6 @@
#include "DataModel.pb.h"
#include <QDebug>
#include <google/protobuf/text_format.h>
#include <sstream>
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());
}

View File

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

View File

@ -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
{

View File

@ -2,6 +2,8 @@
#include "../Age.h"
#include "MetaDataModel.pb.h"
#include <QAbstractTableModel>
#include <QString>
#include <QDate>
@ -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