This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
ESGRAF48/source/DataModel.cpp

201 lines
5.4 KiB
C++
Raw Normal View History

2018-05-16 05:02:12 +00:00
#include "DataModel.h"
2018-11-13 23:17:29 +00:00
#include "DataModel.pb.h"
#include <QFile>
2018-11-03 21:29:38 +00:00
#include <sstream>
2018-05-18 17:51:48 +00:00
DataModel::DataModel(QObject *parent)
2018-11-03 21:29:38 +00:00
: QObject(parent)
, m_metaData(this)
, m_verbEnd(this)
, m_genus(this)
, m_plural(this)
, m_results(this)
, m_akkusativ(this)
, m_dativ(this)
2019-01-31 19:14:38 +00:00
, m_wfModel(this)
, m_otModel(this)
, m_tPrModel(this)
, m_tPeModel(this)
2018-06-26 14:59:51 +00:00
, m_passiv(this)
, m_genitiv(this)
2018-05-16 05:02:12 +00:00
{
2018-11-03 21:29:38 +00:00
connect(&m_plural, &PluralModel::dataChanged, this, &DataModel::pluralModelChanged);
connect(&m_metaData, &MetaDataModel::dataChanged, this, &DataModel::metaDataChanged);
connect(&m_genus, &GenusModel::dataChanged, this, &DataModel::genusModelChanged);
connect(&m_verbEnd, &VerbEndModel::dataChanged, this, &DataModel::verbEndModelChanged);
connect(&m_akkusativ, &AkkusativModel::dataChanged, this, &DataModel::akkusativModelChanged);
connect(&m_dativ, &DativModel::dataChanged, this, &DataModel::dativModelChanged);
2019-01-31 19:14:38 +00:00
connect(&m_wfModel, &WFModel::dataChanged, this, &DataModel::v2SvkModelChanged);
connect(&m_otModel, &OTModel::dataChanged, this, &DataModel::v2SvkModelChanged);
connect(&m_tPrModel, &TPrModel::dataChanged, this, &DataModel::v2SvkModelChanged);
connect(&m_tPeModel, &TPeModel::dataChanged, this, &DataModel::v2SvkModelChanged);
2019-01-31 19:14:38 +00:00
2018-11-03 21:29:38 +00:00
connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged);
connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged);
2018-05-16 05:02:12 +00:00
}
void DataModel::write(const QString &filename) const
2018-11-13 23:17:29 +00:00
{
ESGRAF48::DataModel dataModel;
2018-11-16 22:21:02 +00:00
m_metaData.write(*dataModel.mutable_metadata());
2019-01-31 19:14:38 +00:00
m_wfModel.write(*dataModel.mutable_v2svk());
m_otModel.write(*dataModel.mutable_v2svk());
m_tPrModel.write(*dataModel.mutable_v2svk());
m_tPeModel.write(*dataModel.mutable_v2svk());
2019-01-31 19:14:38 +00:00
2018-11-20 22:05:49 +00:00
m_verbEnd.write(*dataModel.mutable_verbend());
m_genus.write(*dataModel.mutable_genus());
m_akkusativ.write(*dataModel.mutable_akkusativ());
m_dativ.write(*dataModel.mutable_dativ());
2018-11-18 16:40:07 +00:00
m_plural.write(*dataModel.mutable_plural());
m_genitiv.write(*dataModel.mutable_lateskillsgenitiv());
m_passiv.write(*dataModel.mutable_lateskillspassiv());
2018-11-16 22:21:02 +00:00
QFile outFile(filename);
if (!outFile.open(QIODevice::WriteOnly))
{
2019-01-30 19:41:22 +00:00
throw std::runtime_error("failed to open file");
}
2019-01-30 19:41:22 +00:00
bool success = dataModel.SerializeToFileDescriptor(outFile.handle());
if (success == false)
{
throw std::runtime_error("filed to write file");
}
2018-11-13 23:17:29 +00:00
}
void DataModel::read(const QString &filename)
2018-11-13 23:17:29 +00:00
{
QFile inFile(filename);
if (!inFile.open(QIODevice::ReadOnly))
{
2019-01-30 19:41:22 +00:00
throw std::runtime_error("failed to read file");
}
2018-11-13 23:17:29 +00:00
ESGRAF48::DataModel dataModel;
2019-01-30 19:41:22 +00:00
bool success = dataModel.ParseFromFileDescriptor(inFile.handle());
if (success == false)
{
throw std::runtime_error("invalid file format");
}
2018-11-13 23:17:29 +00:00
m_metaData.read(dataModel.metadata());
2019-01-31 19:14:38 +00:00
m_wfModel.read(dataModel.v2svk());
m_otModel.read(dataModel.v2svk());
m_tPrModel.read(dataModel.v2svk());
m_tPeModel.read(dataModel.v2svk());
2019-01-31 19:14:38 +00:00
m_verbEnd.read(dataModel.verbend());
m_genus.read(dataModel.genus());
m_akkusativ.read(dataModel.akkusativ());
m_dativ.read(dataModel.dativ());
2018-11-18 16:40:07 +00:00
m_plural.read(dataModel.plural());
m_genitiv.read(dataModel.lateskillsgenitiv());
m_passiv.read(dataModel.lateskillspassiv());
2018-11-13 23:17:29 +00:00
}
2019-02-03 18:53:51 +00:00
void DataModel::printTo(QPrinter &printer) const
2018-11-03 21:29:38 +00:00
{
2019-02-03 18:53:51 +00:00
QPainter painter;
painter.begin(&printer);
painter.setFont(PrintableModel::h1Font());
2019-01-12 15:50:04 +00:00
painter.drawText(0, painter.fontMetrics().lineSpacing(), "ESGRAF 4-8 Auswertungsbogen");
painter.translate(0, 3 * painter.fontMetrics().lineSpacing());
2018-11-03 21:29:38 +00:00
2019-01-12 15:50:04 +00:00
m_metaData.printTo(painter);
2019-02-03 18:53:51 +00:00
m_wfModel.printTo(painter);
2019-02-03 18:53:51 +00:00
m_otModel.printTo(painter);
m_tPrModel.printTo(painter);
m_tPeModel.printTo(painter);
V2SvkModel::printSummary(painter,
m_wfModel.getV2Points() + m_otModel.getV2Points()
+ m_tPrModel.getV2Points() + m_tPeModel.getV2Points(),
m_wfModel.getSvkPoints() + m_otModel.getSvkPoints()
+ m_tPrModel.getSvkPoints() + m_tPeModel.getSvkPoints());
m_verbEnd.printTo(painter);
m_genus.printTo(painter);
printer.newPage();
painter.resetTransform();
m_plural.printTo(painter);
painter.end();
2018-05-16 05:02:12 +00:00
}
2018-06-15 15:53:43 +00:00
void DataModel::pluralModelChanged()
{
m_results.setPluralResult(m_plural.getPoints());
emit modelChanged();
}
void DataModel::metaDataChanged()
{
2018-06-09 11:13:00 +00:00
m_results.setAge(m_metaData.getAge());
emit modelChanged();
}
2018-06-15 15:53:43 +00:00
void DataModel::genusModelChanged()
{
m_results.setGenusResult(m_genus.getPoints());
emit modelChanged();
2018-06-15 15:53:43 +00:00
}
2018-06-15 16:36:58 +00:00
void DataModel::verbEndModelChanged()
{
m_results.setVerbEndResult(m_verbEnd.getPoints());
emit modelChanged();
2018-06-15 16:36:58 +00:00
}
void DataModel::akkusativModelChanged()
{
m_results.setAkkusativResult(m_akkusativ.getPoints());
emit modelChanged();
}
void DataModel::dativModelChanged()
{
m_results.setDativResult(m_dativ.getPoints());
emit modelChanged();
}
2018-06-25 21:04:32 +00:00
void DataModel::v2SvkModelChanged()
{
2019-01-31 19:14:38 +00:00
m_results.setV2Result(m_wfModel.getV2Points() + m_otModel.getV2Points()
+ m_tPrModel.getV2Points() + m_tPeModel.getV2Points());
m_results.setSvkResult(m_wfModel.getSvkPoints() + m_otModel.getSvkPoints()
+ m_tPrModel.getSvkPoints() + m_tPeModel.getSvkPoints());
emit modelChanged();
2018-06-25 21:04:32 +00:00
}
2018-06-26 14:59:51 +00:00
void DataModel::passivModelChanged()
{
2018-11-03 21:29:38 +00:00
m_results.setPassivResult(m_passiv.getPoints());
emit modelChanged();
2018-06-26 14:59:51 +00:00
}
void DataModel::genitivModelChanged()
{
2018-11-03 21:29:38 +00:00
m_results.setGenitivResult(m_genitiv.getPoints());
emit modelChanged();
2018-06-26 14:59:51 +00:00
}