Merge branch 'hotfix/filename-encoding'
This commit is contained in:
commit
2d88f4c08f
3 changed files with 22 additions and 11 deletions
|
@ -1,6 +1,8 @@
|
|||
#include "DataModel.h"
|
||||
#include "DataModel.pb.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void DataModel::read(std::istream &inStream)
|
||||
dataModel.SerializeToFileDescriptor(outFile.handle());
|
||||
}
|
||||
|
||||
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());
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue