Print subtests 2, 3 and 4

feature/print-as-qtextdocument
mandlm 2018-12-08 21:02:35 +01:00
parent e2237110cf
commit 49b52f1dbc
21 changed files with 223 additions and 201 deletions

View File

@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6)
project(CheckableTestModel LANGUAGES CXX)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
add_library(${PROJECT_NAME}
CheckableTestModel.cpp
@ -22,4 +23,5 @@ target_link_libraries(${PROJECT_NAME}
CheckableItem
CheckableTest
Qt5::Core
Qt5::Gui
)

View File

@ -2,16 +2,17 @@
#include <QJsonArray>
#include <QSize>
#include <QTextTable>
#include <QDebug>
CheckableTestModel::CheckableTestModel(QObject *parent)
: QAbstractTableModel(parent)
: QAbstractTableModel(parent)
{
}
int CheckableTestModel::rowCount(const QModelIndex &) const
{
return static_cast<int>(m_tests.size());
return static_cast<int>(m_tests.size());
}
int CheckableTestModel::columnCount(const QModelIndex &) const
@ -20,7 +21,7 @@ int CheckableTestModel::columnCount(const QModelIndex &) const
for (const auto &test : m_tests)
{
columnCount = std::max(columnCount, static_cast<int>(test.size()));
columnCount = std::max(columnCount, static_cast<int>(test.size()));
}
return columnCount;
@ -37,17 +38,17 @@ QVariant CheckableTestModel::data(const QModelIndex &index, int role) const
{
auto &item = getItem(index);
switch (role)
{
case Qt::DisplayRole:
{
return item.getText().c_str();
}
case Qt::CheckStateRole:
{
return item.isChecked() ? Qt::Checked : Qt::Unchecked;
}
}
switch (role)
{
case Qt::DisplayRole:
{
return item.getText().c_str();
}
case Qt::CheckStateRole:
{
return item.isChecked() ? Qt::Checked : Qt::Unchecked;
}
}
}
catch (std::runtime_error &e)
{
@ -67,8 +68,7 @@ Qt::ItemFlags CheckableTestModel::flags(const QModelIndex &index) const
return Qt::NoItemFlags;
}
bool CheckableTestModel::setData(
const QModelIndex &index, const QVariant &value, int role)
bool CheckableTestModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!isValidIndex(index))
{
@ -93,8 +93,7 @@ bool CheckableTestModel::setData(
return false;
}
QVariant CheckableTestModel::headerData(
int section, Qt::Orientation orientation, int role) const
QVariant CheckableTestModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Vertical)
{
@ -104,7 +103,7 @@ QVariant CheckableTestModel::headerData(
}
}
return QAbstractTableModel::headerData(section, orientation, role);
return QAbstractTableModel::headerData(section, orientation, role);
}
bool CheckableTestModel::isValidIndex(const QModelIndex &index) const
@ -117,6 +116,129 @@ bool CheckableTestModel::isValidIndex(const QModelIndex &index) const
return false;
}
void CheckableTestModel::printTo(QTextCursor &cursor) const
{
QTextCharFormat headerFormat;
headerFormat.setFontPointSize(10);
cursor.insertBlock();
cursor.insertText("\n");
cursor.insertText(getName().c_str(), headerFormat);
printTableTo(cursor);
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n");
printSummaryTo(cursor);
cursor.movePosition(QTextCursor::End);
}
void CheckableTestModel::printTableTo(QTextCursor &cursor) const
{
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3)});
QTextTable *table = cursor.insertTable(m_tests.size() * 2, 13, tableFormat);
const char *emptyBox = "\u2610";
//const char *checkBox = "\u2611";
const char *checkBox = "x";
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);
cell.setFormat(cellFormat);
auto charFormat = textCursor.charFormat();
charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
charFormat.setFontPointSize(8);
textCursor.setCharFormat(charFormat);
textCursor.insertText(text);
};
int currentRow = 0;
for (const auto &test : m_tests)
{
table->mergeCells(currentRow, 0, 2, 1);
int currentColumn = 0;
insertText(currentRow, currentColumn, test.name());
currentColumn++;
for (const auto &item : test.items())
{
insertText(currentRow, currentColumn, item.getText().c_str());
insertText(currentRow + 1, currentColumn, item.isChecked() ? checkBox : emptyBox);
currentColumn++;
}
insertText(currentRow + 1, 12, QString::number(test.getPoints()));
currentRow += 2;
}
}
void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const
{
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 76),
QTextLength(QTextLength::PercentageLength, 20),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3)});
QTextTable *table = cursor.insertTable(1, 4, 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);
cell.setFormat(cellFormat);
auto charFormat = textCursor.charFormat();
charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle);
charFormat.setFontPointSize(8);
textCursor.setCharFormat(charFormat);
textCursor.insertText(text);
};
insertText(0, 1, "Rohwertpunkte Total:");
insertText(0, 3, QString::number(getPoints()));
}
CheckableItems &CheckableTestModel::getItems(const QModelIndex &index)
{
if (index.row() < m_tests.size())
@ -127,8 +249,7 @@ CheckableItems &CheckableTestModel::getItems(const QModelIndex &index)
throw std::runtime_error("invalid index");
}
const CheckableItems &CheckableTestModel::getItems(
const QModelIndex &index) const
const CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) const
{
if (index.row() < m_tests.size())
{
@ -162,7 +283,7 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const
unsigned int CheckableTestModel::getPoints() const
{
unsigned int points = 0;
unsigned int points = 0;
for (const auto &test : m_tests)
{

View File

@ -2,6 +2,7 @@
#include "CheckableTest.h"
#include <QAbstractTableModel>
#include <QTextCursor>
class CheckableTestModel : public QAbstractTableModel
{
@ -27,9 +28,15 @@ public:
unsigned int getPoints() const;
virtual void printTo(QTextCursor &cursor) const;
protected:
virtual bool isValidIndex(const QModelIndex &index) const;
virtual std::string getName() const = 0;
void printTableTo(QTextCursor &cursor) const;
void printSummaryTo(QTextCursor &cursor) const;
private:
CheckableItems &getItems(const QModelIndex &index);
const CheckableItems &getItems(const QModelIndex &index) const;

View File

@ -63,22 +63,23 @@ void DataModel::read(std::istream &inStream)
void DataModel::printTo(QTextCursor &cursor) const
{
QTextCharFormat titleFormat;
titleFormat.setFontPointSize(18);
titleFormat.setFontPointSize(14);
cursor.insertText("ESGRAF 4-8 Auswertungsbogen", titleFormat);
cursor.insertText("\n", titleFormat);
m_metaData.printTo(cursor);
cursor.insertText("\n", titleFormat);
m_v2Svk.printTo(cursor);
cursor.insertText("\n", titleFormat);
//m_v2Svk.printTo(cursor);
m_verbEnd.printTo(cursor);
cursor.insertText("\n", titleFormat);
m_genus.printTo(cursor);
m_akkusativ.printTo(cursor);
m_dativ.printTo(cursor);
//m_plural.printTo(cursor);
//m_genitiv.printTo(cursor);
//m_passiv.printTo(cursor);
//m_results.printTo(cursor);
//cursor.insertText("\n", titleFormat);
}
void DataModel::pluralModelChanged()

View File

@ -136,6 +136,7 @@ void MetaDataModel::printTo(QTextCursor &cursor) const
cursor.insertBlock();
QTextTableFormat tableFormat;
tableFormat.setBorderStyle(QTextTableFormat::BorderStyle_None);
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
@ -161,7 +162,10 @@ void MetaDataModel::printTo(QTextCursor &cursor) const
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(m_dateOfBirth.toString("dd.MM.yyyy"));
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Bemerkungen:");
if (!m_remarks.trimmed().isEmpty())
{
cursor.insertText("Bemerkungen:");
}
cursor.movePosition(QTextCursor::NextRow);
cursor.insertText("Untersuchungsdatum");
@ -175,6 +179,6 @@ void MetaDataModel::printTo(QTextCursor &cursor) const
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(getAge().toString().c_str());
cursor.movePosition(QTextCursor::NextBlock);
cursor.movePosition(QTextCursor::End);
}

View File

@ -105,3 +105,8 @@ void AkkusativModel::write(ESGRAF48::AkkusativModel &model) const
futterModel->set_zucker(testItems[7].isChecked());
}
}
std::string AkkusativModel::getName() const
{
return "Subtest 4: Akkusativ und Dativ";
}

View File

@ -12,4 +12,7 @@ public:
void read(const ESGRAF48::AkkusativModel &model);
void write(ESGRAF48::AkkusativModel &model) const;
protected:
std::string getName() const override;
};

View File

@ -105,3 +105,8 @@ void DativModel::write(ESGRAF48::DativModel &model) const
futterModel->set_zucker(testItems[7].isChecked());
}
}
std::string DativModel::getName() const
{
return "";
}

