From ec5f402cfd0bc439cd373ca8c99c59cb11556966 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Wed, 30 Jul 2014 08:24:49 +0200 Subject: [PATCH] QEasingCurve: The setting order of properties should not matter. Previously, this failed because QEasingCurveFunction only had a linear behavior. The fix is to change that and let QEasingCurveFunction handle any of the simple "non-parametric easing" functions. Task-number: QTBUG-38686 Change-Id: I666d59e10ceb589dcc52956b16a6f0c259aebdad Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira --- src/corelib/tools/qeasingcurve.cpp | 5 ++++- .../tools/qeasingcurve/tst_qeasingcurve.cpp | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 12adc5a433..91a726d785 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -373,9 +373,12 @@ public: }; +static QEasingCurve::EasingFunction curveToFunc(QEasingCurve::Type curve); + qreal QEasingCurveFunction::value(qreal t) { - return t; + QEasingCurve::EasingFunction func = curveToFunc(_t); + return func(t); } QEasingCurveFunction *QEasingCurveFunction::copy() const diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp index 3f46b92ec9..7311244ae7 100644 --- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp +++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp @@ -59,6 +59,7 @@ private slots: void operators(); void properties(); void metaTypes(); + void propertyOrderIsNotImportant(); void bezierSpline_data(); void bezierSpline(); void tcbSpline_data(); @@ -560,6 +561,25 @@ void tst_QEasingCurve::metaTypes() QVERIFY(qMetaTypeId() == QMetaType::QEasingCurve); } +/* + Test to ensure that regardless of what order properties are set, they should produce the same + behavior. + */ +void tst_QEasingCurve::propertyOrderIsNotImportant() +{ + + QEasingCurve c1; + c1.setPeriod(1); + c1.setType(QEasingCurve::OutSine); + QVERIFY(c1.valueForProgress(0.75) > 0.9); + + QEasingCurve c2; + c2.setType(QEasingCurve::OutSine); + c2.setPeriod(1); + + QCOMPARE(c1.valueForProgress(0.75), c2.valueForProgress(0.75)); +} + void tst_QEasingCurve::bezierSpline_data() { QTest::addColumn("definition");