aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-11-16 21:19:10 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2022-11-17 15:58:14 +0100
commit7ea85ac753091253be10a06f502f5c4de4eaa32d (patch)
tree1d7678fe397787c31752738b3144b3d1dafed880
parentde4c85be6a4d35d1518c673245eae6ffccf79c3d (diff)
Make tst_QQuickPinchHandler::scale easier to maintain
I kept forgetting why there were odd indented blocks, why it was letting the QTouchEventSequence go out of scope and making a new one, and why that resulted in an out-of-bounds pinch. It works well enough to just drag the second touchpoint all the way down into the lower-right corner: without maximumScale being set, it goes to 5.75, so we can verify that setting maximumScale limits it to 4. While we're at it: - use QQuickTest::showView() - better comments - loop instead of copy-pasting blocks of code - show the touchpoints - slow it down enough to see them when cat. logging is turned on - get rid of that weird opacity hack - check pinchHandler's own scale() and activeScale() properties Amends f289141524d9331bdafd9f88d95e0fa9b29ccdee Change-Id: I799c256286f4408f89c0502db33c9f676a2ce1b1 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit b0a3a07a68d64fb8f32969e1dc88923fd58c0adf) Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml30
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp131
2 files changed, 86 insertions, 75 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml
index 1cb80e32e6..3f1a2556cd 100644
--- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml
+++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml
@@ -10,6 +10,33 @@ Rectangle {
property int deactiveCount : 0
width: 320; height: 320
color: "white"
+
+ PointHandler {
+ id: ph1
+ acceptedDevices: PointerDevice.TouchScreen
+ target: Rectangle {
+ parent: whiteRect
+ color: "cyan"
+ x: ph1.point.position.x - 3
+ y: ph1.point.position.y - 3
+ width: 6; height: 6; radius: 3
+ }
+ }
+
+ PointHandler {
+ id: ph2
+ acceptedDevices: PointerDevice.TouchScreen
+ target: Rectangle {
+ parent: whiteRect
+ color: "lightgreen"
+ x: ph2.point.position.x - 3
+ y: ph2.point.position.y - 3
+ width: 6; height: 6; radius: 3
+ }
+ }
+
+ Text { color: "magenta"; z: 1; text: "scale: " + blackRect.scale}
+
Rectangle {
id: blackRect
objectName: "blackrect"
@@ -18,8 +45,7 @@ Rectangle {
x: 50
width: 100
height: 100
- opacity: (whiteRect.width-blackRect.x+whiteRect.height-blackRect.y-199)/200
- Text { color: "white"; text: "opacity: " + blackRect.opacity + "\nscale: " + blackRect.scale}
+
Rectangle {
color: "red"
width: 6; height: 6; radius: 3
diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
index 7945f270f4..5ffc49f802 100644
--- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
@@ -181,89 +181,74 @@ QEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i)
void tst_QQuickPinchHandler::scale()
{
- QQuickView *window = QQuickViewTestUtils::createView();
- QScopedPointer<QQuickView> scope(window);
- window->setSource(testFileUrl("pinchproperties.qml"));
- window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- QVERIFY(window->rootObject() != nullptr);
- qApp->processEvents();
-
- auto *pinchHandler = static_cast<PinchHandler *>(window->rootObject()->findChild<QQuickPinchHandler*>("pinchHandler"));
- QVERIFY(pinchHandler != nullptr);
- QSignalSpy grabChangedSpy(pinchHandler, SIGNAL(grabChanged(QPointingDevice::GrabTransition, QEventPoint)));
+ QQuickView window;
+ QVERIFY(QQuickTest::showView(window, testFileUrl("pinchproperties.qml")));
- QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject());
+ QQuickItem *root = qobject_cast<QQuickItem*>(window.rootObject());
QVERIFY(root != nullptr);
-
- // target
- QQuickItem *blackRect = window->rootObject()->findChild<QQuickItem*>("blackrect");
+ auto *pinchHandler = static_cast<PinchHandler *>(root->findChild<QQuickPinchHandler*>());
+ QVERIFY(pinchHandler != nullptr);
+ QQuickItem *blackRect = pinchHandler->target();
QVERIFY(blackRect != nullptr);
+ QSignalSpy grabChangedSpy(pinchHandler, SIGNAL(grabChanged(QPointingDevice::GrabTransition, QEventPoint)));
QPoint p0(80, 80);
QPoint p1(100, 100);
- {
- QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen);
- pinchSequence.press(0, p0, window).commit();
- QQuickTouchUtils::flush(window);
- // In order for the stationary point to remember its previous position,
- // we have to reuse the same pinchSequence object. Otherwise if we let it
- // be destroyed and then start a new sequence, point 0 will default to being
- // stationary at 0, 0, and pinchHandler will filter out that touchpoint because
- // it is outside its bounds.
- pinchSequence.stationary(0).press(1, p1, window).commit();
- QQuickTouchUtils::flush(window);
- QTRY_COMPARE(grabChangedSpy.count(), 1); // passive grab
-
- QPoint pd(10, 10);
- // move one point until PinchHandler activates
- for (int pi = 0; pi < 10 && !pinchHandler->active(); ++pi) {
- p1 += pd;
- pinchSequence.stationary(0).move(1, p1, window).commit();
- QQuickTouchUtils::flush(window);
- }
- QCOMPARE(pinchHandler->active(), true);
- // grabs occur when the handler becomes active; at that time, QQuickHandlerPoint.sceneGrabPosition should be correct
- QVERIFY(pinchHandler->firstPoint().sceneGrabPosition() != QPointF());
- QVERIFY(pinchHandler->lastPoint().sceneGrabPosition() != QPointF());
- QCOMPARE(pinchHandler->firstPoint().sceneGrabPosition(), pinchHandler->firstPoint().scenePosition());
- QCOMPARE(pinchHandler->lastPoint().sceneGrabPosition(), pinchHandler->lastPoint().scenePosition());
- // first point got a passive grab; both points got exclusive grabs
- QCOMPARE(grabChangedSpy.count(), 3);
- QLineF line(p0, p1);
- const qreal startLength = line.length();
-
- p1+=pd;
- pinchSequence.stationary(0).move(1, p1, window).commit();
- QQuickTouchUtils::flush(window);
- line.setP2(p1);
- qreal scale = line.length() / startLength;
- QVERIFY(qFloatDistance(root->property("pinchScale").toReal(), scale) < 10);
- QVERIFY(qFloatDistance(blackRect->scale(), scale) < 10);
-
- p1+=pd;
- pinchSequence.stationary(0).move(1, p1, window).commit();
- QQuickTouchUtils::flush(window);
+ QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(&window, touchscreen);
+ pinchSequence.press(0, p0, &window).commit();
+ QQuickTouchUtils::flush(&window);
+ // In order for the stationary point to remember its previous position,
+ // we have to reuse the same pinchSequence object. Otherwise if we let it
+ // be destroyed and then start a new sequence, point 0 will default to being
+ // stationary at 0, 0, and pinchHandler will filter out that touchpoint because
+ // it is outside its bounds.
+ pinchSequence.stationary(0).press(1, p1, &window).commit();
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(grabChangedSpy.size(), 1); // passive grab
+
+ QPoint pd(10, 10);
+ // move one point until PinchHandler activates
+ for (int pi = 0; pi < 10 && !pinchHandler->active(); ++pi) {
+ p1 += pd;
+ pinchSequence.stationary(0).move(1, p1, &window).commit();
+ QQuickTouchUtils::flush(&window);
+ }
+ QCOMPARE(pinchHandler->active(), true);
+ // grabs occur when the handler becomes active; at that time, QQuickHandlerPoint.sceneGrabPosition should be correct
+ QVERIFY(pinchHandler->firstPoint().sceneGrabPosition() != QPointF());
+ QVERIFY(pinchHandler->lastPoint().sceneGrabPosition() != QPointF());
+ QCOMPARE(pinchHandler->firstPoint().sceneGrabPosition(), pinchHandler->firstPoint().scenePosition());
+ QCOMPARE(pinchHandler->lastPoint().sceneGrabPosition(), pinchHandler->lastPoint().scenePosition());
+ // first point got a passive grab; both points got exclusive grabs
+ QCOMPARE(grabChangedSpy.size(), 3);
+ QLineF line(p0, p1);
+ const qreal startLength = line.length();
+
+ // move the same point even further and observe the change in scale
+ for (int i = 0; i < 2; ++i) {
+ p1 += pd;
+ pinchSequence.stationary(0).move(1, p1, &window).commit();
+ QQuickTouchUtils::flush(&window);
+ if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
line.setP2(p1);
- scale = line.length() / startLength;
-
- QVERIFY(qFloatDistance(root->property("pinchScale").toReal(), scale) < 10);
- QVERIFY(qFloatDistance(blackRect->scale(), scale) < 10);
-
- QPointF expectedCentroid = p0 + (p1 - p0)/2;
+ qreal expectedScale = line.length() / startLength;
+ QVERIFY(qFloatDistance(root->property("pinchScale").toReal(), expectedScale) < 10);
+ QVERIFY(qFloatDistance(blackRect->scale(), expectedScale) < 10);
+ QCOMPARE(pinchHandler->scale(), root->property("pinchScale").toReal());
+ QCOMPARE(pinchHandler->scale(), pinchHandler->activeScale()); // in sync for the first gesture
+ QPointF expectedCentroid = p0 + (p1 - p0) / 2;
QCOMPARE(pinchHandler->centroid().scenePosition(), expectedCentroid);
}
- // scale beyond bound
- p1 += QPoint(20, 20);
- {
- QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen);
- pinchSequence.stationary(0).move(1, p1, window).commit();
- QQuickTouchUtils::flush(window);
- QCOMPARE(blackRect->scale(), qreal(4)); // qquickpinchhandler does not manipulate scale property
- pinchSequence.release(0, p0, window).release(1, p1, window).commit();
- QQuickTouchUtils::flush(window);
- }
+ // scale beyond maximumScale
+ p1 = QPoint(310, 310);
+ pinchSequence.stationary(0).move(1, p1, &window).commit();
+ QQuickTouchUtils::flush(&window);
+ if (lcPointerTests().isDebugEnabled()) QTest::qWait(500);
+ QCOMPARE(blackRect->scale(), qreal(4));
+ QCOMPARE(pinchHandler->scale(), qreal(4)); // limited by maximumScale
+ pinchSequence.release(0, p0, &window).release(1, p1, &window).commit();
+ QQuickTouchUtils::flush(&window);
QCOMPARE(pinchHandler->active(), false);
}