From 09d811ee252137198571df92e23f808ce03e2975 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 17 Nov 2018 11:57:59 +0100 Subject: [PATCH] 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 + "[*]");