summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtreeview
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-08-26 13:30:48 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-08-26 13:33:50 (GMT)
commit88ecc8c8250505129ccff2660c60412996e2fd85 (patch)
tree0ee8ce441e8a1561c4d922fcff1a868d695be1b2 /tests/auto/qtreeview
parent25c7f57c21dd22eaa38b4b511aa754a1be711bf1 (diff)
downloadQt-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
Diffstat (limited to 'tests/auto/qtreeview')
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp29
1 files changed, 29 insertions, 0 deletions
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"