From f8c3dc35fdc53821c5db7b375ec5c6899c6d3f45 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 3 Nov 2018 22:29:38 +0100 Subject: [PATCH 1/2] Print a (unfinished) meta-data table --- source/DataModel.cpp | 87 +++++++++++++++++++------------ source/DataModel.h | 2 + source/MetaData/MetaDataModel.cpp | 37 +++++++++++-- source/MetaData/MetaDataModel.h | 2 + source/mainwindow.cpp | 12 ++--- 5 files changed, 98 insertions(+), 42 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index d96b868..f5fbeb4 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -2,37 +2,30 @@ #include +#include + DataModel::DataModel(QObject *parent) - : QObject(parent) - , m_metaData(this) - , m_verbEnd(this) - , m_genus(this) - , m_plural(this) - , m_results(this) - , m_akkusativ(this) - , m_dativ(this) - , m_v2Svk(this) + : QObject(parent) + , m_metaData(this) + , m_verbEnd(this) + , m_genus(this) + , m_plural(this) + , m_results(this) + , m_akkusativ(this) + , m_dativ(this) + , m_v2Svk(this) , m_passiv(this) , m_genitiv(this) { - 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_v2Svk, &V2SvkModel::dataChanged, this, - &DataModel::v2SvkModelChanged); - connect(&m_passiv, &PassivModel::dataChanged, this, - &DataModel::passivModelChanged); - connect(&m_genitiv, &GenitivModel::dataChanged, this, - &DataModel::genitivModelChanged); + 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_v2Svk, &V2SvkModel::dataChanged, this, &DataModel::v2SvkModelChanged); + connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged); + connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged); } void DataModel::write(QJsonObject &target) const @@ -44,8 +37,8 @@ void DataModel::write(QJsonObject &target) const 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"); + write(m_passiv, target, "Passiv"); + write(m_genitiv, target, "Genitiv"); } void DataModel::read(const QJsonObject &source) @@ -57,8 +50,36 @@ void DataModel::read(const QJsonObject &source) 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"); + read(m_passiv, source, "Passiv"); + read(m_genitiv, source, "Genitiv"); +} + +std::string DataModel::toHtml() const +{ + std::stringstream out; + + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "

ESGRAF 4-8 Auswertungsbogen

" << std::endl; + out << "

" << std::endl; + out << m_metaData.toHtml(); + out << "

" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + + return out.str(); } void DataModel::pluralModelChanged() @@ -113,14 +134,14 @@ void DataModel::v2SvkModelChanged() void DataModel::passivModelChanged() { - m_results.setPassivResult(m_passiv.getPoints()); + m_results.setPassivResult(m_passiv.getPoints()); emit modelChanged(); } void DataModel::genitivModelChanged() { - m_results.setGenitivResult(m_genitiv.getPoints()); + m_results.setGenitivResult(m_genitiv.getPoints()); emit modelChanged(); } diff --git a/source/DataModel.h b/source/DataModel.h index 20d1b31..b2d6f13 100644 --- a/source/DataModel.h +++ b/source/DataModel.h @@ -37,6 +37,8 @@ public: void write(QJsonObject &target) const; void read(const QJsonObject &source); + std::string toHtml() const; + signals: void modelChanged(); diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 3d797a9..822834d 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -2,8 +2,10 @@ #include +#include + MetaDataModel::MetaDataModel(QObject *parent) - : QAbstractTableModel(parent) + : QAbstractTableModel(parent) { m_dateOfBirth = QDate::currentDate().addYears(-9); m_dateOfTest = QDate::currentDate(); @@ -50,8 +52,7 @@ Qt::ItemFlags MetaDataModel::flags(const QModelIndex &modelIndex) const return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable; } -bool MetaDataModel::setData( - const QModelIndex &modelIndex, const QVariant &value, int role) +bool MetaDataModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role) { if (role != Qt::EditRole) { @@ -128,3 +129,33 @@ void MetaDataModel::read(const QJsonObject &json) setData(index(0, 3), json["date of test"].toVariant(), Qt::EditRole); setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole); } + +std::string MetaDataModel::toHtml() const +{ + std::ostringstream out; + + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "" << std::endl; + out << "
Name, Vorname" << m_participant.toStdString() << "Untersucher(in)" << m_instructor.toStdString() << "
GeburtsdatumBemerkungen
Untersuchungsdatum
Alter am Testtag
" << std::endl; + + return out.str(); +} diff --git a/source/MetaData/MetaDataModel.h b/source/MetaData/MetaDataModel.h index 8d5f614..6c81f8a 100644 --- a/source/MetaData/MetaDataModel.h +++ b/source/MetaData/MetaDataModel.h @@ -31,6 +31,8 @@ public: void write(QJsonObject &json) const; void read(const QJsonObject &json); + std::string toHtml() const; + Age getAge() const { return { m_dateOfBirth, m_dateOfTest }; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index ce4e36f..1f3242b 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -16,6 +16,8 @@ #include +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -135,6 +137,9 @@ void MainWindow::closeFile() void MainWindow::print() const { + std::ofstream htmlfile("print.html"); + htmlfile << m_dataModel->toHtml(); + QPrinter printer; QPrintDialog dialog(&printer); @@ -144,12 +149,7 @@ void MainWindow::print() const } QTextDocument printDoc; - printDoc.setHtml( - "" - "" - "

