aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2023-03-10 11:46:25 +0100
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2023-03-17 20:57:14 +0100
commitbf12f5efa41f4ccd9622b0939a143269e66090cd (patch)
tree535ca8c303c466a4a1e6faa9c0b16055f7c28ccd /src/quick/items/qquicktableview.cpp
parent025fca60f504362c9b2b1db667ef16af225b69c6 (diff)
QQuickTableView: implement SelectedTapped correctly
The current implementation of SelectedTapped allowed the user to start editing when tapping on the _current_ cell. This is not correct, SelectedTapped is supposed to (like the name suggests) let the user start editing when tapping on a _selected_ cell. This patch will change the implementation so that the user can tap on a selected cell to edit it. Pick-to: 6.5 Change-Id: Ice5de9250c23f5f57e71077d4f46d1a3f31e9b80 Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r--src/quick/items/qquicktableview.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 59aaec1e9d..1df8f538a8 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -725,8 +725,8 @@
But the application can call \l edit() and \l closeEditor() manually.
\value TableView.SingleTapped - the user can edit a cell by single tapping it.
\value TableView.DoubleTapped - the user can edit a cell by double tapping it.
- \value TableView.SelectedTapped - the user can edit the
- \l {QItemSelectionModel::currentIndex()}{current cell} by tapping it.
+ \value TableView.SelectedTapped - the user can edit a
+ \l {QItemSelectionModel::selectedIndexes()}{selected cell} by tapping it.
\value TableView.EditKeyPressed - the user can edit the
\l {QItemSelectionModel::currentIndex()}{current cell} by pressing one
of the edit keys. The edit keys are decided by the OS, but are normally
@@ -4790,24 +4790,29 @@ void QQuickTableViewPrivate::handleTap(const QQuickHandlerPoint &point)
if (resizeHandler->state() != QQuickTableViewResizeHandler::Listening)
return;
- QModelIndex prevIndex;
- if (selectionModel) {
- prevIndex = selectionModel->currentIndex();
- if (pointerNavigationEnabled) {
- clearSelection();
- setCurrentIndexFromTap(point.position());
- }
- }
+ const QModelIndex tappedIndex = q->modelIndex(q->cellAtPosition(point.position()));
+ bool tappedCellIsSelected = false;
- if (editTriggers != QQuickTableView::NoEditTriggers)
- q->closeEditor();
+ if (selectionModel)
+ tappedCellIsSelected = selectionModel->isSelected(tappedIndex);
- const QModelIndex tappedIndex = q->modelIndex(q->cellAtPosition(point.position()));
if (canEdit(tappedIndex, false)) {
- if (editTriggers & QQuickTableView::SingleTapped)
+ if (editTriggers & QQuickTableView::SingleTapped) {
+ clearSelection();
q->edit(tappedIndex);
- else if ((editTriggers & QQuickTableView::SelectedTapped) && tappedIndex == prevIndex)
+ return;
+ } else if (editTriggers & QQuickTableView::SelectedTapped && tappedCellIsSelected) {
q->edit(tappedIndex);
+ return;
+ }
+ }
+
+ // Since the tap didn't result in selecting or editing cells, we clear
+ // the current selection and move the current index instead.
+ if (pointerNavigationEnabled) {
+ q->closeEditor();
+ clearSelection();
+ setCurrentIndexFromTap(point.position());
}
}