summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@nokia.com>2010-07-02 17:31:51 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2010-07-16 07:16:53 (GMT)
commit9842516c45323b5f3352232f3d76db98256fdb2e (patch)
treeacaa98d21e6117d660ee325816339d441f6b5e4d /src/gui/text
parente6532522d5176d8c5165ea9e9ebab058d597ed80 (diff)
downloadQt-9842516c45323b5f3352232f3d76db98256fdb2e.zip
Qt-9842516c45323b5f3352232f3d76db98256fdb2e.tar.gz
Qt-9842516c45323b5f3352232f3d76db98256fdb2e.tar.bz2
Fix an Assert in QTextTable
The problem was caused by the fragment id being inserted in front of a cell spanning over several rows instead of the next logical cell (or fragment_end) in the cells structure. Task-number: QTBUG-11282 Reviewed-by: Simon Hausmann (cherry picked from commit b2a4c7f0142a48f60e7ec4fc5866917e3da8b7c3)
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtexttable.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp
index 5100176..e3985ce 100644
--- a/src/gui/text/qtexttable.cpp
+++ b/src/gui/text/qtexttable.cpp
@@ -754,19 +754,39 @@ void QTextTable::insertColumns(int pos, int num)
QTextFormatCollection *c = p->formatCollection();
p->beginEditBlock();
+ QList<int> extendedSpans;
for (int i = 0; i < d->nRows; ++i) {
int cell;
if (i == d->nRows - 1 && pos == d->nCols)
cell = d->fragment_end;
else
cell = d->grid[i*d->nCols + pos];
- QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
- QTextCharFormat fmt = c->charFormat(it->format);
if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) {
// cell spans the insertion place, extend it
- fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num);
- p->setCharFormat(it.position(), 1, fmt);
+ if (!extendedSpans.contains(cell)) {
+ QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
+ QTextCharFormat fmt = c->charFormat(it->format);
+ fmt.setTableCellColumnSpan(fmt.tableCellColumnSpan() + num);
+ p->setCharFormat(it.position(), 1, fmt);
+ d->dirty = true;
+ extendedSpans << cell;
+ }
} else {
+ /* If the next cell is spanned from the row above, we need to find the right position
+ to insert to */
+ if (i > 0 && pos < d->nCols && cell == d->grid[(i-1) * d->nCols + pos]) {
+ int gridIndex = i*d->nCols + pos;
+ const int gridEnd = d->nRows * d->nCols - 1;
+ while (gridIndex < gridEnd && cell == d->grid[gridIndex]) {
+ ++gridIndex;
+ }
+ if (gridIndex == gridEnd)
+ cell = d->fragment_end;
+ else
+ cell = d->grid[gridIndex];
+ }
+ QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), cell);
+ QTextCharFormat fmt = c->charFormat(it->format);
fmt.setTableCellRowSpan(1);
fmt.setTableCellColumnSpan(1);
Q_ASSERT(fmt.objectIndex() == objectIndex());