From 997490b36b28bca877409de97a506c969840bc43 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 9 Feb 2010 13:05:09 +0100 Subject: 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 --- src/gui/itemviews/qlistview.cpp | 2 +- tests/auto/qlistview/tst_qlistview.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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() -- cgit v0.12