Paint empty result cells gray
parent
6eb585b08c
commit
c8bd1bbdb8
|
@ -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())
|
||||
|
|
|
@ -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 <typename NumberType>
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QTextTableFormat>
|
||||
#include <QTextTable>
|
||||
|
||||
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<typename NumberType>
|
||||
static void setCellNumber(QTextTable &table, int row, int column, const NumberType &number)
|
||||
{
|
||||
setCellText(table, row, column, QString::number(number));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -161,6 +161,8 @@ void MainWindow::print() const
|
|||
QTextDocument printDoc;
|
||||
QTextCursor printCursor(&printDoc);
|
||||
m_dataModel.printTo(printCursor);
|
||||
|
||||
printDoc.print(&printer);
|
||||
}
|
||||
|
||||
void MainWindow::dataModelChanged()
|
||||
|
|
Loading…
Reference in New Issue