Hello World

" - "" - ""); + printDoc.setHtml(QString::fromStdString(m_dataModel->toHtml())); printDoc.print(&printer); } From fcbe356f75a03924add0fc07f5d797de911d28a8 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 4 Nov 2018 13:57:35 +0100 Subject: [PATCH 2/2] Print metadata table --- source/DataModel.cpp | 5 ----- source/MetaData/MetaDataModel.cpp | 25 ++++++++++++++++--------- source/mainwindow.cpp | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/DataModel.cpp b/source/DataModel.cpp index f5fbeb4..f5fc181 100644 --- a/source/DataModel.cpp +++ b/source/DataModel.cpp @@ -64,11 +64,6 @@ std::string DataModel::toHtml() const out << "body {" << std::endl; out << "font-family:sans-serif;" << std::endl; out << "}" << std::endl; - out << "table, th, td {" << std::endl; - out << "border: 1px solid black;" << std::endl; - out << "border-collapse: collapse;" << std::endl; - out << "padding: 5px;" << std::endl; - out << "}" << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; diff --git a/source/MetaData/MetaDataModel.cpp b/source/MetaData/MetaDataModel.cpp index 822834d..7219715 100644 --- a/source/MetaData/MetaDataModel.cpp +++ b/source/MetaData/MetaDataModel.cpp @@ -134,26 +134,33 @@ std::string MetaDataModel::toHtml() const { std::ostringstream out; - out << "" << std::endl; + out << "
" + << std::endl; out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; + out << "" << std::endl; + out << "" + << std::endl; + out << "" << std::endl; + out << "" + << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; - out << "" << std::endl; + out << "" + << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; - out << "" << std::endl; - out << "" << std::endl; + out << "" + << std::endl; + out << "" + << std::endl; out << "" << std::endl; out << "" << std::endl; out << "" << std::endl; - out << "" << std::endl; + out << "" << std::endl; out << "" << std::endl; out << "
Name, Vorname" << m_participant.toStdString() << "Untersucher(in)" << m_instructor.toStdString() << "Name, Vorname" << m_participant.toHtmlEscaped().toStdString() << "Untersucher(in)" << m_instructor.toHtmlEscaped().toStdString() << "
Geburtsdatum" << m_dateOfBirth.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "Bemerkungen
Untersuchungsdatum" << m_dateOfTest.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "" + << m_remarks.trimmed().toHtmlEscaped().replace("\n", "
").toStdString() << "
Alter am Testtag" << getAge().toString() << "
" << std::endl; diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 1f3242b..12bc99f 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -137,8 +137,8 @@ void MainWindow::closeFile() void MainWindow::print() const { - std::ofstream htmlfile("print.html"); - htmlfile << m_dataModel->toHtml(); + //std::ofstream htmlfile("print.html"); + //htmlfile << m_dataModel->toHtml(); QPrinter printer;