Print subtest 1

feature/print-as-qtextdocument
mandlm 2018-12-13 20:46:38 +01:00
parent be3a3f453d
commit a718113747
4 changed files with 134 additions and 53 deletions

View File

@ -6,7 +6,7 @@ V2SvkModel::V2SvkModel(QObject *parent)
: CheckableTestModel(parent)
{
m_tests = {
{"W-Frage",
{"W-Fragen",
{"Affe", "Affe", "Affe", "Affe", "Schwein", "Schwein", "Schwein", "Schwein", "Gans",
"Gans", "Gans", "Gans"}},
{"Verbtrennung", {"", "Affe", "", "", "", "", "", "Schwein", "", "", "Gans", ""}},
@ -31,7 +31,7 @@ V2SvkModel::V2SvkModel(QObject *parent)
};
}
unsigned int V2SvkModel::getV2Points()
unsigned int V2SvkModel::getV2Points() const
{
unsigned int points = 0;
@ -51,7 +51,7 @@ unsigned int V2SvkModel::getV2Points()
return points;
}
unsigned int V2SvkModel::getSvkPoints()
unsigned int V2SvkModel::getSvkPoints() const
{
unsigned int points = 0;
@ -208,59 +208,142 @@ std::string V2SvkModel::getName() const
}
void V2SvkModel::printTableTo(QTextCursor &cursor) const
{
QTextTableFormat tableFormat12;
tableFormat12.setCellPadding(2);
tableFormat12.setCellSpacing(0);
tableFormat12.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 13),
QTextLength(QTextLength::PercentageLength, 3),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3)});
QTextTableFormat tableFormat6;
tableFormat6.setCellPadding(2);
tableFormat6.setCellSpacing(0);
tableFormat6.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
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, 13),
QTextLength(QTextLength::PercentageLength, 3),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3)});
auto writeHeader = [](QTextTable *table, const CheckableTest &test, int colSpan) {
table->mergeCells(0, 0, 2, 1);
int column = 1;
for (auto it = std::begin(test.items()); it != std::end(test.items());
std::advance(it, colSpan))
{
table->mergeCells(0, column, 1, colSpan);
setCellText(*table, 0, column, it->getText().c_str());
column += colSpan;
}
};
auto writeLine = [](QTextTable *table, const CheckableTest &test, int row, int resultColumn) {
int column = 0;
setCellText(*table, row, column, test.name());
for (const auto item : test.items())
{
column++;
if (!item.getText().empty())
{
setCellChecked(*table, row, column, item.isChecked());
}
}
setCellNumber(*table, row, resultColumn, test.getPoints());
};
{
QTextTable *table = cursor.insertTable(4, 17, tableFormat12);
writeHeader(table, m_tests[0], 4);
writeLine(table, m_tests[0], 1, 14);
writeLine(table, m_tests[1], 2, 14);
writeLine(table, m_tests[2], 3, 16);
}
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n");
{
QTextTable *table = cursor.insertTable(3, 17, tableFormat12);
writeHeader(table, m_tests[3], 4);
writeLine(table, m_tests[3], 1, 14);
writeLine(table, m_tests[4], 2, 16);
}
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n");
{
QTextTable *table = cursor.insertTable(3, 11, tableFormat6);
writeHeader(table, m_tests[5], 2);
writeLine(table, m_tests[5], 1, 8);
writeLine(table, m_tests[6], 2, 10);
}
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();
cursor.insertText("\n");
{
QTextTable *table = cursor.insertTable(5, 11, tableFormat6);
writeHeader(table, m_tests[7], 2);
writeLine(table, m_tests[7], 1, 8);
writeLine(table, m_tests[8], 2, 8);
writeLine(table, m_tests[9], 3, 10);
writeLine(table, m_tests[10], 4, 10);
}
}
void V2SvkModel::printSummaryTo(QTextCursor &cursor) const
{
QTextTableFormat tableFormat;
tableFormat.setCellPadding(2);
tableFormat.setCellSpacing(0);
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 20),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 5),
QTextLength(QTextLength::PercentageLength, 13),
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::PercentageLength, 72),
QTextLength(QTextLength::PercentageLength, 20),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3),
QTextLength(QTextLength::PercentageLength, 1),
QTextLength(QTextLength::PercentageLength, 3)});
QTextTable *table = cursor.insertTable(2, 17, tableFormat);
QTextTable *table = cursor.insertTable(1, 6, tableFormat);
int currentRow = 0;
int currentTest = 0;
//for (const auto &test : m_tests)
{
table->mergeCells(currentRow, 0, 2, 1);
int currentColumn = 0;
setCellText(*table, currentRow, currentColumn, m_tests[0].name());
currentColumn++;
for (auto it = std::begin(m_tests[0].items()); it != std::end(m_tests[0].items()); std::advance(it, 4))
{
table->mergeCells(currentRow, currentColumn, 1, 4);
auto itemName = it->getText();
setCellText(*table, currentRow, currentColumn, itemName.c_str());
setCellChecked(*table, currentRow + 1, currentColumn, it->isChecked());
setCellChecked(*table, currentRow + 1, currentColumn + 1, (it + 1)->isChecked());
setCellChecked(*table, currentRow + 1, currentColumn + 2, (it + 2)->isChecked());
setCellChecked(*table, currentRow + 1, currentColumn + 3, (it + 3)->isChecked());
currentColumn += 4;
}
setCellNumber(*table, currentRow + 1, 14, m_tests[0].getPoints());
currentRow += 2;
}
setCellText(*table, 0, 1, "Rohwertpunkte Total:");
setCellNumber(*table, 0, 3, getV2Points());
setCellNumber(*table, 0, 5, getSvkPoints());
}

View File

@ -12,8 +12,8 @@ class V2SvkModel : public CheckableTestModel
public:
V2SvkModel(QObject *parent);
unsigned int getV2Points();
unsigned int getSvkPoints();
unsigned int getV2Points() const;
unsigned int getSvkPoints() const;
void write(ESGRAF48::V2SvkModel &model) const;
void read(const ESGRAF48::V2SvkModel &model);
@ -23,4 +23,5 @@ protected:
std::string getName() const override;
void printTableTo(QTextCursor &cursor) const override;
void printSummaryTo(QTextCursor &cursor) const override;
};

View File

@ -161,8 +161,6 @@ void MainWindow::print() const
QTextDocument printDoc;
QTextCursor printCursor(&printDoc);
m_dataModel.printTo(printCursor);
printDoc.print(&printer);
}
void MainWindow::dataModelChanged()

View File

@ -5,7 +5,6 @@
#include <QMainWindow>
#include <QString>
class DataModel;
class QDataWidgetMapper;