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

207 lines
5.8 KiB
C++
Raw Permalink 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>
2019-10-05 14:14:45 +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
{
2019-10-05 14:14:45 +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);
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);
connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged);
connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged);
2018-05-16 05:02:12 +00:00
}
2019-10-05 14:14:45 +00:00
void DataModel::write(const QString& filename) const
2018-11-13 23:17:29 +00:00
{
2019-10-05 14:14:45 +00:00
ESGRAF48::DataModel dataModel;
m_metaData.write(*dataModel.mutable_metadata());
m_wfModel.write(*dataModel.mutable_v2svk());
m_otModel.write(*dataModel.mutable_v2svk());
m_tPrModel.write(*dataModel.mutable_v2svk());
m_tPeModel.write(*dataModel.mutable_v2svk());
m_verbEnd.write(*dataModel.mutable_verbend());
m_genus.write(*dataModel.mutable_genus());
m_akkusativ.write(*dataModel.mutable_akkusativ());
m_dativ.write(*dataModel.mutable_dativ());
m_plural.write(*dataModel.mutable_plural());
m_genitiv.write(*dataModel.mutable_lateskillsgenitiv());
m_passiv.write(*dataModel.mutable_lateskillspassiv());
QFile outFile(filename);
if (!outFile.open(QIODevice::WriteOnly))
{
throw std::runtime_error("failed to open file");
}
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
}
2019-10-05 14:14:45 +00:00
void DataModel::read(const QString& filename)
2018-11-13 23:17:29 +00:00
{
2019-10-05 14:14:45 +00:00
QFile inFile(filename);
if (!inFile.open(QIODevice::ReadOnly))
{
throw std::runtime_error("failed to read file");
}
ESGRAF48::DataModel dataModel;
bool success = dataModel.ParseFromFileDescriptor(inFile.handle());
if (success == false)
{
throw std::runtime_error("invalid file format");
}
m_metaData.read(dataModel.metadata());
m_wfModel.read(dataModel.v2svk());
m_otModel.read(dataModel.v2svk());
m_tPrModel.read(dataModel.v2svk());
m_tPeModel.read(dataModel.v2svk());
m_verbEnd.read(dataModel.verbend());
m_genus.read(dataModel.genus());
m_akkusativ.read(dataModel.akkusativ());
m_dativ.read(dataModel.dativ());
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
2019-10-05 14:14:45 +00:00
void DataModel::printTo(QPrinter& printer) const
2018-11-03 21:29:38 +00:00
{
2019-10-05 14:14:45 +00:00
QPainter painter;
painter.begin(&printer);
2019-02-03 18:53:51 +00:00
2019-10-05 14:14:45 +00:00
painter.setFont(PrintableModel::h1Font());
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-10-05 14:14:45 +00:00
m_metaData.printTo(painter);
2019-02-03 18:53:51 +00:00
2019-10-05 14:14:45 +00:00
m_wfModel.printTo(painter);
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());
2019-02-03 18:53:51 +00:00
2019-10-05 14:14:45 +00:00
m_verbEnd.printTo(painter);
m_genus.printTo(painter);
2019-02-03 18:53:51 +00:00
2019-10-05 14:14:45 +00:00
printer.newPage();
painter.resetTransform();
2019-02-03 18:53:51 +00:00
2019-10-05 14:14:45 +00:00
m_akkusativ.printTo(painter);
m_dativ.printTo(painter);
m_plural.printTo(painter);
2019-02-03 18:53:51 +00:00
2019-10-05 14:14:45 +00:00
m_passiv.printTo(painter);
m_genitiv.printTo(painter);
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
m_results.printTo(painter);
2019-02-07 21:36:39 +00:00
2019-10-05 14:14:45 +00:00
painter.end();
2018-05-16 05:02:12 +00:00
}
2018-06-15 15:53:43 +00:00
void DataModel::pluralModelChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setPluralResult(m_plural.getPoints());
2019-10-05 14:14:45 +00:00
emit modelChanged();
}
void DataModel::metaDataChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setAge(m_metaData.getAge());
2019-10-05 14:14:45 +00:00
emit modelChanged();
}
2018-06-15 15:53:43 +00:00
void DataModel::genusModelChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setGenusResult(m_genus.getPoints());
2019-10-05 14:14:45 +00:00
emit modelChanged();
2018-06-15 15:53:43 +00:00
}
2018-06-15 16:36:58 +00:00
void DataModel::verbEndModelChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setVerbEndResult(m_verbEnd.getPoints());
2019-10-05 14:14:45 +00:00
emit modelChanged();
2018-06-15 16:36:58 +00:00
}
void DataModel::akkusativModelChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setAkkusativResult(m_akkusativ.getPoints());
2019-10-05 14:14:45 +00:00
emit modelChanged();
}
void DataModel::dativModelChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setDativResult(m_dativ.getPoints());
2019-10-05 14:14:45 +00:00
emit modelChanged();
}
2018-06-25 21:04:32 +00:00
void DataModel::v2SvkModelChanged()
{
2019-10-05 14:14:45 +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());
2019-10-05 14:14:45 +00:00
emit modelChanged();
2018-06-25 21:04:32 +00:00
}
2018-06-26 14:59:51 +00:00
void DataModel::passivModelChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setPassivResult(m_passiv.getPoints());
2019-10-05 14:14:45 +00:00
emit modelChanged();
2018-06-26 14:59:51 +00:00
}
void DataModel::genitivModelChanged()
{
2019-10-05 14:14:45 +00:00
m_results.setGenitivResult(m_genitiv.getPoints());
2019-10-05 14:14:45 +00:00
emit modelChanged();
2018-06-26 14:59:51 +00:00
}