diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2010-02-09 12:05:09 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2010-02-09 12:22:34 (GMT) |
commit | 997490b36b28bca877409de97a506c969840bc43 (patch) | |
tree | c04ad8e5768de23696aa143b6d0f6bc8f0c75f09 | |
parent | 884a36d300bbe9068d912550a4aeb581f8ce8b37 (diff) | |
download | Qt-997490b36b28bca877409de97a506c969840bc43.zip Qt-997490b36b28bca877409de97a506c969840bc43.tar.gz Qt-997490b36b28bca877409de97a506c969840bc43.tar.bz2 |
QListView: fix crash when hiding many of the lasts item in a QListView
Since 6c1388ee5a3c4796d hidden items are not taken in account when
counting the scrollbar position, and so the vector may be smaller.
Reviewed-by: Gabriel
Task-number: QTBUG-7929
-rw-r--r-- | src/gui/itemviews/qlistview.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qlistview/tst_qlistview.cpp | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp index 19b1e8c..b2def39 100644 --- a/src/gui/itemviews/qlistview.cpp +++ b/src/gui/itemviews/qlistview.cpp @@ -2160,7 +2160,7 @@ void QListModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) } else { if (flowPositions.isEmpty()) return; - const int max = flowPositions.count() - 1; + const int max = scrollValueMap.count() - 1; if (vertical && flow() == QListView::TopToBottom && dy != 0) { int currentValue = qBound(0, verticalValue, max); int previousValue = qBound(0, currentValue + dy, max); diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index 7109213..1e6d36a 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -1834,6 +1834,23 @@ void tst_QListView::taskQTBUG_2233_scrollHiddenItems() QVERIFY(index.isValid()); QCOMPARE(index.row(), 2 * i + 1); } + + //QTBUG-7929 should not crash + view.show(); + QTest::qWaitForWindowShown(&view); + QScrollBar *bar = view.flow() == QListView::TopToBottom + ? view.verticalScrollBar() : view.horizontalScrollBar(); + + int nbVisibleItem = rowCount / 2 - bar->maximum(); + + bar->setValue(bar->maximum()); + QApplication::processEvents(); + for (int i = rowCount; i > rowCount / 2; i--) { + view.setRowHidden(i, true); + } + QApplication::processEvents(); + QCOMPARE(bar->value(), bar->maximum()); + QCOMPARE(bar->maximum(), rowCount/4 - nbVisibleItem); } void tst_QListView::taskQTBUG_633_changeModelData() |