diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2022-12-13 15:36:27 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2022-12-16 23:07:34 +0100 |
commit | 69a0c6f3c1f3edb09e05c32a32f0aaa1bd3ddcf2 (patch) | |
tree | 05743d1e1faebfd209098c8d9b973121963d90f8 | |
parent | 9124fcecb4e33d33bcd6c4d678d746bc673ea46c (diff) |
Stop using deprecated QQuickPinchHandler functions and signals
Amends a432970b258edb9ff041d221b2155df30cad4799.
Task-number: QTBUG-109392
Pick-to: 6.5
Change-Id: I394f2c4b3dc430bbaa2cb55081b6047160ea291b
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
-rw-r--r-- | src/quick/handlers/qquickpinchhandler.cpp | 3 | ||||
-rw-r--r-- | tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp | 114 |
2 files changed, 62 insertions, 55 deletions
diff --git a/src/quick/handlers/qquickpinchhandler.cpp b/src/quick/handlers/qquickpinchhandler.cpp index 696d5c9a76..94b64c357d 100644 --- a/src/quick/handlers/qquickpinchhandler.cpp +++ b/src/quick/handlers/qquickpinchhandler.cpp @@ -720,7 +720,8 @@ void QQuickPinchHandler::handlePointerEventImpl(QPointerEvent *event) << ", distance" << m_startDistance << "->" << dist << ", scale" << m_scaleAxis.m_startValue << "->" << m_scaleAxis.m_accumulatedValue << ", rotation" << m_rotationAxis.m_startValue << "->" << m_rotationAxis.m_accumulatedValue - << ", translation" << translation() << " from " << event->device()->type(); + << ", translation" << persistentTranslation() + << " from " << event->device()->type(); emit updated(); } diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp index 973a4eab5f..b4a87e9e83 100644 --- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp @@ -132,64 +132,70 @@ void tst_QQuickPinchHandler::pinchProperties() QCOMPARE(ymaxSpy.count(),1); // minimum and maximum scale properties - QSignalSpy scaleMinSpy(pinchHandler, SIGNAL(minimumScaleChanged())); - QSignalSpy scaleMaxSpy(pinchHandler, SIGNAL(maximumScaleChanged())); QSignalSpy scaleAxisMinSpy(pinchHandler->scaleAxis(), &QQuickDragAxis::minimumChanged); QSignalSpy scaleAxisMaxSpy(pinchHandler->scaleAxis(), &QQuickDragAxis::maximumChanged); - QCOMPARE(pinchHandler->minimumScale(), 0.5); QCOMPARE(pinchHandler->scaleAxis()->minimum(), 0.5); - QCOMPARE(pinchHandler->maximumScale(), 4); QCOMPARE(pinchHandler->scaleAxis()->maximum(), 4); - pinchHandler->setMinimumScale(0.25); - pinchHandler->setMaximumScale(1.5); +#if QT_DEPRECATED_SINCE(6, 5) +QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED + QCOMPARE(pinchHandler->minimumScale(), 0.5); + QCOMPARE(pinchHandler->maximumScale(), 4); +QT_WARNING_POP +#endif + + pinchHandler->scaleAxis()->setMinimum(0.25); + pinchHandler->scaleAxis()->setMaximum(1.5); - QCOMPARE(pinchHandler->minimumScale(), 0.25); QCOMPARE(pinchHandler->scaleAxis()->minimum(), 0.25); - QCOMPARE(pinchHandler->maximumScale(), 1.5); QCOMPARE(pinchHandler->scaleAxis()->maximum(), 1.5); - QCOMPARE(scaleMinSpy.size(),1); - QCOMPARE(scaleMaxSpy.size(),1); +#if QT_DEPRECATED_SINCE(6, 5) +QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED + QCOMPARE(pinchHandler->minimumScale(), 0.25); + QCOMPARE(pinchHandler->maximumScale(), 1.5); +QT_WARNING_POP +#endif + QCOMPARE(scaleAxisMinSpy.size(),1); QCOMPARE(scaleAxisMaxSpy.size(),1); - pinchHandler->setMinimumScale(0.25); - pinchHandler->setMaximumScale(1.5); + pinchHandler->scaleAxis()->setMinimum(0.25); + pinchHandler->scaleAxis()->setMaximum(1.5); - QCOMPARE(scaleMinSpy.size(),1); - QCOMPARE(scaleMaxSpy.size(),1); QCOMPARE(scaleAxisMinSpy.size(),1); QCOMPARE(scaleAxisMaxSpy.size(),1); // minimum and maximum rotation properties - QSignalSpy rotMinSpy(pinchHandler, SIGNAL(minimumRotationChanged())); - QSignalSpy rotMaxSpy(pinchHandler, SIGNAL(maximumRotationChanged())); QSignalSpy rotAxisMinSpy(pinchHandler->rotationAxis(), &QQuickDragAxis::minimumChanged); QSignalSpy rotAxisMaxSpy(pinchHandler->rotationAxis(), &QQuickDragAxis::maximumChanged); +#if QT_DEPRECATED_SINCE(6, 5) +QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED QCOMPARE(pinchHandler->minimumRotation(), 0); - QCOMPARE(pinchHandler->rotationAxis()->minimum(), 0); QCOMPARE(pinchHandler->maximumRotation(), 90); +QT_WARNING_POP +#endif + QCOMPARE(pinchHandler->rotationAxis()->minimum(), 0); QCOMPARE(pinchHandler->rotationAxis()->maximum(), 90); - pinchHandler->setMinimumRotation(-90); - pinchHandler->setMaximumRotation(45); + pinchHandler->rotationAxis()->setMinimum(-90); + pinchHandler->rotationAxis()->setMaximum(45); +#if QT_DEPRECATED_SINCE(6, 5) +QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED QCOMPARE(pinchHandler->minimumRotation(), -90); QCOMPARE(pinchHandler->maximumRotation(), 45); +QT_WARNING_POP +#endif - QCOMPARE(rotMinSpy.size(),1); - QCOMPARE(rotMaxSpy.size(),1); QCOMPARE(rotAxisMinSpy.size(),1); QCOMPARE(rotAxisMaxSpy.size(),1); - pinchHandler->setMinimumRotation(-90); - pinchHandler->setMaximumRotation(45); + pinchHandler->rotationAxis()->setMinimum(-90); + pinchHandler->rotationAxis()->setMaximum(45); - QCOMPARE(rotMinSpy.size(),1); - QCOMPARE(rotMaxSpy.size(),1); QCOMPARE(rotAxisMinSpy.size(),1); QCOMPARE(rotAxisMaxSpy.size(),1); } @@ -277,8 +283,8 @@ void tst_QQuickPinchHandler::scale() << "multiplier" << scaleChangedSpy.last().first().toReal(); 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 + QCOMPARE(pinchHandler->persistentScale(), root->property("pinchScale").toReal()); + QCOMPARE(pinchHandler->persistentScale(), pinchHandler->activeScale()); // in sync for the first gesture QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), pinchHandler->activeScale()); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), pinchHandler->activeScale()); const qreal expectedIncrement = pinchHandler->activeScale() / lastScale; @@ -288,12 +294,12 @@ void tst_QQuickPinchHandler::scale() QCOMPARE(pinchHandler->centroid().scenePosition(), expectedCentroid); } - qreal lastScale = pinchHandler->scale(); + qreal lastScale = pinchHandler->persistentScale(); pinchSequence.release(0, p0, &window).release(1, p1, &window).commit(); QQuickTouchUtils::flush(&window); if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); // scale property is persistent after release - QCOMPARE(pinchHandler->scale(), lastScale); + QCOMPARE(pinchHandler->persistentScale(), lastScale); QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), lastScale); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1); @@ -309,28 +315,28 @@ void tst_QQuickPinchHandler::scale() } if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); QCOMPARE(pinchHandler->active(), true); - QCOMPARE(pinchHandler->scale(), lastScale); // just activated, not scaling further yet + QCOMPARE(pinchHandler->persistentScale(), lastScale); // just activated, not scaling further yet QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), lastScale); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1); for (int i = 0; i < 2; ++i) { - lastScale = pinchHandler->scale(); + lastScale = pinchHandler->persistentScale(); p1 += pd; pinchSequence.stationary(0).move(1, p1, &window).commit(); QQuickTouchUtils::flush(&window); if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); - QCOMPARE_GT(pinchHandler->scale(), lastScale); + QCOMPARE_GT(pinchHandler->persistentScale(), lastScale); line.setP2(p1); qreal expectedActiveScale = line.length() / startLength; qCDebug(lcPointerTests) << i << "activeScale" << pinchHandler->activeScale() - << "expected" << expectedActiveScale << "; scale" << pinchHandler->scale() + << "expected" << expectedActiveScale << "; scale" << pinchHandler->persistentScale() << "increments" << scaleChangedSpy.size() << "multiplier" << scaleChangedSpy.last().first().toReal(); QVERIFY(qFloatDistance(pinchHandler->activeScale(), expectedActiveScale) < 10); - QCOMPARE(pinchHandler->scale(), root->property("pinchScale").toReal()); + QCOMPARE(pinchHandler->persistentScale(), root->property("pinchScale").toReal()); QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), root->property("pinchScale").toReal()); - QCOMPARE_NE(pinchHandler->scale(), pinchHandler->activeScale()); // not in sync anymore + QCOMPARE_NE(pinchHandler->persistentScale(), pinchHandler->activeScale()); // not in sync anymore QCOMPARE(pinchHandler->scaleAxis()->activeValue(), pinchHandler->activeScale()); - const qreal expectedIncrement = pinchHandler->scale() / lastScale; + const qreal expectedIncrement = pinchHandler->persistentScale() / lastScale; QCOMPARE(scaleChangedSpy.size(), i + 3); QCOMPARE(scaleChangedSpy.last().first().toReal(), expectedIncrement); } @@ -342,7 +348,7 @@ void tst_QQuickPinchHandler::scale() QQuickTouchUtils::flush(&window); if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); QCOMPARE(blackRect->scale(), qreal(4)); - QCOMPARE(pinchHandler->scale(), qreal(4)); // limited by maximumScale + QCOMPARE(pinchHandler->persistentScale(), qreal(4)); // limited by maximumScale QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), 4); const qreal expectedIncrement = pinchHandler->activeScale() / lastScale; QCOMPARE(scaleChangedSpy.size(), 5); @@ -399,16 +405,16 @@ void tst_QQuickPinchHandler::scaleThreeFingers() QCOMPARE(pinchHandler->active(), true); // scale we got was 1.1729088738267854364, but keep some slack - qCDebug(lcPointerTests) << "pinch scale" << pinchHandler->scale() << "expected 1.173"; - QVERIFY(withinBounds(1.163, pinchHandler->scale(), 1.183)); + qCDebug(lcPointerTests) << "pinch scale" << pinchHandler->persistentScale() << "expected 1.173"; + QVERIFY(withinBounds(1.163, pinchHandler->persistentScale(), 1.183)); // should not rotate QCOMPARE(root->rotation(), 0); // rotation should be 0, but could be something tiny - qCDebug(lcPointerTests) << "pinch scale expected zero:" << pinchHandler->rotation() + qCDebug(lcPointerTests) << "pinch scale expected zero:" << pinchHandler->activeRotation() << pinchHandler->rotationAxis()->activeValue() << pinchHandler->rotationAxis()->persistentValue(); - QCOMPARE_LE(qAbs(pinchHandler->rotation()), 0.001); - QCOMPARE(pinchHandler->rotationAxis()->activeValue(), pinchHandler->rotation()); + QCOMPARE_LE(qAbs(pinchHandler->activeRotation()), 0.001); + QCOMPARE(pinchHandler->rotationAxis()->activeValue(), pinchHandler->activeRotation()); QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0); for (int i = 0; i < 5;++i) { @@ -419,7 +425,7 @@ void tst_QQuickPinchHandler::scaleThreeFingers() QQuickTouchUtils::flush(window); } // scale we got was 1.4613, but keep some slack - QVERIFY(withinBounds(1.361, pinchHandler->scale(), 1.561)); + QVERIFY(withinBounds(1.361, pinchHandler->persistentScale(), 1.561)); // since points were moved symetrically around the y axis, centroid should remain at x:150 QCOMPARE(pinchHandler->centroid().scenePosition().x(), 150); // blackrect is at 50,50 @@ -431,7 +437,7 @@ void tst_QQuickPinchHandler::scaleThreeFingers() pinchSequence.move(0, p0,window).move(1, p1,window).move(2, p2,window).commit(); QQuickTouchUtils::flush(window); - QCOMPARE(pinchHandler->scale(), 2); + QCOMPARE(pinchHandler->persistentScale(), 2); QCOMPARE(pinchHandler->scaleAxis()->persistentValue(), 2); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 2); pinchSequence.release(0, p0, window).release(1, p1, window).release(2, p2, window).commit(); @@ -492,29 +498,29 @@ void tst_QQuickPinchHandler::scaleNativeGesture() QCOMPARE(pinchHandler->centroid().scenePosition().toPoint(), pinchPos.toPoint()); QVERIFY(qAbs(target->position().x() - expectedPos.x()) < 0.001); QVERIFY(qAbs(target->position().y() - expectedPos.y()) < 0.001); - QCOMPARE(pinchHandler->scale(), expectedScale); + QCOMPARE(pinchHandler->persistentScale(), expectedScale); QCOMPARE(pinchHandler->activeScale(), scale); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), scale); - QCOMPARE(pinchHandler->translation(), QVector2D()); - QCOMPARE(pinchHandler->rotation(), 0); + QCOMPARE(pinchHandler->activeTranslation(), QPointF()); + QCOMPARE(pinchHandler->activeRotation(), 0); QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0); QCOMPARE(pinchHandler->rotationAxis()->activeValue(), 0); QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad, Qt::EndNativeGesture, pinchPos, pinchPos); QTRY_COMPARE(pinchHandler->active(), false); QCOMPARE(target->scale(), expectedScale); - QCOMPARE(pinchHandler->scale(), expectedScale); + QCOMPARE(pinchHandler->persistentScale(), expectedScale); QCOMPARE(pinchHandler->activeScale(), 1); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1); - QCOMPARE(pinchHandler->translation(), QVector2D()); - QCOMPARE(pinchHandler->rotation(), 0); + QCOMPARE(pinchHandler->activeTranslation(), QPointF()); + QCOMPARE(pinchHandler->activeRotation(), 0); QCOMPARE(pinchHandler->rotationAxis()->persistentValue(), 0); QCOMPARE(pinchHandler->rotationAxis()->activeValue(), 0); // second pinch at a different position: scale it back to original size again // but remove the limits first, so that we can scale arbitrarily - pinchHandler->setMaximumScale(qInf()); - pinchHandler->setMinimumScale(-qInf()); + pinchHandler->scaleAxis()->setMaximum(qInf()); + pinchHandler->scaleAxis()->setMinimum(-qInf()); const qreal reverseScale = (1 / expectedScale); pinchPos = QPointF(110, 110); pinchLocalPos = target->mapFromScene(pinchPos); @@ -526,14 +532,14 @@ void tst_QQuickPinchHandler::scaleNativeGesture() QCOMPARE(pinchHandler->active(), true); QCOMPARE(pinchHandler->centroid().position().toPoint(), pinchLocalPos.toPoint()); QCOMPARE(pinchHandler->centroid().scenePosition().toPoint(), pinchPos.toPoint()); - QCOMPARE(pinchHandler->scale(), 1); + QCOMPARE(pinchHandler->persistentScale(), 1); QCOMPARE(pinchHandler->activeScale(), reverseScale); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), reverseScale); QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad, Qt::EndNativeGesture, pinchPos, pinchPos); QTRY_COMPARE(pinchHandler->active(), false); QCOMPARE(target->scale(), 1); - QCOMPARE(pinchHandler->scale(), 1); + QCOMPARE(pinchHandler->persistentScale(), 1); QCOMPARE(pinchHandler->activeScale(), 1); QCOMPARE(pinchHandler->scaleAxis()->activeValue(), 1); } |