diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-03-27 16:06:11 +0000 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-07-10 14:32:56 +0200 |
commit | 4e400369c08db251cd489fec1229398c224d02b4 (patch) | |
tree | 6279489dce7b0469d590461798deccf5d1193e29 /tests/auto/widgets/graphicsview | |
parent | 773a6bffd78b363577d27604e17f4ee08ff07e77 (diff) |
Refactor pointer event hierarchy
Some goals that have hopefully been achieved are:
- make QPointerEvent and QEventPoint resemble their Qt Quick
counterparts to such an extent that we can remove those wrappers
and go back to delivering the original events in Qt Quick
- make QEventPoint much smaller than QTouchEvent::TouchPoint, with no pimpl
- remove most public setters
- reduce the usage of complex constructors that take many arguments
- don't repeat ourselves: move accessors and storage upwards
rather than having redundant ones in subclasses
- standardize the set of accessors in QPointerEvent
- maintain source compatibility as much as possible: do not require
modifying event-handling code in any QWidget subclass
To avoid public setters we now introduce a few QMutable* subclasses.
This is a bit like the Builder pattern except that it doesn't involve
constructing a separate disposable object: the main event type can be
cast to the mutable type at any time to enable modifications, iff the
code is linked with gui-private. Therefore event classes can have
less-"complete" constructors, because internal Qt code can use setters
the same way it could use the ones in QTouchEvent before; and the event
classes don't need many friends. Even some read-accessors can be kept
private unless we are sure we want to expose them.
Task-number: QTBUG-46266
Fixes: QTBUG-72173
Change-Id: I740e4e40165b7bc41223d38b200bbc2b403e07b6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/widgets/graphicsview')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 65 | ||||
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 15 |
2 files changed, 35 insertions, 45 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 1bd5b160ea..1c311a27ea 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -33,6 +33,7 @@ #include <private/qgraphicsitem_p.h> #include <private/qgraphicsview_p.h> #include <private/qgraphicsscene_p.h> +#include <private/qinputdevice_p.h> #include <QRandomGenerator> #include <QStyleOptionGraphicsItem> #include <QAbstractTextDocumentLayout> @@ -490,7 +491,7 @@ private slots: private: GraphicsItems paintedItems; - QPointingDevice *m_touchDevice = nullptr; + QPointingDevice *m_touchDevice = QTest::createTouchDevice(); }; void tst_QGraphicsItem::initMain() @@ -10980,7 +10981,7 @@ void tst_QGraphicsItem::focusHandling() class TouchEventTestee : public QGraphicsRectItem { public: - using TouchPoints = QList<QTouchEvent::TouchPoint>; + using TouchPoints = QList<QEventPoint>; TouchEventTestee(const QSizeF &size = QSizeF(100, 100)) : QGraphicsRectItem(QRectF(QPointF(), size)) @@ -11019,25 +11020,21 @@ private: TouchPoints m_touchUpdatePoints; }; -static QList<QTouchEvent::TouchPoint> +static QList<QEventPoint> createTouchPoints(const QGraphicsView &view, const QPointF &scenePos, const QSizeF &ellipseDiameters, - Qt::TouchPointState state = Qt::TouchPointPressed) + QEventPoint::State state = QEventPoint::State::Pressed) { - QTouchEvent::TouchPoint tp(0); - tp.setState(state); - tp.setScenePos(scenePos); - tp.setStartScenePos(scenePos); - tp.setLastScenePos(scenePos); const QPointF screenPos = view.viewport()->mapToGlobal(view.mapFromScene(scenePos)); - tp.setScreenPos(screenPos); - tp.setStartScreenPos(screenPos); - tp.setLastScreenPos(screenPos); + QMutableEventPoint tp(0, state, scenePos, screenPos); + tp.setState(state); + tp.setScenePosition(scenePos); + tp.setGlobalPosition(screenPos); + tp.setGlobalPressPosition(screenPos); + tp.setGlobalLastPosition(screenPos); tp.setEllipseDiameters(ellipseDiameters); - const QSizeF screenSize = view.screen()->geometry().size(); - tp.setNormalizedPos(QPointF(screenPos.x() / screenSize.width(), screenPos.y() / screenSize.height())); - return QList<QTouchEvent::TouchPoint>() << tp; + return QList<QEventPoint>() << tp; } static bool comparePointF(const QPointF &p1, const QPointF &p2) @@ -11104,15 +11101,14 @@ void tst_QGraphicsItem::touchEventPropagation() view.setSceneRect(touchEventReceiver->boundingRect()); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + QInputDevicePrivate::get(m_touchDevice)->setAvailableVirtualGeometry(view.screen()->geometry()); QCOMPARE(touchEventReceiver->touchBeginEventCount(), 0); const QPointF scenePos = view.sceneRect().center(); sendMousePress(&scene, scenePos); - if (m_touchDevice == nullptr) - m_touchDevice = QTest::createTouchDevice(); - QTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, Qt::TouchPointPressed, - createTouchPoints(view, scenePos, QSizeF(10, 10))); + QMutableTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, + createTouchPoints(view, scenePos, QSizeF(10, 10))); touchBegin.setTarget(view.viewport()); qApp->sendEvent(&scene, &touchBegin); @@ -11165,39 +11161,36 @@ void tst_QGraphicsItem::touchEventTransformation() view.setTransform(viewTransform); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + QInputDevicePrivate::get(m_touchDevice)->setAvailableVirtualGeometry(view.screen()->geometry()); QCOMPARE(touchEventReceiver->touchBeginEventCount(), 0); - if (m_touchDevice == nullptr) - m_touchDevice = QTest::createTouchDevice(); - QTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, Qt::TouchPointPressed, - createTouchPoints(view, touchScenePos, ellipseDiameters)); + QMutableTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, + createTouchPoints(view, touchScenePos, ellipseDiameters)); touchBegin.setTarget(view.viewport()); - QCoreApplication::sendEvent(&scene, &touchBegin); QCOMPARE(touchEventReceiver->touchBeginEventCount(), 1); - const QTouchEvent::TouchPoint touchBeginPoint = touchEventReceiver->touchBeginPoints().constFirst(); + const QEventPoint touchBeginPoint = touchEventReceiver->touchBeginPoints().constFirst(); - COMPARE_POINTF(touchBeginPoint.scenePos(), touchScenePos); - COMPARE_POINTF(touchBeginPoint.startScenePos(), touchScenePos); - COMPARE_POINTF(touchBeginPoint.lastScenePos(), touchScenePos); - COMPARE_POINTF(touchBeginPoint.pos(), expectedItemPos); + COMPARE_POINTF(touchBeginPoint.scenePosition(), touchScenePos); + COMPARE_POINTF(touchBeginPoint.scenePressPosition(), touchScenePos); + COMPARE_POINTF(touchBeginPoint.sceneLastPosition(), touchScenePos); + COMPARE_POINTF(touchBeginPoint.position(), expectedItemPos); COMPARE_SIZEF(touchBeginPoint.ellipseDiameters(), ellipseDiameters); // Must remain untransformed - QTouchEvent touchUpdate(QEvent::TouchUpdate, m_touchDevice, Qt::NoModifier, Qt::TouchPointMoved, - createTouchPoints(view, touchScenePos, ellipseDiameters, Qt::TouchPointMoved)); + QMutableTouchEvent touchUpdate(QEvent::TouchUpdate, m_touchDevice, Qt::NoModifier, + createTouchPoints(view, touchScenePos, ellipseDiameters, QEventPoint::State::Updated)); touchUpdate.setTarget(view.viewport()); QCoreApplication::sendEvent(&scene, &touchUpdate); QCOMPARE(touchEventReceiver->touchUpdateEventCount(), 1); - const QTouchEvent::TouchPoint touchUpdatePoint = touchEventReceiver->touchUpdatePoints().constFirst(); + const QEventPoint touchUpdatePoint = touchEventReceiver->touchUpdatePoints().constFirst(); - COMPARE_POINTF(touchUpdatePoint.scenePos(), touchScenePos); - COMPARE_POINTF(touchBeginPoint.startScenePos(), touchScenePos); - COMPARE_POINTF(touchUpdatePoint.lastScenePos(), touchScenePos); - COMPARE_POINTF(touchUpdatePoint.pos(), expectedItemPos); + COMPARE_POINTF(touchUpdatePoint.scenePosition(), touchScenePos); + COMPARE_POINTF(touchBeginPoint.scenePressPosition(), touchScenePos); + COMPARE_POINTF(touchUpdatePoint.position(), expectedItemPos); COMPARE_SIZEF(touchUpdatePoint.ellipseDiameters(), ellipseDiameters); // Must remain untransformed } diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 8387d6f1dd..3365ccd179 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -4840,15 +4840,12 @@ void tst_QGraphicsScene::focusOnTouch() scene.setFocusOnTouch(false); - QPointingDevice device; - device.setType(QInputDevice::DeviceType::TouchPad); - QList<QTouchEvent::TouchPoint> touchPoints; - QTouchEvent::TouchPoint point; - point.setScenePos(QPointF(10, 10)); - point.setState(Qt::TouchPointPressed); - touchPoints.append(point); - QTouchEvent event(QEvent::TouchBegin, &device, Qt::NoModifier, Qt::TouchPointStates(), - touchPoints); + QPointingDevice device("fake touchpad", 4321, QInputDevice::DeviceType::TouchPad, + QPointingDevice::PointerType::Finger, QInputDevice::Capability::Position, 1, 3); + + auto touchPoints = QList<QEventPoint>() << + QEventPoint(0, QEventPoint::State::Pressed, {10, 10}, {}); + QTouchEvent event(QEvent::TouchBegin, &device, Qt::NoModifier, touchPoints); QApplication::sendEvent(&scene, &event); |