23 #include <QAbstractTextDocumentLayout>
26 #include <QTextCursor>
27 #include <QTextTableCell>
30 class CellContentMap :
public QMap<QPair<int , int >, Cell>
34 void getSize(
int &rows,
int &columns)
const
38 for (const_iterator it = begin(); it != end(); ++it) {
39 rows = qMax(rows, it.key().first + 1);
40 columns = qMax(columns, it.key().second + 1);
46 class KDReports::TableElementPrivate
51 , m_headerColumnCount(0)
54 ~TableElementPrivate() { }
56 KDReports::CellContentMap m_cellContentMap;
58 int m_headerColumnCount;
64 : d(new TableElementPrivate)
70 , d(new TableElementPrivate(*other.d))
96 d->m_headerRowCount = count;
101 return d->m_headerRowCount;
106 d->m_headerColumnCount = count;
111 return d->m_headerColumnCount;
116 const QPair<int, int> coord = qMakePair(row, column);
117 return d->m_cellContentMap[coord];
122 if (d->m_cellContentMap.isEmpty())
125 QTextCursor &textDocCursor = builder.
cursor();
129 d->m_cellContentMap.getSize(rowCount, columnCount);
131 QTextTableFormat tableFormat;
132 tableFormat.setHeaderRowCount(d->m_headerRowCount);
134 tableFormat.setAlignment(textDocCursor.blockFormat().alignment());
135 tableFormat.setBackground(background());
136 fillTableFormat(tableFormat, textDocCursor);
137 QTextCharFormat charFormat = textDocCursor.charFormat();
139 QTextTable *textTable = textDocCursor.insertTable(rowCount, columnCount, tableFormat);
141 CellContentMap::const_iterator it = d->m_cellContentMap.constBegin();
142 for (; it != d->m_cellContentMap.constEnd(); ++it) {
143 const int row = it.key().first;
144 const int column = it.key().second;
145 const Cell &cell = it.value();
148 QTextTableCell tableCell = textTable->cellAt(row, column);
149 Q_ASSERT(tableCell.isValid());
150 QTextCursor cellCursor = tableCell.firstCursorPosition();
151 QTextCharFormat tableCellFormat = charFormat;
152 tableCellFormat.setBackground(cell.
background());
153 tableCellFormat.setTableCellColumnSpan(cell.
columnSpan());
154 tableCellFormat.setTableCellRowSpan(cell.
rowSpan());
155 tableCell.setFormat(tableCellFormat);
156 cellCursor.setCharFormat(tableCellFormat);
160 cell.
build(cellBuilder);
163 textDocCursor.movePosition(QTextCursor::End);