From c726e83aebf2252b5a94444d5d61e03ef2033437 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Fri, 30 Oct 2009 11:36:30 +0100 Subject: In ItemViews, right click on the viewport clear the ext selection Task-number: QTBUG-435 Reviewed-by: Gabriel --- src/gui/itemviews/qabstractitemview.cpp | 2 +- tests/auto/qlistview/tst_qlistview.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 9247411..23bef12 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -3641,7 +3641,7 @@ QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionC const bool controlKeyPressed = modifiers & Qt::ControlModifier; if (((index == pressedIndex && selectionModel->isSelected(index)) || !index.isValid()) && state != QAbstractItemView::DragSelectingState - && !shiftKeyPressed && !controlKeyPressed && !rightButtonPressed) + && !shiftKeyPressed && !controlKeyPressed && (!rightButtonPressed || !index.isValid())) return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); return QItemSelectionModel::NoUpdate; } diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp index 727e6d3..a5ff153 100644 --- a/tests/auto/qlistview/tst_qlistview.cpp +++ b/tests/auto/qlistview/tst_qlistview.cpp @@ -120,6 +120,7 @@ private slots: void taskQTBUG_2233_scrollHiddenItems_data(); void taskQTBUG_2233_scrollHiddenItems(); void taskQTBUG_633_changeModelData(); + void taskQTBUG_435_deselectOnViewportClick(); }; // Testing get/set functions @@ -1852,6 +1853,28 @@ void tst_QListView::taskQTBUG_633_changeModelData() QVERIFY( ! rectLongText.intersects(rect2) ); } +void tst_QListView::taskQTBUG_435_deselectOnViewportClick() +{ + QListView view; + QStringListModel model( QStringList() << "1" << "2" << "3" << "4"); + view.setModel(&model); + view.setSelectionMode(QAbstractItemView::ExtendedSelection); + view.selectAll(); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), model.rowCount()); + + + QPoint p = view.visualRect(model.index(model.rowCount() - 1)).center() + QPoint(0, 20); + //first the left button + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p); + QVERIFY(!view.selectionModel()->hasSelection()); + + view.selectAll(); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), model.rowCount()); + + //and now the right button + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, p); + QVERIFY(!view.selectionModel()->hasSelection()); +} QTEST_MAIN(tst_QListView) #include "tst_qlistview.moc" -- cgit v0.12