View File

@ -12,4 +12,7 @@ public:
void read(const ESGRAF48::DativModel &model);
void write(ESGRAF48::DativModel &model) const;
protected:
std::string getName() const override;
};

View File

@ -95,3 +95,8 @@ void GenusModel::write(ESGRAF48::GenusModel &model) const
zirkusModel->set_baum(testItems[3].isChecked());
}
}
std::string GenusModel::getName() const
{
return "Subtest 3: Genus";
}

View File

@ -12,4 +12,7 @@ public:
void read(const ESGRAF48::GenusModel &model);
void write(ESGRAF48::GenusModel &model) const;
protected:
std::string getName() const override;
};

View File

@ -107,3 +107,8 @@ void GenitivModel::write(ESGRAF48::LateSkillsGenitivModel &model) const
attributierungModel->set_guertel2(testItems[9].isChecked());
}
}
std::string GenitivModel::getName() const
{
return "";
}

View File

@ -14,4 +14,7 @@ public:
void read(const ESGRAF48::LateSkillsGenitivModel &model);
void write(ESGRAF48::LateSkillsGenitivModel &model) const;
protected:
std::string getName() const override;
};

View File

@ -65,3 +65,8 @@ void PassivModel::write(ESGRAF48::LateSkillsPassivModel &model) const
model.set_fleisch1(testItems[8].isChecked());
model.set_fleisch2(testItems[9].isChecked());
}
std::string PassivModel::getName() const
{
return "Subtest 6: Späte Fähigkeiten (7;0 - 8;11)";
}

