From 3f2d02e2f4436ace5f0fbbf432878a963f5ee969 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sun, 26 Feb 2023 16:47:42 +0100 Subject: QAbtractItemView: deselect before click opens editor A click on the selected item should deselect all other items before editing starts. Remove the part of the test case that assumes that we can have multiple items selected in ExtendedSelection mode, and click on an item to start editing while maintaining selection. That can never happen. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-111131 Change-Id: I0312eed4614502cfb77eca26d3f7615427493d7d Reviewed-by: Axel Spoerl --- .../qabstractitemview/tst_qabstractitemview.cpp | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'tests/auto/widgets/itemviews') diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index a59a7ac498..9b8948001d 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -755,22 +755,6 @@ void tst_QAbstractItemView::pressClosesReleaseDoesntOpenEditor() QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, inChildOutsideEditor); // should not reopen editor QTest::qWait(QApplication::doubleClickInterval() * 2); QCOMPARE(view.state(), QAbstractItemView::NoState); - - // with multiple items selected, clicking from the currently edited item into another - // selected item closes the current and reopens a new editor - view.setSelectionMode(QAbstractItemView::ExtendedSelection); - const QRect child2Rect = view.visualRect(model.indexFromItem(parent->child(1))); - QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, child2Rect.center()); // select - QVERIFY(view.selectionModel()->selectedIndexes().contains(model.indexFromItem(parent->child(0)))); - QVERIFY(view.selectionModel()->selectedIndexes().contains(model.indexFromItem(parent->child(1)))); - QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, child2Rect.center()); // edit - QTRY_COMPARE(view.state(), QAbstractItemView::EditingState); - QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, inChildOutsideEditor); // editor closes - QCOMPARE(view.state(), QAbstractItemView::NoState); - QTest::qWait(10); // process some events, let the internal timer time out - QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, inChildOutsideEditor); // should open editor - QTest::qWait(QApplication::doubleClickInterval() * 2); - QCOMPARE(view.state(), QAbstractItemView::EditingState); } @@ -3044,6 +3028,19 @@ void tst_QAbstractItemView::mouseSelection_data() << QList{SelectionEvent(SelectionEvent::Click, 3), SelectionEvent(SelectionEvent::Click, Qt::ControlModifier, 3)} << QList{}; + // Extended: when drag is enabled, click on selected without Ctrl clears before editing + QTest::addRow("Extended:Range,Click,editable") << QAbstractItemView::ExtendedSelection << false + << QAbstractItemView::SelectedClicked + << QList{SelectionEvent(SelectionEvent::Click, 1), + SelectionEvent(SelectionEvent::Click, Qt::ShiftModifier, 3), + SelectionEvent(SelectionEvent::Click, 2)} + << QList{2}; + QTest::addRow("Extended:Range,Click,dragable,editable") << QAbstractItemView::ExtendedSelection << true + << QAbstractItemView::SelectedClicked + << QList{SelectionEvent(SelectionEvent::Click, 1), + SelectionEvent(SelectionEvent::Click, Qt::ShiftModifier, 3), + SelectionEvent(SelectionEvent::Click, 2)} + << QList{2}; } void tst_QAbstractItemView::mouseSelection() -- cgit v1.2.3