aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2024-01-09 15:46:05 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-01-16 10:05:36 +0000
commita63c691041df948152d330b71012b36d626ed0b8 (patch)
treebc9b4918195467c0618c5322b7b58cd43ad72515
parentd661e38affb7c59e1bd31e06de1f67ce5d1f82db (diff)
TableView: start a new selection when using Qt::ShiftModifier (PressAndHold)
Follow up on previous patch to qquickselectionrectangle, and implement starting a new selection when using Qt::ShiftModifier also for PressAndHold. This configuration, PressAndHold + holding Shift to start a selection, is normally not used in combination. But at the same time, there seems to be no reason why it should't work either, as using selections handles on desktop is allowed. Task-number: QTBUG-120628 Pick-to: 6.5 Change-Id: I8a7589ffd4d16e339a5654605ee0916d96c8cbf0 Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> (cherry picked from commit 4335010a80a4b5128d3da66c654a458a3b53f65f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 43ebd251240b5fb07bacfae73eb47eb5234759c1)
-rw-r--r--src/quicktemplates/qquickselectionrectangle.cpp11
-rw-r--r--tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml25
2 files changed, 33 insertions, 3 deletions
diff --git a/src/quicktemplates/qquickselectionrectangle.cpp b/src/quicktemplates/qquickselectionrectangle.cpp
index 58e7c2e752..80f4ab1b44 100644
--- a/src/quicktemplates/qquickselectionrectangle.cpp
+++ b/src/quicktemplates/qquickselectionrectangle.cpp
@@ -242,9 +242,14 @@ QQuickSelectionRectanglePrivate::QQuickSelectionRectanglePrivate()
}
if (modifiers == Qt::ShiftModifier) {
- // Extend the existing selection towards the pressed cell
- if (!m_active)
- return;
+ // Extend the selection towards the pressed cell. If there is no
+ // existing selection, start a new selection from the current item
+ // to the pressed item.
+ if (!m_active) {
+ if (!m_selectable->startSelection(pos))
+ return;
+ m_selectable->setSelectionStartPos(QPoint{-1, -1});
+ }
m_selectable->setSelectionEndPos(pos);
updateHandles();
updateActiveState(true);
diff --git a/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml b/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml
index fc5bd98b35..932ca0b1c7 100644
--- a/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml
+++ b/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml
@@ -571,6 +571,31 @@ TestCase {
verify(!tableView.selectionModel.hasSelection)
}
+ function test_pressAndHoldPlussShift() {
+ let tableView = createTemporaryObject(tableviewComp, testCase)
+ verify(tableView)
+ let selectionRectangle = tableView.selectionRectangle
+ verify(selectionRectangle)
+
+ selectionRectangle.selectionMode = SelectionRectangle.Drag
+
+ verify(!tableView.selectionModel.hasSelection)
+ verify(!tableView.selectionModel.currentIndex.isValid)
+
+ // select cell 0,0
+ mouseClick(tableView, 1, 1, Qt.LeftButton)
+ compare(tableView.selectionModel.currentIndex, tableView.index(0, 0))
+
+ // do a long press on cell 1,0 while holding down Shift. This will
+ // select both cells.
+ mousePress(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier)
+ mouseRelease(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier, 2000)
+ verify(tableView.selectionModel.hasSelection)
+ compare(tableView.selectionModel.selectedIndexes.length, 2)
+ verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
+ verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
+ }
+
function test_pressAndHold_on_top_of_handle() {
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)