summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-08-24 08:24:27 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-08-27 09:52:13 (GMT)
commit7982f6ad2703e13edbf80d55e537871bf1cd548d (patch)
treead23b8bbbe93704d01702948f8abd10bba748004
parent99e6ea17e257664467d49f4803952b7dd92f72da (diff)
downloadQt-7982f6ad2703e13edbf80d55e537871bf1cd548d.zip
Qt-7982f6ad2703e13edbf80d55e537871bf1cd548d.tar.gz
Qt-7982f6ad2703e13edbf80d55e537871bf1cd548d.tar.bz2
Take account of hidden items in QListView when using scrollTo.
This is a backport of 799ceebad8a2dbe1ca0e60a11c7d6ca0c2c8b7a9 from qtbase. Task-number: QTBUG-21804 Change-Id: I757b9598f354cdfa62c08d0c2613ded93fe88804 Reviewed-by: Jani Honkonen <jani.honkonen@digia.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
-rw-r--r--src/gui/itemviews/qlistview.cpp12
-rw-r--r--tests/auto/qlistview/tst_qlistview.cpp29
2 files changed, 38 insertions, 3 deletions
diff --git a/src/gui/itemviews/qlistview.cpp b/src/gui/itemviews/qlistview.cpp
index 3a8cedb..2632807 100644
--- a/src/gui/itemviews/qlistview.cpp
+++ b/src/gui/itemviews/qlistview.cpp
@@ -2133,10 +2133,16 @@ int QListModeViewBase::verticalScrollToValue(int index, QListView::ScrollHint hi
{
if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
int value;
- if (scrollValueMap.isEmpty())
+ if (scrollValueMap.isEmpty()) {
value = 0;
- else
- value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()), flowPositions.count() - 1);
+ } else {
+ int scrollBarValue = verticalScrollBar()->value();
+ int numHidden = 0;
+ for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i)
+ if (isHidden(i))
+ ++numHidden;
+ value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1);
+ }
if (above)
hint = QListView::PositionAtTop;
else if (below)
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp
index 155ace9..9759790 100644
--- a/tests/auto/qlistview/tst_qlistview.cpp
+++ b/tests/auto/qlistview/tst_qlistview.cpp
@@ -134,6 +134,7 @@ private slots:
void taskQTBUG_21804_hiddenItemsAndScrollingWithKeys();
void spacing_data();
void spacing();
+ void testScrollToWithHidden();
};
// Testing get/set functions
@@ -2232,5 +2233,33 @@ void tst_QListView::spacing()
}
}
+void tst_QListView::testScrollToWithHidden()
+{
+ QListView lv;
+
+ QStringListModel model;
+ QStringList list;
+ for (int i = 0; i < 30; i++)
+ list << QString::number(i);
+ model.setStringList(list);
+ lv.setModel(&model);
+
+ lv.setRowHidden(1, true);
+ lv.setSpacing(5);
+
+ lv.show();
+ QTest::qWaitForWindowShown(&lv);
+
+ QCOMPARE(lv.verticalScrollBar()->value(), 0);
+
+ lv.scrollTo(model.index(26, 0));
+ int expectedScrollBarValue = lv.verticalScrollBar()->value();
+ QVERIFY(expectedScrollBarValue != 0);
+
+ lv.scrollTo(model.index(25, 0));
+ QCOMPARE(expectedScrollBarValue, lv.verticalScrollBar()->value());
+}
+
+
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"