Merge branch 'hotfix/filename-encoding'

This commit is contained in:
Michael Mandl 2019-01-29 20:14:59 +01:00
commit 2d88f4c08f
3 changed files with 22 additions and 11 deletions

View file

@ -1,6 +1,8 @@
#include "DataModel.h" #include "DataModel.h"
#include "DataModel.pb.h" #include "DataModel.pb.h"
#include <QFile>
#include <sstream> #include <sstream>
DataModel::DataModel(QObject *parent) DataModel::DataModel(QObject *parent)
@ -27,7 +29,7 @@ DataModel::DataModel(QObject *parent)
connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); 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; ESGRAF48::DataModel dataModel;
@ -41,13 +43,25 @@ void DataModel::write(std::ostream &outStream) const
m_genitiv.write(*dataModel.mutable_lateskillsgenitiv()); m_genitiv.write(*dataModel.mutable_lateskillsgenitiv());
m_passiv.write(*dataModel.mutable_lateskillspassiv()); 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; ESGRAF48::DataModel dataModel;
dataModel.ParseFromIstream(&inStream); dataModel.ParseFromFileDescriptor(inFile.handle());
m_metaData.read(dataModel.metadata()); m_metaData.read(dataModel.metadata());
m_v2Svk.read(dataModel.v2svk()); m_v2Svk.read(dataModel.v2svk());

View file

@ -36,8 +36,8 @@ public:
std::string toHtml() const; std::string toHtml() const;
void write(std::ostream &outStream) const; void write(const QString &filename) const;
void read(std::istream &inStream); void read(const QString &filename);
signals: signals:
void modelChanged(); void modelChanged();

View file

@ -92,8 +92,7 @@ void MainWindow::openFile(const QString &filename)
{ {
closeFile(); closeFile();
std::fstream protoInFile(filename.toStdString(), std::ios::in | std::ios::binary); m_dataModel.read(filename);
m_dataModel.read(protoInFile);
setWindowModified(false); setWindowModified(false);
setWindowTitle(filename + "[*]"); setWindowTitle(filename + "[*]");
@ -196,9 +195,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::saveFile(const QString &filename) void MainWindow::saveFile(const QString &filename)
{ {
std::fstream protoOutFile(filename.toStdString(), m_dataModel.write(filename);
std::ios::out | std::ios::trunc | std::ios::binary);
m_dataModel.write(protoOutFile);
qDebug() << "Wrote" << filename; qDebug() << "Wrote" << filename;