Take account of hidden items in QListView when using scrollTo.

Task-number: QTBUG-21804
Change-Id: I475166f3f60b1278089baa255ace4e18baeb568e
Reviewed-by: Jani Honkonen <jani.honkonen@digia.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Stephen Kelly 2012-08-06 11:34:56 +02:00 committed by Qt by Nokia
parent 79f660d374
commit 799ceebad8
2 changed files with 36 additions and 3 deletions

View File

@ -2108,10 +2108,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)

View File

@ -140,6 +140,7 @@ private slots:
void taskQTBUG_21804_hiddenItemsAndScrollingWithKeys();
void spacing_data();
void spacing();
void testScrollToWithHidden();
};
// Testing get/set functions
@ -2280,6 +2281,32 @@ 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::qWaitForWindowExposed(&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"