From 2883580a3e10df16789ba1c9ee67507e508b95c1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 7 Apr 2010 13:44:20 +0200 Subject: QTableView: fix spans corruption when removing spans. - We should not do -1 after erasing, as it is done later on. - We should consider the 0 height even if it is not the last span. - Added an assert. Task-number: QTBUG-9631 Reviewed-by: Gabriel --- src/gui/itemviews/qtableview.cpp | 9 ++++----- tests/auto/qtableview/tst_qtableview.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index c824a8a..c4d1317 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -114,15 +114,14 @@ void QSpanCollection::updateSpan(QSpanCollection::Span *span, int old_height) } } else if (old_height > span->height()) { //remove the span from all the subspans lists that intersect the columns not covered anymore - Index::iterator it_y = index.lowerBound(-span->bottom()); - if (it_y == index.end()) - it_y = index.find(-span->top()); // This is the only span remaining and we are deleting it. + Index::iterator it_y = index.lowerBound(-qMax(span->bottom(), span->top())); //qMax usefull if height is 0 Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list while (-it_y.key() <= span->top() + old_height -1) { if (-it_y.key() > span->bottom()) { - (*it_y).remove(-span->left()); + int removed = (*it_y).remove(-span->left()); + Q_ASSERT(removed == 1); Q_UNUSED(removed); if (it_y->isEmpty()) { - it_y = index.erase(it_y) - 1; + it_y = index.erase(it_y); } } if(it_y == index.begin()) diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index 54e32218..2062e8e 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -3035,6 +3035,14 @@ void tst_QTableView::spans_data() << QPoint(0, 0) << 1 << 1; + + QTest::newRow("QTBUG-9631: remove one span") + << 10 << 10 + << (SpanList() << QRect(1, 1, 2, 1) << QRect(2, 2, 2, 2) << QRect(1, 1, 1, 1)) + << false + << QPoint(1, 1) + << 1 + << 1; } void tst_QTableView::spans() -- cgit v0.12