summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2012-07-12 10:55:04 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-07-13 08:02:33 (GMT)
commitea718a55f119381df25fc9d62126bb76a677ba95 (patch)
tree24410d26a0a45b880516742bfc04dfb3a67e6b73 /src/gui/text
parentaca359dcc14a8ed6bcebdf2ba887dc0fc43f6e01 (diff)
downloadQt-ea718a55f119381df25fc9d62126bb76a677ba95.zip
Qt-ea718a55f119381df25fc9d62126bb76a677ba95.tar.gz
Qt-ea718a55f119381df25fc9d62126bb76a677ba95.tar.bz2
Fix crash when column is inserted before rowspanned cell
When you're inserting a column in front of a rowspanned cell and this cell is not the first in the rowspan, we would get the wrong logical index of the new cell (putting it in front of the initial cell with the rowspan). If the cell does not span all rows, the table will get into a broken state and trigger asserts in update(). To fix this, we search for the first cell after the insertion point which has a logical index higher than the cell directly before the insertion point. Change-Id: Ic6fb66bc25ad91f3534886f964173ead924429e2 Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtexttable.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp
index 64b2881..cfbf426 100644
--- a/src/gui/text/qtexttable.cpp
+++ b/src/gui/text/qtexttable.cpp
@@ -757,10 +757,30 @@ void QTextTable::insertColumns(int pos, int num)
QList<int> extendedSpans;
for (int i = 0; i < d->nRows; ++i) {
int cell;
- if (i == d->nRows - 1 && pos == d->nCols)
+ if (i == d->nRows - 1 && pos == d->nCols) {
cell = d->fragment_end;
- else
- cell = d->grid[i*d->nCols + pos];
+ } else {
+ int logicalGridIndexBeforePosition = pos > 0
+ ? d->findCellIndex(d->grid[i*d->nCols + pos - 1])
+ : -1;
+
+ // Search for the logical insertion point by skipping past cells which are not the first
+ // cell in a rowspan. This means any cell for which the logical grid index is
+ // less than the logical cell index of the cell before the insertion.
+ int logicalGridIndex;
+ int gridArrayOffset = i*d->nCols + pos;
+ do {
+ cell = d->grid[gridArrayOffset];
+ logicalGridIndex = d->findCellIndex(cell);
+ gridArrayOffset++;
+ } while (logicalGridIndex < logicalGridIndexBeforePosition
+ && gridArrayOffset < d->nRows*d->nCols);
+
+ if (logicalGridIndex < logicalGridIndexBeforePosition
+ && gridArrayOffset == d->nRows*d->nCols)
+ cell = d->fragment_end;
+ }
+
if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) {
// cell spans the insertion place, extend it
if (!extendedSpans.contains(cell)) {