diff options
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 16 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p_p.h | 16 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/data/tableviewinteractive.qml | 32 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 37 |
4 files changed, 100 insertions, 1 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index c8d07ace6f..cc5c45db72 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -4154,7 +4154,7 @@ void QQuickTableViewPrivate::init() positionYAnimation.setProperty(QStringLiteral("contentY")); positionYAnimation.setEasing(QEasingCurve::OutQuart); - auto tapHandler = new QQuickTapHandler(q->contentItem()); + auto tapHandler = new QQuickTableViewTapHandler(q); QObject::connect(tapHandler, &QQuickTapHandler::pressedChanged, [this, q, tapHandler] { if (!pointerNavigationEnabled || !tapHandler->isPressed()) @@ -5288,6 +5288,20 @@ QQuickTableSectionSizeProviderPrivate::~QQuickTableSectionSizeProviderPrivate() } +// ---------------------------------------------- + +QQuickTableViewTapHandler::QQuickTableViewTapHandler(QQuickTableView *view) + : QQuickTapHandler(view->contentItem()) +{ +} + +bool QQuickTableViewTapHandler::wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) +{ + auto tableView = static_cast<QQuickTableView *>(parentItem()->parent()); + auto tableViewPrivate = QQuickTableViewPrivate::get(tableView); + return tableViewPrivate->pointerNavigationEnabled && QQuickTapHandler::wantsEventPoint(event, point); +} + QT_END_NAMESPACE #include "moc_qquicktableview_p.cpp" diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index e3eea18bca..7c865169cb 100644 --- a/src/quick/items/qquicktableview_p_p.h +++ b/src/quick/items/qquicktableview_p_p.h @@ -29,6 +29,7 @@ #include <QtQuick/private/qquickitemviewfxitem_p_p.h> #include <QtQuick/private/qquickanimation_p.h> #include <QtQuick/private/qquickselectable_p.h> +#include <QtQuick/private/qquicktaphandler_p.h> QT_BEGIN_NAMESPACE @@ -60,6 +61,21 @@ private: Q_DECLARE_PRIVATE(QQuickTableSectionSizeProvider) }; +/*! \internal + * QQuickTableViewTapHandler used to handle tap events explicitly for table view + */ +class QQuickTableViewTapHandler : public QQuickTapHandler +{ + Q_OBJECT + +public: + explicit QQuickTableViewTapHandler(QQuickTableView *view); + bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override; + + friend class QQuickTableViewPrivate; +}; + + class Q_QUICK_PRIVATE_EXPORT QQuickTableViewPrivate : public QQuickFlickablePrivate, public QQuickSelectable { public: diff --git a/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml b/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml new file mode 100644 index 0000000000..526313dc24 --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml @@ -0,0 +1,32 @@ +import QtQuick +import QtQuick.Controls + +Item { + id: rootItem + + width: 200 + height: 200 + visible: true + + property int eventCount: 0 + property alias tableView: tableView + + MouseArea { + anchors.fill: parent + onPressed: function(mouse) { + ++eventCount + } + } + + TableView { + id: tableView + objectName: "tableView" + anchors.fill: parent + model: 1 + delegate: Rectangle { + color: "red" + implicitWidth: 200 + implicitHeight: 200 + } + } +} diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index c433e65e53..176b9cb603 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -218,6 +218,7 @@ private slots: void testDeprecatedApi(); void alternatingRows(); void boundDelegateComponent(); + void tableViewInteractive(); }; tst_QQuickTableView::tst_QQuickTableView() @@ -5487,6 +5488,42 @@ void tst_QQuickTableView::boundDelegateComponent() QVERIFY(innerTableView->itemAtCell(0, i)->objectName().isEmpty()); } +void tst_QQuickTableView::tableViewInteractive() +{ + LOAD_TABLEVIEW("tableviewinteractive.qml"); + auto *root = view->rootObject(); + QVERIFY(root); + auto *window = root->window(); + QVERIFY(window); + int eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 0); + // Event though we make 'interactive' as false, the TableView has + // pointerNacigationEnabled set as true by default, which allows it to consume + // mouse events and thus, eventCount still be zero + tableView->setInteractive(false); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 0); + // Making both 'interactive' and 'pointerNavigationEnabled' as false, doesn't + // allow TableView (and its parent Flickable) to consume mouse event and it + // passes to the below visual item + tableView->setInteractive(false); + tableView->setPointerNavigationEnabled(false); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 1); + // Making 'interactive' as true and 'pointerNavigationEnabled' as false, + // allows parent of TableView (i.e. Flickable) to consume mouse events + tableView->setInteractive(true); + tableView->setPointerNavigationEnabled(false); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 1); +} + QTEST_MAIN(tst_QQuickTableView) #include "tst_qquicktableview.moc" |