From ef5686e83ea80f93ad62572987df70f264197f4a Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 20 Nov 2018 07:59:12 +0100 Subject: [PATCH 1/2] Renamed read/writeProtoBuf to read/write --- source/DataModel.cpp | 20 ++++++++++---------- source/DataModel.h | 4 ++-- source/MetaData/MetaDataModel.cpp | 4 ++-- source/MetaData/MetaDataModel.h | 4 ++-- source/SubTests/Genus/GenusModel.cpp | 4 ++-- source/SubTests/Genus/GenusModel.h | 4 ++-- source/SubTests/V2Svk/V2SvkModel.cpp | 4 ++-- source/SubTests/V2Svk/V2SvkModel.h | 4 ++-- source/SubTests/VerbEnd/VerbEndModel.cpp | 4 ++-- source/SubTests/VerbEnd/VerbEndModel.h | 4 ++-- source/mainwindow.cpp | 4 ++-- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index d979a39..d7be767 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -27,14 +27,14 @@ DataModel::DataModel(QObject *parent) connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); } -void DataModel::writeProtoBuf(std::ostream &outStream) const +void DataModel::write(std::ostream &outStream) const { ESGRAF48::DataModel dataModel; - m_metaData.writeProtoBuf(*dataModel.mutable_metadata()); - m_v2Svk.writeProtoBuf(*dataModel.mutable_v2svk()); - m_verbEnd.writeProtoBuf(*dataModel.mutable_verbend()); - m_genus.writeProtoBuf(*dataModel.mutable_genus()); + m_metaData.write(*dataModel.mutable_metadata()); + m_v2Svk.write(*dataModel.mutable_v2svk()); + u_verbEnd.write(*dataModel.mutable_verbend()); + m_genus.write(*dataModel.mutable_genus()); m_akkusativ.write(*dataModel.mutable_akkusativ()); m_dativ.write(*dataModel.mutable_dativ()); m_plural.write(*dataModel.mutable_plural()); @@ -44,15 +44,15 @@ void DataModel::writeProtoBuf(std::ostream &outStream) const dataModel.SerializeToOstream(&outStream); } -void DataModel::readProtoBuf(std::istream &inStream) +void DataModel::read(std::istream &inStream) { ESGRAF48::DataModel dataModel; dataModel.ParseFromIstream(&inStream); - m_metaData.readProtoBuf(dataModel.metadata()); - m_v2Svk.readProtoBuf(dataModel.v2svk()); - m_verbEnd.readProtoBuf(dataModel.verbend()); - m_genus.readProtoBuf(dataModel.genus()); + m_metaData.read(dataModel.metadata()); + m_v2Svk.read(dataModel.v2svk()); + m_verbEnd.read(dataModel.verbend()); + m_genus.read(dataModel.genus()); m_akkusativ.read(dataModel.akkusativ()); m_dativ.read(dataModel.dativ()); m_plural.read(dataModel.plural()); diff --git a/source/DataModel.h b/source/DataModel.h index 4030321..71a9352 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -36,8 +36,8 @@ public: std::string toHtml() const; - void writeProtoBuf(std::ostream &outStream) const; - void readProtoBuf(std::istream &inStream); + void write(std::ostream &outStream) const; + void read(std::istream &inStream); signals: void modelChanged(); diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index cc5dd87..94c2a62 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -112,7 +112,7 @@ bool MetaDataModel::setData(const QModelIndex &modelIndex, const QVariant &value return valueChanged; } -void MetaDataModel::readProtoBuf(const ESGRAF48::MetaDataModel &model) +void MetaDataModel::read(const ESGRAF48::MetaDataModel &model) { setData(index(0, 0), QString::fromStdString(model.participantname())); setData(index(0, 1), QString::fromStdString(model.instructorname())); @@ -121,7 +121,7 @@ void MetaDataModel::readProtoBuf(const ESGRAF48::MetaDataModel &model) setData(index(0, 4), QString::fromStdString(model.remarks())); } -void MetaDataModel::writeProtoBuf(ESGRAF48::MetaDataModel &model) const +void MetaDataModel::write(ESGRAF48::MetaDataModel &model) const { model.set_participantname(m_participant.toStdString()); model.set_instructorname(m_instructor.toStdString()); diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 78a9e14..d2ebaa7 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -30,8 +30,8 @@ public: bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - void readProtoBuf(const ESGRAF48::MetaDataModel &model); - void writeProtoBuf(ESGRAF48::MetaDataModel &model) const; + void read(const ESGRAF48::MetaDataModel &model); + void write(ESGRAF48::MetaDataModel &model) const; std::string toHtml() const; diff --git a/source/SubTests/Genus/GenusModel.cpp b/source/SubTests/Genus/GenusModel.cpp index 24e5c36..3f2278b 100644 --- a/source/SubTests/Genus/GenusModel.cpp +++ b/source/SubTests/Genus/GenusModel.cpp @@ -9,7 +9,7 @@ GenusModel::GenusModel(QObject *parent) {"Zirkus", {"Kiste", "Holz", "Vorhang", "Baum"}}}; } -void GenusModel::readProtoBuf(const ESGRAF48::GenusModel &model) +void GenusModel::read(const ESGRAF48::GenusModel &model) { const auto &tiereModel = model.tiere(); { @@ -52,7 +52,7 @@ void GenusModel::readProtoBuf(const ESGRAF48::GenusModel &model) emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1)); } -void GenusModel::writeProtoBuf(ESGRAF48::GenusModel &model) const +void GenusModel::write(ESGRAF48::GenusModel &model) const { auto *tiereModel = model.mutable_tiere(); if (tiereModel != nullptr) diff --git a/source/SubTests/Genus/GenusModel.h b/source/SubTests/Genus/GenusModel.h index 3dd8dc9..8261779 100644 --- a/source/SubTests/Genus/GenusModel.h +++ b/source/SubTests/Genus/GenusModel.h @@ -10,6 +10,6 @@ class GenusModel : public CheckableTestModel public: GenusModel(QObject *parent); - void readProtoBuf(const ESGRAF48::GenusModel &model); - void writeProtoBuf(ESGRAF48::GenusModel &model) const; + void read(const ESGRAF48::GenusModel &model); + void write(ESGRAF48::GenusModel &model) const; }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 6d7b373..2196ba4 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -87,7 +87,7 @@ bool V2SvkModel::isValidIndex(const QModelIndex &index) const } } -void V2SvkModel::writeProtoBuf(ESGRAF48::V2SvkModel &model) const +void V2SvkModel::write(ESGRAF48::V2SvkModel &model) const { auto writeOneVal = [&](ESGRAF48::V2SvkModel::OneEach *modelData, int testIndex) { if (modelData != nullptr) @@ -147,7 +147,7 @@ void V2SvkModel::writeProtoBuf(ESGRAF48::V2SvkModel &model) const writeTwoVals(model.mutable_partizip(), 10); } -void V2SvkModel::readProtoBuf(const ESGRAF48::V2SvkModel &model) +void V2SvkModel::read(const ESGRAF48::V2SvkModel &model) { auto readOneVal = [&](const ESGRAF48::V2SvkModel::OneEach &modelData, int testIndex) { auto &testItems = m_tests.at(testIndex).items(); diff --git a/source/SubTests/V2Svk/V2SvkModel.h b/source/SubTests/V2Svk/V2SvkModel.h index a574ac3..519508a 100644 --- a/source/SubTests/V2Svk/V2SvkModel.h +++ b/source/SubTests/V2Svk/V2SvkModel.h @@ -13,8 +13,8 @@ public: unsigned int getV2Points(); unsigned int getSvkPoints(); - void writeProtoBuf(ESGRAF48::V2SvkModel &model) const; - void readProtoBuf(const ESGRAF48::V2SvkModel &model); + void write(ESGRAF48::V2SvkModel &model) const; + void read(const ESGRAF48::V2SvkModel &model); protected: bool isValidIndex(const QModelIndex &index) const override; diff --git a/source/SubTests/VerbEnd/VerbEndModel.cpp b/source/SubTests/VerbEnd/VerbEndModel.cpp index 9df5e5d..dea4d95 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.cpp +++ b/source/SubTests/VerbEnd/VerbEndModel.cpp @@ -12,7 +12,7 @@ VerbEndModel::VerbEndModel(QObject *parent) "Temporal", "Relativ" } } }; } -void VerbEndModel::writeProtoBuf(ESGRAF48::VerbEndModel &model) const +void VerbEndModel::write(ESGRAF48::VerbEndModel &model) const { auto *telefonatModel = model.mutable_telefonat(); if (telefonatModel != nullptr) @@ -56,7 +56,7 @@ void VerbEndModel::writeProtoBuf(ESGRAF48::VerbEndModel &model) const } } -void VerbEndModel::readProtoBuf(const ESGRAF48::VerbEndModel &model) +void VerbEndModel::read(const ESGRAF48::VerbEndModel &model) { const auto &telefonatModel = model.telefonat(); { diff --git a/source/SubTests/VerbEnd/VerbEndModel.h b/source/SubTests/VerbEnd/VerbEndModel.h index ea729fc..cf6342a 100644 --- a/source/SubTests/VerbEnd/VerbEndModel.h +++ b/source/SubTests/VerbEnd/VerbEndModel.h @@ -10,6 +10,6 @@ class VerbEndModel : public CheckableTestModel public: VerbEndModel(QObject *parent); - void writeProtoBuf(ESGRAF48::VerbEndModel &model) const; - void readProtoBuf(const ESGRAF48::VerbEndModel &model); + void write(ESGRAF48::VerbEndModel &model) const; + void read(const ESGRAF48::VerbEndModel &model); }; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 0d86a4d..1932b2a 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -75,7 +75,7 @@ void MainWindow::openFile() closeFile(); std::fstream protoInFile(filename.toStdString(), std::ios::in | std::ios::binary); - m_dataModel->readProtoBuf(protoInFile); + m_dataModel->read(protoInFile); setWindowModified(false); setWindowTitle(filename + "[*]"); @@ -160,7 +160,7 @@ void MainWindow::saveFile(const QString &filename) { std::fstream protoOutFile(filename.toStdString(), std::ios::out | std::ios::trunc | std::ios::binary); - m_dataModel->writeProtoBuf(protoOutFile); + m_dataModel->write(protoOutFile); qDebug() << "Wrote" << filename; From 188f33c7369441a115efc8297ae80fee8c17fb6f Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 20 Nov 2018 23:05:49 +0100 Subject: [PATCH 2/2] Use protobuf conan package --- CMakeLists.txt | 3 +++ conanfile.txt | 8 ++++++++ source/DataModel.cpp | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 conanfile.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 908eff4..d819e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,4 +2,7 @@ cmake_minimum_required(VERSION 3.5) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + add_subdirectory(source) diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..322722b --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,8 @@ +[requires] +protobuf/3.6.1@bincrafters/stable + +[generators] +cmake + +[options] +protobuf:shared=True diff --git a/source/DataModel.cpp b/source/DataModel.cpp index d7be767..216eb8c 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -33,7 +33,7 @@ void DataModel::write(std::ostream &outStream) const m_metaData.write(*dataModel.mutable_metadata()); m_v2Svk.write(*dataModel.mutable_v2svk()); - u_verbEnd.write(*dataModel.mutable_verbend()); + m_verbEnd.write(*dataModel.mutable_verbend()); m_genus.write(*dataModel.mutable_genus()); m_akkusativ.write(*dataModel.mutable_akkusativ()); m_dativ.write(*dataModel.mutable_dativ());