diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-08-26 13:30:48 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-08-26 13:33:50 (GMT) |
commit | 88ecc8c8250505129ccff2660c60412996e2fd85 (patch) | |
tree | 0ee8ce441e8a1561c4d922fcff1a868d695be1b2 | |
parent | 25c7f57c21dd22eaa38b4b511aa754a1be711bf1 (diff) | |
download | Qt-88ecc8c8250505129ccff2660c60412996e2fd85.zip Qt-88ecc8c8250505129ccff2660c60412996e2fd85.tar.gz Qt-88ecc8c8250505129ccff2660c60412996e2fd85.tar.bz2 |
QAbstractItemView sometimes doesn't allow changing the selection
If you do a selection with the mouse and react to selectionChanged by
changing the selection. Those changes would be overwritten by
QAbstractItemView::mouseReleaseEvent.
It is useless to set the selection on mouse release. We already do
that on mouse press.
Task-number: 250683
Reviewed-by: ogoffart
-rw-r--r-- | src/gui/itemviews/qabstractitemview.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qtreeview/tst_qtreeview.cpp | 29 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index bca5df7..ccc57d7 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -1661,9 +1661,6 @@ void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event) EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers); bool edited = edit(index, trigger, event); - if (d->selectionModel) - d->selectionModel->select(index, selectionCommand(index, event)); - setState(NoState); if (click) { diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index d28c3c3..44185e7 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -232,6 +232,7 @@ private slots: void task250683_wrongSectionSize(); void task239271_addRowsWithFirstColumnHidden(); void task254234_proxySort(); + void task248022_changeSelection(); }; class QtTestModel: public QAbstractItemModel @@ -3435,5 +3436,33 @@ void tst_QTreeView::task254234_proxySort() QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g")); } +class TreeView : public QTreeView +{ + Q_OBJECT +public slots: + void handleSelectionChanged() + { + //let's select the last item + QModelIndex idx = model()->index(0, 0); + selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select); + disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(handleSelectionChanged())); + } +}; + +void tst_QTreeView::task248022_changeSelection() +{ + //we check that changing the selection between the mouse press and the mouse release + //works correctly + TreeView view; + QStringList list = QStringList() << "1" << "2"; + QStringListModel model(list); + view.setSelectionMode(QAbstractItemView::ExtendedSelection); + view.setModel(&model); + view.connect(view.selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(handleSelectionChanged())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(1)).center()); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), list.count()); +} + + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" |