diff options
author | Frank Reininghaus <frank78ac@googlemail.com> | 2009-10-12 19:12:39 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-13 08:20:41 (GMT) |
commit | 6201e4adda316e5a582af687cdd2f1bcd19be31d (patch) | |
tree | dcb1a1fc96b60f911bd84356e4e422b7f8d2f6c4 /tests/auto/qabstractitemview | |
parent | 6a1be803bf94b8af4a4766e31df9b441d1c81eed (diff) | |
download | Qt-6201e4adda316e5a582af687cdd2f1bcd19be31d.zip Qt-6201e4adda316e5a582af687cdd2f1bcd19be31d.tar.gz Qt-6201e4adda316e5a582af687cdd2f1bcd19be31d.tar.bz2 |
Itemview: fix regression concerning Ctrl+rubber band selections
When making a rubber band selection while Control is pressed in an
itemview with extended selection, make sure that the selection state
of the items inside the rubber band is toggled.
This ammend commit 0644e3dce532b1df00a77d3a30c61d6b75d3ff30
Merge-request: 1759
Reviewed-by: Olivier Goffart <ogoffart@trolltech.com>
Reviewed-by: Gabriel
Task-number: QTBUG-1435
Task-number: 191545
Diffstat (limited to 'tests/auto/qabstractitemview')
-rw-r--r-- | tests/auto/qabstractitemview/tst_qabstractitemview.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp index d6911d2..db840f4 100644 --- a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp @@ -223,6 +223,7 @@ private slots: void task257481_emptyEditor(); void shiftArrowSelectionAfterScrolling(); void shiftSelectionAfterRubberbandSelection(); + void ctrlRubberbandSelection(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1388,5 +1389,49 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection() QVERIFY(selected.contains(index2)); } +void tst_QAbstractItemView::ctrlRubberbandSelection() +{ + QStandardItemModel model; + for (int i=0; i<3; ++i) { + QStandardItem *item = new QStandardItem(QString("%1").arg(i)); + model.setItem(i, 0, item); + } + + QListView view; + view.setFixedSize(150, 450); + view.setFlow(QListView::LeftToRight); + view.setGridSize(QSize(100, 100)); + view.setSelectionMode(QListView::ExtendedSelection); + view.setViewMode(QListView::IconMode); + view.setModel(&model); + view.show(); + QTest::qWait(30); + + QModelIndex index1 = model.index(1, 0); + QModelIndex index2 = model.index(2, 0); + + // Select item 1 + view.setCurrentIndex(index1); + QModelIndexList selected = view.selectionModel()->selectedIndexes(); + QCOMPARE(selected.count(), 1); + QVERIFY(selected.contains(index1)); + + // Now press control and draw a rubberband around items 1 and 2. + // The mouse move event has to be created manually because the QTest framework does not + // contain a function for mouse moves with buttons pressed. + QPoint pressPos = view.visualRect(index1).topLeft() - QPoint(1, 1); + QPoint releasePos = view.visualRect(index2).bottomRight() + QPoint(1, 1); + QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pressPos); + QMouseEvent moveEvent(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); + bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent); + QVERIFY(moveEventReceived); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, releasePos); + + // Verify that item 2 is selected now + selected = view.selectionModel()->selectedIndexes(); + QCOMPARE(selected.count(), 1); + QVERIFY(selected.contains(index2)); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" |