From a3b8e355fc17783a5d4badfb9ad50247655000cd Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Fri, 12 Feb 2016 15:31:07 +0300 Subject: [PATCH 076/122] QListView: fix skipping indexes in selectedIndexes(). Remove spurious increment of i. Task-number: QTBUG-51086 Change-Id: I4307a6728de1e7f25c8afa31fe2066f92373f3fc Reviewed-by: Edward Welbourne Reviewed-by: Oswald Buddenhagen Reviewed-by: Marc Mutz --- src/widgets/itemviews/qlistview.cpp | 2 +- .../widgets/itemviews/qlistview/tst_qlistview.cpp | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9c79509..a17d89e 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -1437,7 +1437,7 @@ QModelIndexList QListView::selectedIndexes() const return QModelIndexList(); QModelIndexList viewSelected = d->selectionModel->selectedIndexes(); - for (int i = 0; i < viewSelected.count(); ++i) { + for (int i = 0; i < viewSelected.count();) { const QModelIndex &index = viewSelected.at(i); if (!isIndexHidden(index) && index.parent() == d->root && index.column() == d->column) ++i; diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 5b206af..3cf9f7f 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -152,6 +152,7 @@ private slots: void taskQTBUG_39902_mutualScrollBars_data(); void taskQTBUG_39902_mutualScrollBars(); void horizontalScrollingByVerticalWheelEvents(); + void taskQTBUG_51086_skippingIndexesInSelectedIndexes(); }; // Testing get/set functions @@ -2493,5 +2494,32 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents() QVERIFY(lv.verticalScrollBar()->value() > vValue); } +void tst_QListView::taskQTBUG_51086_skippingIndexesInSelectedIndexes() +{ + // simple way to get access to selectedIndexes() + class QListViewWithPublicSelectedIndexes : public QListView + { + public: + using QListView::selectedIndexes; + }; + + QStandardItemModel data(10, 1); + QItemSelectionModel selections(&data); + QListViewWithPublicSelectedIndexes list; + list.setModel(&data); + list.setSelectionModel(&selections); + + list.setRowHidden(7, true); + list.setRowHidden(8, true); + + for (int i = 0, count = data.rowCount(); i < count; ++i) + selections.select(data.index(i, 0), QItemSelectionModel::Select); + + const QModelIndexList indexes = list.selectedIndexes(); + + QVERIFY(!indexes.contains(data.index(7, 0))); + QVERIFY(!indexes.contains(data.index(8, 0))); +} + QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" -- 2.5.0