summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-09-08 10:59:44 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-09-08 11:01:28 (GMT)
commit9d9b7f53750dce2da88d7d11d312b4b36250b5c5 (patch)
tree2dfec33fb3da2c19f0ac33d81f67ec36cf8617a5
parent9a90fcca3e9a9a49cee228054017ff7d15645082 (diff)
downloadQt-9d9b7f53750dce2da88d7d11d312b4b36250b5c5.zip
Qt-9d9b7f53750dce2da88d7d11d312b4b36250b5c5.tar.gz
Qt-9d9b7f53750dce2da88d7d11d312b4b36250b5c5.tar.bz2
Fixes a regression in QListView in 4.6 regarding the selection
In icon mode, if you click on the viewport (with extended selection), the selection should be cleared when you release the mouse button. Reviewed-by: ogoffart
-rw-r--r--src/gui/itemviews/qabstractitemview.cpp4
-rw-r--r--tests/auto/qlistview/tst_qlistview.cpp30
2 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp
index 52529ff..99e9aeb 100644
--- a/src/gui/itemviews/qabstractitemview.cpp
+++ b/src/gui/itemviews/qabstractitemview.cpp
@@ -1661,6 +1661,10 @@ void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event)
EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers);
bool edited = edit(index, trigger, event);
+ //in the case the user presses on no item we might decide to clear the selection
+ if (d->selectionModel && !index.isValid())
+ d->selectionModel->select(QModelIndex(), selectionCommand(index, event));
+
setState(NoState);
if (click) {
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp
index 2be1a03..2831747 100644
--- a/tests/auto/qlistview/tst_qlistview.cpp
+++ b/tests/auto/qlistview/tst_qlistview.cpp
@@ -113,6 +113,7 @@ private slots:
void task254449_draggingItemToNegativeCoordinates();
void keyboardSearch();
void shiftSelectionWithNonUniformItemSizes();
+ void clickOnViewportClearsSelection();
};
// Testing get/set functions
@@ -1733,5 +1734,34 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes()
}
}
+void tst_QListView::clickOnViewportClearsSelection()
+{
+ QStringList items;
+ items << "Text1";
+ QStringListModel model(items);
+ QListView view;
+ view.setModel(&model);
+ view.setSelectionMode(QListView::ExtendedSelection);
+
+ view.selectAll();
+ QModelIndex index = model.index(0);
+ QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QVERIFY(view.selectionModel()->isSelected(index));
+
+ //we try to click outside of the index
+ const QPoint point = view.visualRect(index).bottomRight() + QPoint(10,10);
+
+ QTest::mousePress(view.viewport(), Qt::LeftButton, 0, point);
+ //at this point, the selection shouldn't have changed
+ QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QVERIFY(view.selectionModel()->isSelected(index));
+
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, point);
+ //now the selection should be cleared
+ QVERIFY(!view.selectionModel()->hasSelection());
+
+}
+
+
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"