diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-07-13 23:55:13 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-07-15 20:53:10 +0200 |
commit | 1204ed14dc11e6343a569646428a7ffddd098f8c (patch) | |
tree | 49ff80392d6ffbb18e6f5b3dbbe5aa366d230ac5 /tests/auto | |
parent | 2967572e129cab889d9c6f89825ef9d77bf1ce63 (diff) |
Begin handling the QEvent refactoring
This is an intermediate step to get Qt Quick working again after
qtbase 4e400369c08db251cd489fec1229398c224d02b4.
- QQuickEventPoint::id() is no longer unique across devices, because now
eventPoint.event.device tells which specific device the event comes from.
(In Qt 5, we could not yet add the device pointer to QInputEvent.)
- However, MultiPointTouchArea's docs say that each pointId is unique,
and so do the HandlerPoint docs (for similar use cases with PointHandler).
So we still need the same hack using a Qt-specific short device ID
to unique-ify the QEventPoint::id(). Now we use the device index
in QInputDevice::devices() as the short ID.
- Otherwise, we trust QInputDevice::systemId() and QEventPoint::id()
more than before.
- Use QMutable* classes from qevent_p.h to continue using setters
that were in QTouchEvent before, etc. But setTouchPoints() is
not there, so we have to make new event instances in a couple of cases.
- QGuiApplicationPrivate::setMouseEventCapsAndVelocity() and
setMouseEventSource() are gone.
- Use (compiler-written) event copy constructors when possible.
Task-number: QTBUG-72173
Change-Id: I3915dc535ae4c5a81cbf333aba9355f01c420c15
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
5 files changed, 68 insertions, 77 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp index 89e9fa3f23..cd24d8643e 100644 --- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp @@ -29,8 +29,9 @@ #include <QtTest/QtTest> #include <QtTest/QSignalSpy> #include <QtGui/QStyleHints> +#include <QtGui/private/qevent_p.h> #include <qpa/qwindowsysteminterface.h> -#include <private/qquickpinchhandler_p.h> +#include <QtQuick/private/qquickpinchhandler_p.h> #include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/qquickview.h> #include <QtQml/qqmlcontext.h> @@ -186,12 +187,12 @@ void tst_QQuickPinchHandler::pinchProperties() QCOMPARE(rotMaxSpy.count(),1); } -QEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) +QMutableEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) { - QEventPoint touchPoint(id); - touchPoint.setPos(i->mapFromScene(p)); - touchPoint.setScreenPos(v->mapToGlobal(p)); - touchPoint.setScenePos(p); + QMutableEventPoint touchPoint(id); + touchPoint.setPosition(i->mapFromScene(p)); + touchPoint.setGlobalPosition(v->mapToGlobal(p)); + touchPoint.setScenePosition(p); return touchPoint; } diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index 0e7ab12074..f8986ce66b 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -33,6 +33,7 @@ #include <QtQuick/qquickview.h> #include "private/qquickfocusscope_p.h" #include "private/qquickitem_p.h" +#include <QtGui/private/qevent_p.h> #include <qpa/qwindowsysteminterface.h> #ifdef Q_OS_WIN #include <QOpenGLContext> @@ -1341,15 +1342,12 @@ void tst_qquickitem::touchEventAcceptIgnore() // Send Begin, Update & End touch sequence { - QEventPoint point; - point.setId(1); - point.setPos(QPointF(50, 50)); - point.setScreenPos(point.position()); - point.setState(QEventPoint::State::Pressed); + QMutableEventPoint point(1, QEventPoint::State::Pressed); + point.setPosition(QPointF(50, 50)); + point.setGlobalPosition(point.position()); QTouchEvent event(QEvent::TouchBegin, device, Qt::NoModifier, - QEventPoint::State::Pressed, QList<QEventPoint>() << point); event.setAccepted(true); @@ -1365,15 +1363,12 @@ void tst_qquickitem::touchEventAcceptIgnore() QCOMPARE(accepted && event.isAccepted(), true); } { - QEventPoint point; - point.setId(1); - point.setPos(QPointF(60, 60)); - point.setScreenPos(point.position()); - point.setState(QEventPoint::State::Updated); + QMutableEventPoint point(1, QEventPoint::State::Updated); + point.setPosition(QPointF(60, 60)); + point.setGlobalPosition(point.position()); QTouchEvent event(QEvent::TouchUpdate, device, Qt::NoModifier, - QEventPoint::State::Updated, QList<QEventPoint>() << point); event.setAccepted(true); @@ -1389,15 +1384,12 @@ void tst_qquickitem::touchEventAcceptIgnore() QCOMPARE(accepted && event.isAccepted(), true); } { - QEventPoint point; - point.setId(1); - point.setPos(QPointF(60, 60)); - point.setScreenPos(point.position()); - point.setState(QEventPoint::State::Released); + QMutableEventPoint point(1, QEventPoint::State::Released); + point.setPosition(QPointF(60, 60)); + point.setGlobalPosition(point.position()); QTouchEvent event(QEvent::TouchEnd, device, Qt::NoModifier, - QEventPoint::State::Released, QList<QEventPoint>() << point); event.setAccepted(true); @@ -1620,7 +1612,7 @@ void tst_qquickitem::hoverEvent_data() // ### For some unknown reason QTest::mouseMove() isn't working correctly. static void sendMouseMove(QObject *object, const QPoint &position) { - QMouseEvent moveEvent(QEvent::MouseMove, position, Qt::NoButton, Qt::NoButton, nullptr); + QMouseEvent moveEvent(QEvent::MouseMove, position, Qt::NoButton, Qt::NoButton, Qt::NoModifier); QGuiApplication::sendEvent(object, &moveEvent); } diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index 0806914763..47f7943d12 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -35,6 +35,7 @@ #include <qpa/qwindowsysteminterface.h> #include <QtQuick/qquickview.h> #include <QtGui/QScreen> +#include <QtGui/private/qevent_p.h> #include "../../shared/util.h" #include "../shared/viewtestutil.h" @@ -1373,9 +1374,9 @@ void tst_QQuickMultiPointTouchArea::stationaryTouchWithChangingPressure() // QTB QCOMPARE(point1->pressed(), false); QPoint p1(20,100); - QEventPoint tp1(1); + QMutableEventPoint tp1(1); - tp1.setScreenPos(window->mapToGlobal(p1)); + tp1.setGlobalPosition(window->mapToGlobal(p1)); tp1.setState(QEventPoint::State::Pressed); tp1.setPressure(0.5); qt_handleTouchEvent(window.data(), device, {tp1}); diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp index b65e12d2be..a9f35e8727 100644 --- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -29,6 +29,7 @@ #include <QtTest/QtTest> #include <QtTest/QSignalSpy> #include <QtGui/QStyleHints> +#include <QtGui/private/qevent_p.h> #include <qpa/qwindowsysteminterface.h> #include <private/qquickpincharea_p.h> #include <QtQuick/private/qquickrectangle_p.h> @@ -175,12 +176,12 @@ void tst_QQuickPinchArea::pinchProperties() QCOMPARE(rotMaxSpy.count(),1); } -QEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) +QMutableEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) { - QEventPoint touchPoint(id); - touchPoint.setPos(i->mapFromScene(p)); - touchPoint.setScreenPos(v->mapToGlobal(p)); - touchPoint.setScenePos(p); + QMutableEventPoint touchPoint(id); + touchPoint.setPosition(i->mapFromScene(p)); + touchPoint.setGlobalPosition(v->mapToGlobal(p)); + touchPoint.setScenePosition(p); return touchPoint; } diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index ef304894bc..603fa28bee 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -68,18 +68,16 @@ struct TouchEventData { QList<QEventPoint> touchPoints; }; -static QEventPoint makeTouchPoint(QQuickItem *item, const QPointF &p, const QPointF &lastPoint = QPointF()) +static QMutableEventPoint makeTouchPoint(QQuickItem *item, const QPointF &p, const QPointF &lastPoint = QPointF()) { QPointF last = lastPoint.isNull() ? p : lastPoint; - QEventPoint tp; + QMutableEventPoint tp; - tp.setPos(p); - tp.setLastPos(last); - tp.setScenePos(item->mapToScene(p)); - tp.setLastScenePos(item->mapToScene(last)); - tp.setScreenPos(item->window()->mapToGlobal(tp.scenePosition().toPoint())); - tp.setLastScreenPos(item->window()->mapToGlobal(tp.lastScenePos().toPoint())); + tp.setPosition(p); + tp.setScenePosition(item->mapToScene(p)); + tp.setGlobalPosition(item->mapToGlobal(p)); + tp.setGlobalLastPosition(item->mapToGlobal(last)); return tp; } @@ -98,12 +96,12 @@ static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, QEventPoint:: #define COMPARE_TOUCH_POINTS(tp1, tp2) \ { \ - QCOMPARE(tp1.position(), tp2.pos()); \ - QCOMPARE(tp1.lastPos(), tp2.lastPos()); \ - QCOMPARE(tp1.scenePos(), tp2.scenePos()); \ - QCOMPARE(tp1.lastScenePos(), tp2.lastScenePos()); \ - QCOMPARE(tp1.screenPos(), tp2.screenPos()); \ - QCOMPARE(tp1.lastScreenPos(), tp2.lastScreenPos()); \ + QCOMPARE(tp1.position(), tp2.position()); \ + QCOMPARE(tp1.lastPosition(), tp2.lastPosition()); \ + QCOMPARE(tp1.scenePosition(), tp2.scenePosition()); \ + QCOMPARE(tp1.sceneLastPosition(), tp2.sceneLastPosition()); \ + QCOMPARE(tp1.globalPosition(), tp2.globalPosition()); \ + QCOMPARE(tp1.globalLastPosition(), tp2.globalLastPosition()); \ } #define COMPARE_TOUCH_DATA(d1, d2) \ @@ -207,7 +205,7 @@ public: return; } ++touchEventCount; - lastEvent = makeTouchData(event->type(), event->window(), event->touchPointStates(), event->touchPoints()); + lastEvent = makeTouchData(event->type(), nullptr, event->touchPointStates(), event->touchPoints()); if (event->device()->capabilities().testFlag(QPointingDevice::Capability::Velocity) && !event->touchPoints().isEmpty()) { lastVelocity = event->touchPoints().first().velocity(); } else { @@ -234,7 +232,7 @@ public: return; } mouseMoveCount = ++mouseMoveNum; - lastVelocityFromMouseMove = QGuiApplicationPrivate::mouseEventVelocity(e); + lastVelocityFromMouseMove = e->point(0).velocity(); lastMouseCapabilityFlags = e->device()->capabilities(); lastMousePos = e->position().toPoint(); } @@ -1006,14 +1004,12 @@ void tst_qquickwindow::touchEvent_velocity() item->setPosition(QPointF(50, 50)); item->setSize(QSizeF(150, 150)); - QList<QEventPoint> points; - QEventPoint tp; - tp.setId(1); - tp.setState(QEventPoint::State::Pressed); + QList<QMutableEventPoint> points; + QMutableEventPoint tp(1, QEventPoint::State::Pressed); const QPointF localPos = item->mapToScene(QPointF(10, 10)); const QPointF screenPos = window->mapToGlobal(localPos.toPoint()); - tp.setPos(localPos); - tp.setScreenPos(screenPos); + tp.setPosition(localPos); + tp.setGlobalPosition(screenPos); tp.setEllipseDiameters(QSizeF(4, 4)); points << tp; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, @@ -1023,8 +1019,8 @@ void tst_qquickwindow::touchEvent_velocity() QCOMPARE(item->touchEventCount, 1); points[0].setState(QEventPoint::State::Updated); - points[0].setPos(localPos + QPointF(5, 5)); - points[0].setScreenPos(screenPos + QPointF(5, 5)); + points[0].setPosition(localPos + QPointF(5, 5)); + points[0].setGlobalPosition(screenPos + QPointF(5, 5)); QVector2D velocity(1.5, 2.5); points[0].setVelocity(velocity); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, @@ -1040,8 +1036,8 @@ void tst_qquickwindow::touchEvent_velocity() QMatrix4x4 transformMatrix; transformMatrix.rotate(-90, 0, 0, 1); // counterclockwise QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D(); - points[0].setPos(points[0].position() + QPointF(5, 5)); - points[0].setScreenPos(points[0].globalPosition() + QPointF(5, 5)); + points[0].setPosition(points[0].position() + QPointF(5, 5)); + points[0].setGlobalPosition(points[0].globalPosition() + QPointF(5, 5)); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); @@ -1150,14 +1146,12 @@ void tst_qquickwindow::mouseFromTouch_basic() item->setSize(QSizeF(150, 150)); item->acceptTouchEvents = false; - QList<QEventPoint> points; - QEventPoint tp; - tp.setId(1); - tp.setState(QEventPoint::State::Pressed); + QList<QMutableEventPoint> points; + QMutableEventPoint tp(1, QEventPoint::State::Pressed); const QPointF localPos = item->mapToScene(QPointF(10, 10)); const QPointF screenPos = window->mapToGlobal(localPos.toPoint()); - tp.setPos(localPos); - tp.setScreenPos(screenPos); + tp.setPosition(localPos); + tp.setGlobalPosition(screenPos); tp.setEllipseDiameters(QSizeF(4, 4)); points << tp; QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, @@ -1165,8 +1159,8 @@ void tst_qquickwindow::mouseFromTouch_basic() QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); points[0].setState(QEventPoint::State::Updated); - points[0].setPos(localPos + QPointF(5, 5)); - points[0].setScreenPos(screenPos + QPointF(5, 5)); + points[0].setPosition(localPos + QPointF(5, 5)); + points[0].setGlobalPosition(screenPos + QPointF(5, 5)); QVector2D velocity(1.5, 2.5); points[0].setVelocity(velocity); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, @@ -1194,15 +1188,15 @@ void tst_qquickwindow::mouseFromTouch_basic() QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D(); points[0].setState(QEventPoint::State::Pressed); points[0].setVelocity(velocity); - tp.setPos(localPos); - tp.setScreenPos(screenPos); + tp.setPosition(localPos); + tp.setGlobalPosition(screenPos); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); QQuickTouchUtils::flush(window); points[0].setState(QEventPoint::State::Updated); - points[0].setPos(localPos + QPointF(5, 5)); - points[0].setScreenPos(screenPos + QPointF(5, 5)); + points[0].setPosition(localPos + QPointF(5, 5)); + points[0].setGlobalPosition(screenPos + QPointF(5, 5)); QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, QWindowSystemInterfacePrivate::toNativeTouchPoints(points, window)); QGuiApplication::processEvents(); @@ -2846,8 +2840,8 @@ void tst_qquickwindow::pointerEventTypeAndPointCount() QPointF screenPosition(333, 366); QMouseEvent me(QEvent::MouseButtonPress, localPosition, scenePosition, screenPosition, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); - QTouchEvent te(QEvent::TouchBegin, touchDevice, Qt::NoModifier, QEventPoint::State::Pressed, - QList<QEventPoint>() << QEventPoint(1)); + QMutableTouchEvent te(QEvent::TouchBegin, touchDevice, Qt::NoModifier, + QList<QEventPoint>() << QEventPoint(1)); QQuickPointerMouseEvent pme(nullptr, QPointingDevice::primaryPointingDevice()); @@ -2874,14 +2868,16 @@ void tst_qquickwindow::pointerEventTypeAndPointCount() QCOMPARE(pte.touchPointById(1)->id(), 1); QVERIFY(!pte.touchPointById(0)); - te.setTouchPoints(QList<QEventPoint>() << QEventPoint(1) << QEventPoint(2)); + te = QMutableTouchEvent(QEvent::TouchBegin, touchDevice, Qt::NoModifier, + QList<QEventPoint>() << QEventPoint(1) << QEventPoint(2)); pte.reset(&te); QCOMPARE(pte.pointCount(), 2); QCOMPARE(pte.touchPointById(1)->id(), 1); QCOMPARE(pte.touchPointById(2)->id(), 2); QVERIFY(!pte.touchPointById(0)); - te.setTouchPoints(QList<QEventPoint>() << QEventPoint(2)); + te = QMutableTouchEvent(QEvent::TouchBegin, touchDevice, Qt::NoModifier, + QList<QEventPoint>() << QEventPoint(2)); pte.reset(&te); QCOMPARE(pte.pointCount(), 1); QCOMPARE(pte.touchPointById(2)->id(), 2); |