diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-11-17 17:31:32 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-11-18 14:19:59 (GMT) |
commit | e15accd154c40bcf26dcb5209431974ad2617a73 (patch) | |
tree | 9e2d29d8a191a37e1748deeb46388b52718f676f /tests/auto/qlistview/tst_qlistview.cpp | |
parent | b099c4c07f3747fefff3d7457b4ae817225ca9ae (diff) | |
download | Qt-e15accd154c40bcf26dcb5209431974ad2617a73.zip Qt-e15accd154c40bcf26dcb5209431974ad2617a73.tar.gz Qt-e15accd154c40bcf26dcb5209431974ad2617a73.tar.bz2 |
QListView: fixes skipping one item in pageDown(Up)
The previous implementation was scrolling down (number of visible items
in viewport) + 1 and this was leading to one item being skipped while doing
page down (the same also happened for page up). Now we are scrolling (number
of visible items in viewport) - 1 for each page down(up) (the '-1' is for
keeping the context, so the last item will turn into the first in case of
a page down, for example).
Task-number: QTBUG-5877
Reviewed-by: thierry
Diffstat (limited to 'tests/auto/qlistview/tst_qlistview.cpp')
-rw-r--r-- | tests/auto/qlistview/tst_qlistview.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index bfd038e..596ac9b 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -122,6 +122,7 @@ private slots: void taskQTBUG_633_changeModelData(); void taskQTBUG_435_deselectOnViewportClick(); void taskQTBUG_2678_spacingAndWrappedText(); + void taskQTBUG_5877_skippingItemInPageDownUp(); }; // Testing get/set functions @@ -1881,5 +1882,36 @@ void tst_QListView::taskQTBUG_2678_spacingAndWrappedText() QCOMPARE(w.horizontalScrollBar()->minimum(), w.horizontalScrollBar()->maximum()); } +void tst_QListView::taskQTBUG_5877_skippingItemInPageDownUp() +{ + QList<int> currentItemIndexes; + QtTestModel model(0); + model.colCount = 1; + model.rCount = 100; + + currentItemIndexes << 0 << 6 << 16 << 25 << 34 << 42 << 57 << 68 << 77 + << 83 << 91 << 94; + QMoveCursorListView vu; + vu.setModel(&model); + vu.show(); + + int itemHeight = vu.visualRect(model.index(0, 0)).height(); + int visibleRowCount = vu.height() / itemHeight; + int scrolledRowCount = visibleRowCount - 1; + + for (int i = 0; i < currentItemIndexes.size(); ++i) { + vu.selectionModel()->setCurrentIndex(model.index(currentItemIndexes[i], 0), + QItemSelectionModel::SelectCurrent); + + QModelIndex idx = vu.moveCursor(QMoveCursorListView::MovePageDown, Qt::NoModifier); + int newCurrent = qMin(currentItemIndexes[i] + scrolledRowCount, 99); + QCOMPARE(idx, model.index(newCurrent, 0)); + + idx = vu.moveCursor(QMoveCursorListView::MovePageUp, Qt::NoModifier); + newCurrent = qMax(currentItemIndexes[i] - scrolledRowCount, 0); + QCOMPARE(idx, model.index(newCurrent, 0)); + } +} + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" |