Fix QTextTable:insertRows() for tables with spanning cells
Don't resize the height of cells spanning several columns multiple times. Fixes: QTBUG-36713 Change-Id: I5eb45892f2008e6a4f85745b56efd04323e25673 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>bb10
parent
c066656aff
commit
4247d7c5a0
|
|
@ -696,18 +696,22 @@ void QTextTable::insertRows(int pos, int num)
|
|||
int extended = 0;
|
||||
int insert_before = 0;
|
||||
if (pos > 0 && pos < d->nRows) {
|
||||
int lastCell = -1;
|
||||
for (int i = 0; i < d->nCols; ++i) {
|
||||
int cell = d->grid[pos*d->nCols + i];
|
||||
if (cell == d->grid[(pos-1)*d->nCols+i]) {
|
||||
// cell spans the insertion place, extend it
|
||||
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
|
||||
QTextCharFormat fmt = c->charFormat(it->format);
|
||||
fmt.setTableCellRowSpan(fmt.tableCellRowSpan() + num);
|
||||
p->setCharFormat(it.position(), 1, fmt);
|
||||
if (cell != lastCell) {
|
||||
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
|
||||
QTextCharFormat fmt = c->charFormat(it->format);
|
||||
fmt.setTableCellRowSpan(fmt.tableCellRowSpan() + num);
|
||||
p->setCharFormat(it.position(), 1, fmt);
|
||||
}
|
||||
extended++;
|
||||
} else if (!insert_before) {
|
||||
insert_before = cell;
|
||||
}
|
||||
lastCell = cell;
|
||||
}
|
||||
} else {
|
||||
insert_before = (pos == 0 ? d->grid[0] : d->fragment_end);
|
||||
|
|
|
|||
|
|
@ -431,6 +431,12 @@ void tst_QTextTable::insertRows()
|
|||
table->insertRows(5, 2);
|
||||
QCOMPARE(table->rows(), 7);
|
||||
|
||||
table = cursor.insertTable(5,5);
|
||||
table->mergeCells(0,0,3,3);
|
||||
table->insertRows(2,1);
|
||||
|
||||
QCOMPARE(table->rows(), 6);
|
||||
|
||||
}
|
||||
|
||||
void tst_QTextTable::deleteInTable()
|
||||
|
|
|
|||
Loading…
Reference in New Issue