diff options
author | Jani Honkonen <jani.honkonen@digia.com> | 2012-02-03 15:11:01 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-09 15:23:50 (GMT) |
commit | b0601630dd0ddabfaa3b97d042ee02b981d95988 (patch) | |
tree | e0b3c6d329c25b5db751f95fe32614991f687267 /tests/auto/qlistview | |
parent | a13b2a248e5091ddf21e3c5ac08c9ddf0b940b5b (diff) | |
download | Qt-b0601630dd0ddabfaa3b97d042ee02b981d95988.zip Qt-b0601630dd0ddabfaa3b97d042ee02b981d95988.tar.gz Qt-b0601630dd0ddabfaa3b97d042ee02b981d95988.tar.bz2 |
Fix QListView::scrollTo() when there are hidden rows
QListView does not consider hidden rows when scrolling to an item.
If there are hidden rows (or columns) before the selected item then
the visual index of an item is not the same as the row index
from the model. So scrolling will be off by the number of hidden
rows before the selected item.
Added a autotest for this also.
Task-number: QTBUG-21115
Change-Id: I49c39033d83f80d4405b59510617096029ee6d3b
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/qlistview')
-rw-r--r-- | tests/auto/qlistview/tst_qlistview.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index d3cf76b..7558210 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -128,6 +128,8 @@ private slots: void styleOptionViewItem(); void taskQTBUG_12308_artihmeticException(); void taskQTBUG_12308_wrongFlowLayout(); + void taskQTBUG_21115_scrollToAndHiddenItems_data(); + void taskQTBUG_21115_scrollToAndHiddenItems(); }; // Testing get/set functions @@ -2061,5 +2063,50 @@ void tst_QListView::taskQTBUG_12308_wrongFlowLayout() QTest::qWaitForWindowShown(&lw); } +void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems_data() +{ + QTest::addColumn<int>("flow"); + QTest::newRow("flow TopToBottom") << static_cast<int>(QListView::TopToBottom); + QTest::newRow("flow LeftToRight") << static_cast<int>(QListView::LeftToRight); +} + +void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems() +{ + QFETCH(int, flow); + + QListView lv; + lv.setUniformItemSizes(true); + lv.setFlow(static_cast<QListView::Flow>(flow)); + + QStringListModel model; + QStringList list; + for (int i = 0; i < 30; i++) + list << QString::number(i); + model.setStringList(list); + lv.setModel(&model); + lv.show(); + QTest::qWaitForWindowShown(&lv); + + // Save first item rect for reference + QRect firstItemRect = lv.visualRect(model.index(0, 0)); + + // Select an item and scroll to selection + QModelIndex index = model.index(2, 0); + lv.setCurrentIndex(index); + lv.scrollTo(index, QAbstractItemView::PositionAtTop); + QApplication::processEvents(); + QCOMPARE(lv.visualRect(index), firstItemRect); + + // Hide some rows and scroll to selection + for (int i = 0; i < 5; i++) { + if (i == index.row()) + continue; + lv.setRowHidden(i, true); + } + lv.scrollTo(index, QAbstractItemView::PositionAtTop); + QApplication::processEvents(); + QCOMPARE(lv.visualRect(index), firstItemRect); +} + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" |