Print results

This commit is contained in:
Michael Mandl 2018-12-09 12:49:12 +01:00
parent c065b04cbe
commit 2570d5d5b5
3 changed files with 82 additions and 30 deletions

View file

@ -79,7 +79,7 @@ void DataModel::printTo(QTextCursor &cursor) const
//m_genitiv.printTo(cursor); //m_genitiv.printTo(cursor);
//m_passiv.printTo(cursor); //m_passiv.printTo(cursor);
//m_results.printTo(cursor); m_results.printTo(cursor);
} }
void DataModel::pluralModelChanged() void DataModel::pluralModelChanged()

View file

@ -10,13 +10,13 @@
#include "PassivPR.h" #include "PassivPR.h"
#include "GenitivPR.h" #include "GenitivPR.h"
#include <QTextTable>
#include <QDebug> #include <QDebug>
ResultModel::ResultModel(QObject *parent) ResultModel::ResultModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
{ {
m_results = { { "V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", m_results = {"V2", "SVK", "VE", "Passiv", "Genus", "Akkusativ", "Dativ", "Genitiv", "Plural"};
"Genitiv", "Plural" } };
} }
int ResultModel::rowCount(const QModelIndex &parent) const int ResultModel::rowCount(const QModelIndex &parent) const
@ -81,8 +81,7 @@ QVariant ResultModel::data(const QModelIndex &index, int role) const
return {}; return {};
} }
QVariant ResultModel::headerData( QVariant ResultModel::headerData(int section, Qt::Orientation orientation, int role) const
int section, Qt::Orientation orientation, int role) const
{ {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
{ {
@ -102,11 +101,11 @@ QVariant ResultModel::headerData(
case 0: case 0:
return "RP"; return "RP";
case 1: case 1:
return ">= PR 84"; return "\u2265 PR 84";
case 2: case 2:
return "< PR 84"; return "< PR 84";
case 3: case 3:
return "<= PR 16"; return "\u2264 PR 16";
default: default:
return {}; return {};
} }
@ -213,20 +212,74 @@ void ResultModel::setGenitivResult(unsigned int points)
void ResultModel::printTo(QTextCursor &cursor) const void ResultModel::printTo(QTextCursor &cursor) const
{ {
cursor.insertBlock();
QTextCharFormat headerFormat; QTextCharFormat headerFormat;
headerFormat.setFontPointSize(12); headerFormat.setFontPointSize(10);
cursor.insertText( cursor.insertBlock();
"Prozentränge (PR)", cursor.insertText("\nProzentränge (PR)");
headerFormat);
QTextTableFormat tableFormat; QTextTableFormat tableFormat;
tableFormat.setCellPadding(2); tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0); tableFormat.setCellSpacing(0);
QTextTable *table = cursor.insertTable(1, 1, tableFormat); const unsigned int columnCount = 10;
cursor.movePosition(QTextCursor::NextBlock); tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10),
QTextLength(QTextLength::PercentageLength, 10)});
QTextTable *table = cursor.insertTable(4, columnCount, tableFormat);
auto insertText = [&table](int row, int column, const QString &text) {
auto cell = table->cellAt(row, column);
auto textCursor = cell.firstCursorPosition();
auto blockFormat = textCursor.blockFormat();
blockFormat.setAlignment(Qt::AlignCenter);
textCursor.setBlockFormat(blockFormat);
auto cellFormat = cell.format();
cellFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
if (row == 3)
{
QBrush backgroundBrush(QColor(192, 192, 192));
cellFormat.setBackground(backgroundBrush);
}
cell.setFormat(cellFormat);
auto charFormat = textCursor.charFormat();
charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
charFormat.setFontPointSize(8);
if (row == 0 || column == 0)
{
charFormat.setFontWeight(QFont::Bold);
}
textCursor.setCharFormat(charFormat);
textCursor.insertText(text);
};
insertText(1, 0, "\u2265 PR 84");
insertText(2, 0, "< PR 84");
insertText(3, 0, "\u2264 PR 16");
for (size_t index = 0; index < m_results.size(); ++index)
{
insertText(0, index + 1, m_results[index].name());
int pr = m_results[index].pr();
insertText(1, index + 1, pr >= 84 ? QString::number(pr) : "-");
insertText(2, index + 1, pr < 84 && pr > 16 ? QString::number(pr) : "-");
insertText(3, index + 1, pr <= 16 ? QString::number(pr) : "-");
}
} }

View file

@ -6,7 +6,6 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QTextCursor> #include <QTextCursor>
class ResultModel : public QAbstractTableModel class ResultModel : public QAbstractTableModel
{ {
Q_OBJECT Q_OBJECT