View File

@ -14,4 +14,7 @@ public:
void read(const ESGRAF48::LateSkillsPassivModel &model);
void write(ESGRAF48::LateSkillsPassivModel &model) const;
protected:
std::string getName() const override;
};

View File

@ -51,3 +51,8 @@ void PluralModel::write(ESGRAF48::PluralModel &model) const
model.set_baer(testItems[7].isChecked());
model.set_apfel(testItems[8].isChecked());
}
std::string PluralModel::getName() const
{
return "Subtest 5: Plural";
}

View File

@ -15,4 +15,7 @@ public:
void read(const ESGRAF48::PluralModel &model);
void write(ESGRAF48::PluralModel &model) const;
protected:
std::string getName() const override;
};

View File

@ -200,22 +200,7 @@ void V2SvkModel::read(const ESGRAF48::V2SvkModel &model)
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void V2SvkModel::printTo(QTextCursor &cursor) const
std::string V2SvkModel::getName() const
{
cursor.insertBlock();
QTextCharFormat headerFormat;
headerFormat.setFontPointSize(12);
cursor.insertText(
"Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)",
headerFormat);
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
QTextTable *table = cursor.insertTable(1, 1, tableFormat);
cursor.movePosition(QTextCursor::NextBlock);
return "Subtest 1: Verbzweitstellungsregel (V2) und Subjekt-Verb-Kontrollregel (SVK)";
}

View File

@ -18,8 +18,8 @@ public:
void write(ESGRAF48::V2SvkModel &model) const;
void read(const ESGRAF48::V2SvkModel &model);
void printTo(QTextCursor &cursor) const;
protected:
bool isValidIndex(const QModelIndex &index) const override;
std::string getName() const override;
};

View File

@ -98,154 +98,7 @@ void VerbEndModel::read(const ESGRAF48::VerbEndModel &model)
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
}
void VerbEndModel::printTo(QTextCursor &cursor) const
std::string VerbEndModel::getName() const
{
cursor.insertBlock();
QTextCharFormat headerFormat;
headerFormat.setFontPointSize(12);
cursor.insertText("Subtest 2: Verbendstellungsregel (VE)", headerFormat);
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 15),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 9),
QTextLength(QTextLength::PercentageLength, 2),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 5)});
QTextTable *table = cursor.insertTable(6, 13, tableFormat);
table->mergeCells(0, 0, 2, 1);
table->mergeCells(2, 0, 2, 1);
table->mergeCells(4, 0, 2, 1);
const char *emptyBox = "\u2610";
//const char *checkBox = "\u2611";
const char *checkBox = "x";
cursor.insertText("Telefonat");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextRow);
const auto &telTestItems = m_tests.at(0).items();
cursor.insertText(telTestItems[0].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[1].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[2].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[3].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[4].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[5].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(telTestItems[6].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(QString::number(m_tests.at(0).getPoints()));
cursor.movePosition(QTextCursor::NextRow);
cursor.insertText("Zaubertrick");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextRow);
const auto &trickTestItems = m_tests.at(1).items();
cursor.insertText(trickTestItems[0].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[1].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[2].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[3].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[4].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[5].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(trickTestItems[6].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(QString::number(m_tests.at(1).getPoints()));
cursor.movePosition(QTextCursor::NextRow);
cursor.insertText("Zauberregel");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Kausal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Final");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Temporal");
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText("Relativ");
cursor.movePosition(QTextCursor::NextRow);
const auto &regelTestItems = m_tests.at(2).items();
cursor.insertText(regelTestItems[0].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[1].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[2].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[3].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[4].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(regelTestItems[5].isChecked() ? checkBox : emptyBox);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.movePosition(QTextCursor::NextCell);
cursor.insertText(QString::number(m_tests.at(2).getPoints()));
cursor.movePosition(QTextCursor::NextBlock);
}
return "Subtest 2: Verbendstellungsregel (VE)";
};

View File

@ -15,5 +15,6 @@ public:
void write(ESGRAF48::VerbEndModel &model) const;
void read(const ESGRAF48::VerbEndModel &model);
void printTo(QTextCursor &cursor) const;
protected:
std::string getName() const override;
};