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>
This commit is contained in:
parent
025fca60f5
commit
bf12f5efa4
|
@ -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) {
|
||||
const QModelIndex tappedIndex = q->modelIndex(q->cellAtPosition(point.position()));
|
||||
bool tappedCellIsSelected = false;
|
||||
|
||||
if (selectionModel)
|
||||
tappedCellIsSelected = selectionModel->isSelected(tappedIndex);
|
||||
|
||||
if (canEdit(tappedIndex, false)) {
|
||||
if (editTriggers & QQuickTableView::SingleTapped) {
|
||||
clearSelection();
|
||||
setCurrentIndexFromTap(point.position());
|
||||
q->edit(tappedIndex);
|
||||
return;
|
||||
} else if (editTriggers & QQuickTableView::SelectedTapped && tappedCellIsSelected) {
|
||||
q->edit(tappedIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (editTriggers != QQuickTableView::NoEditTriggers)
|
||||
// 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();
|
||||
|
||||
const QModelIndex tappedIndex = q->modelIndex(q->cellAtPosition(point.position()));
|
||||
if (canEdit(tappedIndex, false)) {
|
||||
if (editTriggers & QQuickTableView::SingleTapped)
|
||||
q->edit(tappedIndex);
|
||||
else if ((editTriggers & QQuickTableView::SelectedTapped) && tappedIndex == prevIndex)
|
||||
q->edit(tappedIndex);
|
||||
clearSelection();
|
||||
setCurrentIndexFromTap(point.position());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6591,7 +6591,7 @@ void tst_QQuickTableView::editUsingEditTriggers()
|
|||
|
||||
if (editTriggers & QQuickTableView::SelectedTapped) {
|
||||
// select cell first, then tap on it
|
||||
tableView->selectionModel()->setCurrentIndex(index1, QItemSelectionModel::NoUpdate);
|
||||
tableView->selectionModel()->setCurrentIndex(index1, QItemSelectionModel::Select);
|
||||
QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, tapPos1);
|
||||
QCOMPARE(tableView->selectionModel()->currentIndex(), index1);
|
||||
const auto editItem1 = tableView->property(kEditItem).value<QQuickItem *>();
|
||||
|
@ -6612,6 +6612,11 @@ void tst_QQuickTableView::editUsingEditTriggers()
|
|||
QVERIFY(!tableView->property(kEditItem).value<QQuickItem *>());
|
||||
QVERIFY(!tableView->property(kEditIndex).value<QModelIndex>().isValid());
|
||||
QCOMPARE(tableView->selectionModel()->currentIndex(), index2);
|
||||
|
||||
// tap on the current cell. This alone should not start an edit (unless it's also selected)
|
||||
QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, tapPos1);
|
||||
QVERIFY(!tableView->property(kEditItem).value<QQuickItem *>());
|
||||
QVERIFY(!tableView->property(kEditIndex).value<QModelIndex>().isValid());
|
||||
}
|
||||
|
||||
if (editTriggers & QQuickTableView::EditKeyPressed) {
|
||||
|
|
Loading…
Reference in New Issue