Removed obsolete json read/writes

This commit is contained in:
mandlm 2018-11-17 11:57:59 +01:00
parent a2c4b16eb4
commit 09d811ee25
5 changed files with 5 additions and 86 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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()));

View File

@ -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;

View File

@ -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());
}
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);
QJsonDocument saveDoc(saveData);
QFile saveFile(filename);
saveFile.open(QFile::WriteOnly);
saveFile.write(saveDoc.toJson());
saveFile.close();
}
qDebug() << "Wrote" << filename;
setWindowTitle(filename + "[*]");