From 542d2df9923247e171c0e221b46c2e38a406de0c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 29 Jan 2019 20:14:24 +0100 Subject: [PATCH] Removed filename string conversion from loading/saving to avoid codepage problems --- source/DataModel.cpp | 22 ++++++++++++++++++---- source/DataModel.h | 4 ++-- source/mainwindow.cpp | 7 ++----- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index 216eb8c..eba7f53 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -1,6 +1,8 @@ #include "DataModel.h" #include "DataModel.pb.h" +#include + #include DataModel::DataModel(QObject *parent) @@ -27,7 +29,7 @@ DataModel::DataModel(QObject *parent) connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); } -void DataModel::write(std::ostream &outStream) const +void DataModel::write(const QString &filename) const { ESGRAF48::DataModel dataModel; @@ -41,13 +43,25 @@ void DataModel::write(std::ostream &outStream) const m_genitiv.write(*dataModel.mutable_lateskillsgenitiv()); m_passiv.write(*dataModel.mutable_lateskillspassiv()); - dataModel.SerializeToOstream(&outStream); + QFile outFile(filename); + if (!outFile.open(QIODevice::WriteOnly)) + { + return; + } + + dataModel.SerializeToFileDescriptor(outFile.handle()); } -void DataModel::read(std::istream &inStream) +void DataModel::read(const QString &filename) { + QFile inFile(filename); + if (!inFile.open(QIODevice::ReadOnly)) + { + return; + } + ESGRAF48::DataModel dataModel; - dataModel.ParseFromIstream(&inStream); + dataModel.ParseFromFileDescriptor(inFile.handle()); m_metaData.read(dataModel.metadata()); m_v2Svk.read(dataModel.v2svk()); diff --git a/source/DataModel.h b/source/DataModel.h index 71a9352..42b5294 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -36,8 +36,8 @@ public: std::string toHtml() const; - void write(std::ostream &outStream) const; - void read(std::istream &inStream); + void write(const QString &filename) const; + void read(const QString &filename); signals: void modelChanged(); diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index e91549a..8f0eab0 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -92,8 +92,7 @@ void MainWindow::openFile(const QString &filename) { closeFile(); - std::fstream protoInFile(filename.toStdString(), std::ios::in | std::ios::binary); - m_dataModel.read(protoInFile); + m_dataModel.read(filename); setWindowModified(false); setWindowTitle(filename + "[*]"); @@ -196,9 +195,7 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::saveFile(const QString &filename) { - std::fstream protoOutFile(filename.toStdString(), - std::ios::out | std::ios::trunc | std::ios::binary); - m_dataModel.write(protoOutFile); + m_dataModel.write(filename); qDebug() << "Wrote" << filename;