diff --git a/source/CheckableTestModel/CheckableTestModel.cpp b/source/CheckableTestModel/CheckableTestModel.cpp index 953089a..504ab98 100644 --- a/source/CheckableTestModel/CheckableTestModel.cpp +++ b/source/CheckableTestModel/CheckableTestModel.cpp @@ -191,32 +191,6 @@ void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const setCellNumber(*table, 0, 3, getPoints()); } -void CheckableTestModel::setCellText(QTextTable &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); -} - -void CheckableTestModel::setCellChecked(QTextTable &table, int row, int column, bool check) -{ - setCellText(table, row, column, check ? "x" : "\u2610"); -} - CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) { if (index.row() < m_tests.size()) diff --git a/source/CheckableTestModel/CheckableTestModel.h b/source/CheckableTestModel/CheckableTestModel.h index bf58c07..d30ad6b 100644 --- a/source/CheckableTestModel/CheckableTestModel.h +++ b/source/CheckableTestModel/CheckableTestModel.h @@ -40,15 +40,6 @@ protected: virtual void printTableTo(QTextCursor &cursor) const; virtual void printSummaryTo(QTextCursor &cursor) const; - static void setCellText(QTextTable &table, int row, int column, const QString &text); - static void setCellChecked(QTextTable &table, int row, int column, bool check); - - template - static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number) - { - setCellText(table, row, column, QString::number(number)); - } - private: CheckableItems &getItems(const QModelIndex &index); const CheckableItems &getItems(const QModelIndex &index) const; diff --git a/source/PrintableModel.cpp b/source/PrintableModel.cpp index 7176aba..c3b9d03 100644 --- a/source/PrintableModel.cpp +++ b/source/PrintableModel.cpp @@ -9,3 +9,38 @@ QTextTableFormat PrintableModel::defaultTableFormat() return tableFormat; } +void PrintableModel::setCellText(QTextTable &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); +} + +void PrintableModel::setCellChecked(QTextTable &table, int row, int column, bool check) +{ + setCellText(table, row, column, check ? "x" : "\u2610"); +} + +void PrintableModel::setCellBackground(QTextTable &table, int row, int column, const QColor &color) +{ + auto cell = table.cellAt(row, column); + + auto cellFormat = cell.format(); + cellFormat.setBackground(QBrush(color)); + cell.setFormat(cellFormat); +} + diff --git a/source/PrintableModel.h b/source/PrintableModel.h index e3bea6a..b3652ac 100644 --- a/source/PrintableModel.h +++ b/source/PrintableModel.h @@ -1,6 +1,7 @@ #pragma once #include +#include class PrintableModel { @@ -9,4 +10,14 @@ public: protected: static QTextTableFormat defaultTableFormat(); + + static void setCellText(QTextTable &table, int row, int column, const QString &text); + static void setCellChecked(QTextTable &table, int row, int column, bool check); + static void setCellBackground(QTextTable &table, int row, int column, const QColor &color); + + template + static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number) + { + setCellText(table, row, column, QString::number(number)); + } }; diff --git a/source/SubTests/V2Svk/V2SvkModel.cpp b/source/SubTests/V2Svk/V2SvkModel.cpp index 30b143c..a982b93 100644 --- a/source/SubTests/V2Svk/V2SvkModel.cpp +++ b/source/SubTests/V2Svk/V2SvkModel.cpp @@ -266,7 +266,11 @@ void V2SvkModel::printTableTo(QTextCursor &cursor) const { column++; - if (!item.getText().empty()) + if (item.getText().empty()) + { + setCellBackground(*table, row, column, QColor(92, 92, 92)); + } + else { setCellChecked(*table, row, column, item.isChecked()); } diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 488af63..d0e6d9f 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -161,6 +161,8 @@ void MainWindow::print() const QTextDocument printDoc; QTextCursor printCursor(&printDoc); m_dataModel.printTo(printCursor); + + printDoc.print(&printer); } void MainWindow::dataModelChanged()