Skip to content

Commit a63c691

Browse files
Richard Moe GustavsenQt Cherry-pick Bot
authored andcommitted
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 4335010) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 43ebd25)
1 parent d661e38 commit a63c691

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/quicktemplates/qquickselectionrectangle.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,14 @@ QQuickSelectionRectanglePrivate::QQuickSelectionRectanglePrivate()
242242
}
243243

244244
if (modifiers == Qt::ShiftModifier) {
245-
// Extend the existing selection towards the pressed cell
246-
if (!m_active)
247-
return;
245+
// Extend the selection towards the pressed cell. If there is no
246+
// existing selection, start a new selection from the current item
247+
// to the pressed item.
248+
if (!m_active) {
249+
if (!m_selectable->startSelection(pos))
250+
return;
251+
m_selectable->setSelectionStartPos(QPoint{-1, -1});
252+
}
248253
m_selectable->setSelectionEndPos(pos);
249254
updateHandles();
250255
updateActiveState(true);

tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,31 @@ TestCase {
571571
verify(!tableView.selectionModel.hasSelection)
572572
}
573573

574+
function test_pressAndHoldPlussShift() {
575+
let tableView = createTemporaryObject(tableviewComp, testCase)
576+
verify(tableView)
577+
let selectionRectangle = tableView.selectionRectangle
578+
verify(selectionRectangle)
579+
580+
selectionRectangle.selectionMode = SelectionRectangle.Drag
581+
582+
verify(!tableView.selectionModel.hasSelection)
583+
verify(!tableView.selectionModel.currentIndex.isValid)
584+
585+
// select cell 0,0
586+
mouseClick(tableView, 1, 1, Qt.LeftButton)
587+
compare(tableView.selectionModel.currentIndex, tableView.index(0, 0))
588+
589+
// do a long press on cell 1,0 while holding down Shift. This will
590+
// select both cells.
591+
mousePress(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier)
592+
mouseRelease(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier, 2000)
593+
verify(tableView.selectionModel.hasSelection)
594+
compare(tableView.selectionModel.selectedIndexes.length, 2)
595+
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
596+
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
597+
}
598+
574599
function test_pressAndHold_on_top_of_handle() {
575600
let tableView = createTemporaryObject(tableviewComp, testCase)
576601
verify(tableView)

0 commit comments

Comments
 (0)