diff options
| author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-05-25 19:25:25 +0200 |
|---|---|---|
| committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-05-26 14:46:39 +0200 |
| commit | 2d1ec2f84953f93fb661d442cd4207e7f0198e4b (patch) | |
| tree | 7425d58e02d024e7b2129851dc9d0aedbf477768 /tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp | |
| parent | 348085dd7d1aeb83628eeb9687d70b0ba595dacd (diff) | |
PointerHandler constructor: add to Item parent's list of handlers
When a pointer handler is created in C++, a parent Item might be given
to the constructor, so QQuickItemPrivate::data_append() might not be
called. But to be functional, it needs to be added to
ExtraData.pointerHandlers.
Task-number: QTBUG-68110
Change-Id: I02f6574f801018b964ecf4167bac65792d9c6094
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp')
| -rw-r--r-- | tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp index 2d8c722649..9bbf7a38b7 100644 --- a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp @@ -185,6 +185,9 @@ public: class EventHandler : public QQuickPointerHandler { public: + EventHandler(QQuickItem *parent = nullptr) : + QQuickPointerHandler(parent) {} + void handlePointerEventImpl(QPointerEvent *event) override { QQuickPointerHandler::handlePointerEventImpl(event); @@ -247,6 +250,7 @@ private slots: void dynamicCreation(); void handlerInWindow(); void dynamicCreationInWindow(); + void cppConstruction(); protected: bool eventFilter(QObject *, QEvent *event) override @@ -695,6 +699,39 @@ void tst_PointerHandlers::dynamicCreationInWindow() QTRY_COMPARE(handler->releaseEventCount, 1); } +void tst_PointerHandlers::cppConstruction() +{ + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "itemOnly.qml"); + QQuickView * window = windowPtr.data(); + + EventItem *eventItem1 = window->rootObject()->findChild<EventItem*>("eventItem1"); + QVERIFY(eventItem1); + QQuickItemPrivate *eventItemPriv = QQuickItemPrivate::get(eventItem1); + // tell the handler to grab on press + eventItem1->grabPointer = true; + + EventHandler handler(eventItem1); + QCOMPARE(handler.parentItem(), eventItem1); + QCOMPARE(handler.target(), eventItem1); + QCOMPARE(eventItemPriv->extra->pointerHandlers.first(), &handler); + QVERIFY(eventItemPriv->extra->resourcesList.contains(&handler)); + + // the handler and then eventItem1 sees each event + QPoint p1 = QPoint(20, 20); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, p1); + QCOMPARE(handler.pressEventCount, 1); + qCDebug(lcPointerTests) << "events after mouse press" << eventItem1->eventList; + QCOMPARE(eventItem1->eventList.size(), 3); + QTest::mouseRelease(window, Qt::LeftButton); + QCOMPARE(handler.releaseEventCount, 1); + qCDebug(lcPointerTests) << "events after mouse release" << eventItem1->eventList; + QCOMPARE(eventItem1->eventList.size(), 7); + + // wait to avoid getting a double click event + QTest::qWait(qApp->styleHints()->mouseDoubleClickInterval() + 10); +} + QTEST_MAIN(tst_PointerHandlers) #include "tst_qquickpointerhandler.moc" |
