Paint empty result cells gray

This commit is contained in:
Michael Mandl 2018-12-15 16:31:51 +01:00
parent 6eb585b08c
commit c8bd1bbdb8
6 changed files with 53 additions and 36 deletions

View file

@ -191,32 +191,6 @@ void CheckableTestModel::printSummaryTo(QTextCursor &cursor) const
setCellNumber(*table, 0, 3, getPoints()); 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) CheckableItems &CheckableTestModel::getItems(const QModelIndex &index)
{ {
if (index.row() < m_tests.size()) if (index.row() < m_tests.size())

View file

@ -40,15 +40,6 @@ protected:
virtual void printTableTo(QTextCursor &cursor) const; virtual void printTableTo(QTextCursor &cursor) const;
virtual void printSummaryTo(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 <typename NumberType>
static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number)
{
setCellText(table, row, column, QString::number(number));
}
private: private:
CheckableItems &getItems(const QModelIndex &index); CheckableItems &getItems(const QModelIndex &index);
const CheckableItems &getItems(const QModelIndex &index) const; const CheckableItems &getItems(const QModelIndex &index) const;

View file

@ -9,3 +9,38 @@ QTextTableFormat PrintableModel::defaultTableFormat()
return tableFormat; 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);
}

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QTextTableFormat> #include <QTextTableFormat>
#include <QTextTable>
class PrintableModel class PrintableModel
{ {
@ -9,4 +10,14 @@ public:
protected: protected:
static QTextTableFormat defaultTableFormat(); 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<typename NumberType>
static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number)
{
setCellText(table, row, column, QString::number(number));
}
}; };

View file

@ -266,7 +266,11 @@ void V2SvkModel::printTableTo(QTextCursor &cursor) const
{ {
column++; column++;
if (!item.getText().empty()) if (item.getText().empty())
{
setCellBackground(*table, row, column, QColor(92, 92, 92));
}
else
{ {
setCellChecked(*table, row, column, item.isChecked()); setCellChecked(*table, row, column, item.isChecked());
} }

View file

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