Merge branch 'feature/print-structure' into develop
This commit is contained in:
commit
590e1dbfc6
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
DataModel::DataModel(QObject *parent)
|
DataModel::DataModel(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_metaData(this)
|
, m_metaData(this)
|
||||||
@ -15,24 +17,15 @@ DataModel::DataModel(QObject *parent)
|
|||||||
, m_passiv(this)
|
, m_passiv(this)
|
||||||
, m_genitiv(this)
|
, m_genitiv(this)
|
||||||
{
|
{
|
||||||
connect(&m_plural, &PluralModel::dataChanged, this,
|
connect(&m_plural, &PluralModel::dataChanged, this, &DataModel::pluralModelChanged);
|
||||||
&DataModel::pluralModelChanged);
|
connect(&m_metaData, &MetaDataModel::dataChanged, this, &DataModel::metaDataChanged);
|
||||||
connect(&m_metaData, &MetaDataModel::dataChanged, this,
|
connect(&m_genus, &GenusModel::dataChanged, this, &DataModel::genusModelChanged);
|
||||||
&DataModel::metaDataChanged);
|
connect(&m_verbEnd, &VerbEndModel::dataChanged, this, &DataModel::verbEndModelChanged);
|
||||||
connect(&m_genus, &GenusModel::dataChanged, this,
|
connect(&m_akkusativ, &AkkusativModel::dataChanged, this, &DataModel::akkusativModelChanged);
|
||||||
&DataModel::genusModelChanged);
|
connect(&m_dativ, &DativModel::dataChanged, this, &DataModel::dativModelChanged);
|
||||||
connect(&m_verbEnd, &VerbEndModel::dataChanged, this,
|
connect(&m_v2Svk, &V2SvkModel::dataChanged, this, &DataModel::v2SvkModelChanged);
|
||||||
&DataModel::verbEndModelChanged);
|
connect(&m_passiv, &PassivModel::dataChanged, this, &DataModel::passivModelChanged);
|
||||||
connect(&m_akkusativ, &AkkusativModel::dataChanged, this,
|
connect(&m_genitiv, &GenitivModel::dataChanged, this, &DataModel::genitivModelChanged);
|
||||||
&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
|
void DataModel::write(QJsonObject &target) const
|
||||||
@ -61,6 +54,29 @@ void DataModel::read(const QJsonObject &source)
|
|||||||
read(m_genitiv, source, "Genitiv");
|
read(m_genitiv, source, "Genitiv");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string DataModel::toHtml() const
|
||||||
|
{
|
||||||
|
std::stringstream out;
|
||||||
|
|
||||||
|
out << "<html>" << std::endl;
|
||||||
|
out << "<head>" << std::endl;
|
||||||
|
out << "<style>" << std::endl;
|
||||||
|
out << "body {" << std::endl;
|
||||||
|
out << "font-family:sans-serif;" << std::endl;
|
||||||
|
out << "}" << std::endl;
|
||||||
|
out << "</style>" << std::endl;
|
||||||
|
out << "</head>" << std::endl;
|
||||||
|
out << "<body>" << std::endl;
|
||||||
|
out << "<h2>ESGRAF 4-8 Auswertungsbogen</h2>" << std::endl;
|
||||||
|
out << "<p>" << std::endl;
|
||||||
|
out << m_metaData.toHtml();
|
||||||
|
out << "</p>" << std::endl;
|
||||||
|
out << "</body>" << std::endl;
|
||||||
|
out << "</html>" << std::endl;
|
||||||
|
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
void DataModel::pluralModelChanged()
|
void DataModel::pluralModelChanged()
|
||||||
{
|
{
|
||||||
m_results.setPluralResult(m_plural.getPoints());
|
m_results.setPluralResult(m_plural.getPoints());
|
||||||
|
@ -37,6 +37,8 @@ public:
|
|||||||
void write(QJsonObject &target) const;
|
void write(QJsonObject &target) const;
|
||||||
void read(const QJsonObject &source);
|
void read(const QJsonObject &source);
|
||||||
|
|
||||||
|
std::string toHtml() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void modelChanged();
|
void modelChanged();
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
MetaDataModel::MetaDataModel(QObject *parent)
|
MetaDataModel::MetaDataModel(QObject *parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
{
|
{
|
||||||
@ -50,8 +52,7 @@ Qt::ItemFlags MetaDataModel::flags(const QModelIndex &modelIndex) const
|
|||||||
return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable;
|
return QAbstractTableModel::flags(modelIndex) | Qt::ItemIsEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MetaDataModel::setData(
|
bool MetaDataModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
|
||||||
const QModelIndex &modelIndex, const QVariant &value, int role)
|
|
||||||
{
|
{
|
||||||
if (role != Qt::EditRole)
|
if (role != Qt::EditRole)
|
||||||
{
|
{
|
||||||
@ -128,3 +129,40 @@ void MetaDataModel::read(const QJsonObject &json)
|
|||||||
setData(index(0, 3), json["date of test"].toVariant(), Qt::EditRole);
|
setData(index(0, 3), json["date of test"].toVariant(), Qt::EditRole);
|
||||||
setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole);
|
setData(index(0, 4), json["remarks"].toVariant(), Qt::EditRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MetaDataModel::toHtml() const
|
||||||
|
{
|
||||||
|
std::ostringstream out;
|
||||||
|
|
||||||
|
out << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" frame=\"box\" rules=\"all\">"
|
||||||
|
<< std::endl;
|
||||||
|
out << "<tr>" << std::endl;
|
||||||
|
out << "<td width=\"25%\">Name, Vorname</td>" << std::endl;
|
||||||
|
out << "<td width=\"25%\">" << m_participant.toHtmlEscaped().toStdString() << "</td>"
|
||||||
|
<< std::endl;
|
||||||
|
out << "<td width=\"25%\">Untersucher(in)</td>" << std::endl;
|
||||||
|
out << "<td width=\"25%\">" << m_instructor.toHtmlEscaped().toStdString() << "</td>"
|
||||||
|
<< std::endl;
|
||||||
|
out << "</tr>" << std::endl;
|
||||||
|
out << "<tr>" << std::endl;
|
||||||
|
out << "<td>Geburtsdatum</td>" << std::endl;
|
||||||
|
out << "<td>" << m_dateOfBirth.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "</td>"
|
||||||
|
<< std::endl;
|
||||||
|
out << "<td colspan=\"2\">Bemerkungen</td>" << std::endl;
|
||||||
|
out << "</tr>" << std::endl;
|
||||||
|
out << "<tr>" << std::endl;
|
||||||
|
out << "<td>Untersuchungsdatum</td>" << std::endl;
|
||||||
|
out << "<td>" << m_dateOfTest.toString("dd.MM.yyyy").toHtmlEscaped().toStdString() << "</td>"
|
||||||
|
<< std::endl;
|
||||||
|
out << "<td colspan=\"2\" rowspan=\"2\">"
|
||||||
|
<< m_remarks.trimmed().toHtmlEscaped().replace("\n", "<br>").toStdString() << "</td>"
|
||||||
|
<< std::endl;
|
||||||
|
out << "</tr>" << std::endl;
|
||||||
|
out << "<tr>" << std::endl;
|
||||||
|
out << "<td>Alter am Testtag</td>" << std::endl;
|
||||||
|
out << "<td>" << getAge().toString() << "</td>" << std::endl;
|
||||||
|
out << "</tr>" << std::endl;
|
||||||
|
out << "</table>" << std::endl;
|
||||||
|
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
@ -31,6 +31,8 @@ public:
|
|||||||
void write(QJsonObject &json) const;
|
void write(QJsonObject &json) const;
|
||||||
void read(const QJsonObject &json);
|
void read(const QJsonObject &json);
|
||||||
|
|
||||||
|
std::string toHtml() const;
|
||||||
|
|
||||||
Age getAge() const
|
Age getAge() const
|
||||||
{
|
{
|
||||||
return { m_dateOfBirth, m_dateOfTest };
|
return { m_dateOfBirth, m_dateOfTest };
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
@ -135,6 +137,9 @@ void MainWindow::closeFile()
|
|||||||
|
|
||||||
void MainWindow::print() const
|
void MainWindow::print() const
|
||||||
{
|
{
|
||||||
|
//std::ofstream htmlfile("print.html");
|
||||||
|
//htmlfile << m_dataModel->toHtml();
|
||||||
|
|
||||||
QPrinter printer;
|
QPrinter printer;
|
||||||
|
|
||||||
QPrintDialog dialog(&printer);
|
QPrintDialog dialog(&printer);
|
||||||
@ -144,12 +149,7 @@ void MainWindow::print() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QTextDocument printDoc;
|
QTextDocument printDoc;
|
||||||
printDoc.setHtml(
|
printDoc.setHtml(QString::fromStdString(m_dataModel->toHtml()));
|
||||||
"<html>"
|
|
||||||
"<body>"
|
|
||||||
"<h2>Hello World</h2>"
|
|
||||||
"</body>"
|
|
||||||
"</hthml>");
|
|
||||||
|
|
||||||
printDoc.print(&printer);
|
printDoc.print(&printer);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user