diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-11-09 10:41:12 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-11-16 00:24:23 +0100 |
commit | 3af953871300f3eba3f6647e96a4e98532c4293a (patch) | |
tree | 31c93a9e3010014aee49d41d3547f9427ab2a2fb | |
parent | 7fa4a53ebba1d10f249d017551e618b0406a3b57 (diff) |
QQuickTableView: don't change index if tapping on the resize area
The current implementation would change the current index when
a single tap was done on the resize area between the cells.
But doing that was not ideal if the tap turned out to be
a double tap instead, since a double tap should only reset
the column size. The current solution would solve this by
using exclusive signals on the tap handler. But despite of
that, it would still look wrong that a tap on the resize
area, while the cursor has a resize appearance, changed the
index. Using exclusive signals also comes with a small signal
delay.
So, all in all, it's simply better to change the logic
so that the resize area is reserved for resizing only.
And then, to change the current index, the tap needs to
happen outside the resize area.
Change-Id: I1e7cb8d1031d1b86c14d777c322f1717fa5eb171
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 38 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 37 |
2 files changed, 47 insertions, 28 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 3161df9061..e267ea329f 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -4316,7 +4316,6 @@ void QQuickTableViewPrivate::init() positionYAnimation.setEasing(QEasingCurve::OutQuart); auto tapHandler = new QQuickTapHandler(q->contentItem()); - tapHandler->setExclusiveSignals(QQuickTapHandler::SingleTap | QQuickTapHandler::DoubleTap); hoverHandler = new QQuickTableViewHoverHandler(q); resizeHandler = new QQuickTableViewResizeHandler(q); @@ -4341,6 +4340,10 @@ void QQuickTableViewPrivate::init() q->forceActiveFocus(Qt::MouseFocusReason); if (q->isInteractive()) return; + if (resizableRows && hoverHandler->m_row != -1) + return; + if (resizableColumns && hoverHandler->m_column != -1) + return; if (resizeHandler->state() != QQuickTableViewResizeHandler::Listening) return; @@ -4349,22 +4352,25 @@ void QQuickTableViewPrivate::init() currentIndexChangedOnPress = true; }); - QObject::connect(tapHandler, &QQuickTapHandler::tapped, [this, q, tapHandler] { - if (currentIndexChangedOnPress) + QObject::connect(tapHandler, &QQuickTapHandler::singleTapped, [this, tapHandler] { + if (!pointerNavigationEnabled || currentIndexChangedOnPress) return; - if (tapHandler->tapCount() == 1) { - if (pointerNavigationEnabled) { - clearSelection(); - setCurrentIndexFromTap(tapHandler->point().pressPosition()); - } - } else if (tapHandler->tapCount() == 2) { - if (hoverHandler->isHoveringGrid()) { - if (hoverHandler->m_row != -1) - q->setRowHeight(hoverHandler->m_row, -1); - if (hoverHandler->m_column != -1) - q->setColumnWidth(hoverHandler->m_column, -1); - } - } + if (resizableRows && hoverHandler->m_row != -1) + return; + if (resizableColumns && hoverHandler->m_column != -1) + return; + + clearSelection(); + setCurrentIndexFromTap(tapHandler->point().pressPosition()); + }); + + QObject::connect(tapHandler, &QQuickTapHandler::doubleTapped, [this, q] { + const bool resizeRow = resizableRows && hoverHandler->m_row != -1; + const bool resizeColumn = resizableColumns && hoverHandler->m_column != -1; + if (resizeRow) + q->setRowHeight(hoverHandler->m_row, -1); + if (resizeColumn) + q->setColumnWidth(hoverHandler->m_column, -1); }); } diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 4914af8a3c..f04816b167 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -6270,23 +6270,33 @@ void tst_QQuickTableView::dragFromCellCenter() void tst_QQuickTableView::tapOnResizeArea_data() { - QTest::addColumn<bool>("pointerNavigationEnabled"); - QTest::newRow("pointer naviagation enabled") << true; - QTest::newRow("pointer naviagation disabled") << false; + QTest::addColumn<bool>("resizableRows"); + QTest::addColumn<bool>("resizableColumns"); + QTest::addColumn<bool>("interactive"); + + for (bool interactive : {true, false}) { + QTest::newRow("resize disabled") << false << false << interactive; + QTest::newRow("resizableRows") << true << false << interactive; + QTest::newRow("resizableColumns") << false << true << interactive; + QTest::newRow("resizableRows && resizableColumns") << true << true << interactive; + } } void tst_QQuickTableView::tapOnResizeArea() { - // Check that the user can tap close to the edge of a cell, on the resize area, and - // as such, change the current index (unless pointer navigation is disabled). - QFETCH(bool, pointerNavigationEnabled); + // Check that if a tap or a press happens on the resize area between the + // cells, we only change the current index if the resizing is disabled. + QFETCH(bool, resizableRows); + QFETCH(bool, resizableColumns); + QFETCH(bool, interactive); LOAD_TABLEVIEW("tableviewwithselected2.qml"); auto model = TestModel(3, 3); tableView->setModel(QVariant::fromValue(&model)); - tableView->setResizableColumns(true); - tableView->setResizableRows(true); - tableView->setPointerNavigationEnabled(pointerNavigationEnabled); + tableView->setResizableRows(resizableRows); + tableView->setResizableColumns(resizableColumns); + tableView->setInteractive(interactive); + tableView->setPointerNavigationEnabled(true); WAIT_UNTIL_POLISHED; @@ -6297,13 +6307,16 @@ void tst_QQuickTableView::tapOnResizeArea() const QPoint localPos = QPoint(item->width() - 1, item->height() - 1); const QPoint tapPos = window->contentItem()->mapFromItem(item, localPos).toPoint(); + // Start by moving the mouse out of the way + QTest::mouseMove(window, tapPos + QPoint(200, 200)); + // Then do a tap on the resize area QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, tapPos); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, tapPos); - if (pointerNavigationEnabled) - QCOMPARE(tableView->selectionModel()->currentIndex(), model.index(1, 1)); - else + if (resizableRows || resizableColumns) QVERIFY(!tableView->selectionModel()->currentIndex().isValid()); + else + QCOMPARE(tableView->selectionModel()->currentIndex(), model.index(1, 1)); } QTEST_MAIN(tst_QQuickTableView) |