diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-06-26 01:10:56 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-06-26 01:10:56 (GMT) |
commit | 662488175fb9c6a44e9641867177b5396c507891 (patch) | |
tree | 554411c26dd635e327198b212d1f6648fec57316 | |
parent | baff8c7e3bba56c3d9c53300ed4524c4b3546c15 (diff) | |
download | Qt-662488175fb9c6a44e9641867177b5396c507891.zip Qt-662488175fb9c6a44e9641867177b5396c507891.tar.gz Qt-662488175fb9c6a44e9641867177b5396c507891.tar.bz2 |
Fix animation bugs, and add autotest.
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 13 | ||||
-rw-r--r-- | tests/auto/declarative/animations/animations.pro | 5 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/badtype1.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/badtype2.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/badtype3.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/badtype4.qml | 23 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/color.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/mixedtype1.qml | 22 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/mixedtype2.qml | 22 | ||||
-rw-r--r-- | tests/auto/declarative/animations/data/number.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative/animations/tst_animations.cpp | 82 |
11 files changed, 212 insertions, 5 deletions
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index e42672d..42ed40b 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -1439,7 +1439,10 @@ QVariant QmlPropertyAnimationPrivate::interpolateVariant(const QVariant &from, c return QVariant(); QVariantAnimation::Interpolator interpolator = QVariantAnimationPrivate::getInterpolator(from.userType()); - return interpolator(from.constData(), to.constData(), progress); + if (interpolator) + return interpolator(from.constData(), to.constData(), progress); + else + return QVariant(); } //convert a variant from string type to another animatable type @@ -1851,8 +1854,8 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, if (d->toIsDefined) myAction.toValue = d->to; - d->convertVariant(myAction.fromValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); - d->convertVariant(myAction.toValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); + d->convertVariant(myAction.fromValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType())); + d->convertVariant(myAction.toValue, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType())); modified << action.property; @@ -1868,10 +1871,10 @@ void QmlPropertyAnimation::transition(QmlStateActions &actions, myAction.property = QmlMetaProperty(obj, props.at(jj)); if (d->fromIsDefined) { - d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); + d->convertVariant(d->from, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType())); myAction.fromValue = d->from; } - d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : d->property.propertyType())); + d->convertVariant(d->to, (QVariant::Type)(d->interpolatorType ? d->interpolatorType : myAction.property.propertyType())); myAction.toValue = d->to; myAction.bv = 0; myAction.event = 0; diff --git a/tests/auto/declarative/animations/animations.pro b/tests/auto/declarative/animations/animations.pro new file mode 100644 index 0000000..419da4e --- /dev/null +++ b/tests/auto/declarative/animations/animations.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_animations.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/animations/data/badtype1.qml b/tests/auto/declarative/animations/data/badtype1.qml new file mode 100644 index 0000000..691d2b3 --- /dev/null +++ b/tests/auto/declarative/animations/data/badtype1.qml @@ -0,0 +1,10 @@ +Rect { + width: 240 + height: 320 + Rect { + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: PropertyAnimation { from: "blue"; to: "green"; running: true; } + } +} diff --git a/tests/auto/declarative/animations/data/badtype2.qml b/tests/auto/declarative/animations/data/badtype2.qml new file mode 100644 index 0000000..18d9079 --- /dev/null +++ b/tests/auto/declarative/animations/data/badtype2.qml @@ -0,0 +1,10 @@ +Rect { + width: 240 + height: 320 + Rect { + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: NumericAnimation { from: "blue"; to: "green"; running: true; } + } +} diff --git a/tests/auto/declarative/animations/data/badtype3.qml b/tests/auto/declarative/animations/data/badtype3.qml new file mode 100644 index 0000000..f1a89b6 --- /dev/null +++ b/tests/auto/declarative/animations/data/badtype3.qml @@ -0,0 +1,10 @@ +Rect { + width: 240 + height: 320 + Rect { + color: "red" + color: ColorAnimation { from: 10; to: 15; running: true; } + width: 50; height: 50 + x: 100; y: 100 + } +} diff --git a/tests/auto/declarative/animations/data/badtype4.qml b/tests/auto/declarative/animations/data/badtype4.qml new file mode 100644 index 0000000..e3d312e --- /dev/null +++ b/tests/auto/declarative/animations/data/badtype4.qml @@ -0,0 +1,23 @@ +Rect { + id: Wrapper + width: 240 + height: 320 + Rect { + id: MyRect + color: "red" + width: 50; height: 50 + x: 100; y: 100 + MouseRegion { + anchors.fill: parent + onClicked: if (Wrapper.state == "state1") Wrapper.state = ""; else Wrapper.state = "state1"; + } + } + states: State { + name: "state1" + SetProperties { target: MyRect; x: 200; color: "blue" } + } + transitions: Transition { + ColorAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color + //NumericAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color + } +} diff --git a/tests/auto/declarative/animations/data/color.qml b/tests/auto/declarative/animations/data/color.qml new file mode 100644 index 0000000..051e0e1 --- /dev/null +++ b/tests/auto/declarative/animations/data/color.qml @@ -0,0 +1,10 @@ +Rect { + width: 240 + height: 320 + Rect { + color: "red" + color: PropertyAnimation { to: "green"; running: true } + width: 50; height: 50 + x: 100; y: 100 + } +} diff --git a/tests/auto/declarative/animations/data/mixedtype1.qml b/tests/auto/declarative/animations/data/mixedtype1.qml new file mode 100644 index 0000000..415bbfb --- /dev/null +++ b/tests/auto/declarative/animations/data/mixedtype1.qml @@ -0,0 +1,22 @@ +Rect { + id: Wrapper + width: 240 + height: 320 + Rect { + id: MyRect + color: "red" + width: 50; height: 50 + x: 100; y: 100 + MouseRegion { + anchors.fill: parent + onClicked: if (Wrapper.state == "state1") Wrapper.state = ""; else Wrapper.state = "state1"; + } + } + states: State { + name: "state1" + SetProperties { target: MyRect; x: 200; width: 40 } + } + transitions: Transition { + PropertyAnimation { properties: "x,width"; duration: 1000 } //x is real, width is int + } +} diff --git a/tests/auto/declarative/animations/data/mixedtype2.qml b/tests/auto/declarative/animations/data/mixedtype2.qml new file mode 100644 index 0000000..0e9fb8d --- /dev/null +++ b/tests/auto/declarative/animations/data/mixedtype2.qml @@ -0,0 +1,22 @@ +Rect { + id: Wrapper + width: 240 + height: 320 + Rect { + id: MyRect + color: "red" + width: 50; height: 50 + x: 100; y: 100 + MouseRegion { + anchors.fill: parent + onClicked: if (Wrapper.state == "state1") Wrapper.state = ""; else Wrapper.state = "state1"; + } + } + states: State { + name: "state1" + SetProperties { target: MyRect; x: 200; color: "blue" } + } + transitions: Transition { + PropertyAnimation { properties: "x,color"; duration: 1000 } //x is real, color is color + } +} diff --git a/tests/auto/declarative/animations/data/number.qml b/tests/auto/declarative/animations/data/number.qml new file mode 100644 index 0000000..feb551b --- /dev/null +++ b/tests/auto/declarative/animations/data/number.qml @@ -0,0 +1,10 @@ +Rect { + width: 240 + height: 320 + Rect { + color: "red" + width: 50; height: 50 + x: 100; y: 100 + x: PropertyAnimation { from: 0; to: 200; duration: 1000; running: true } + } +} diff --git a/tests/auto/declarative/animations/tst_animations.cpp b/tests/auto/declarative/animations/tst_animations.cpp new file mode 100644 index 0000000..1895cef2 --- /dev/null +++ b/tests/auto/declarative/animations/tst_animations.cpp @@ -0,0 +1,82 @@ +#include <qtest.h> +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qfxview.h> +#include <QtDeclarative/qfxrect.h> + +class tst_animations : public QObject +{ + Q_OBJECT +public: + tst_animations() {} + +private slots: + void badTypes(); + //void mixedTypes(); +}; + +void tst_animations::badTypes() +{ + //don't crash + { + QFxView *view = new QFxView; + view->setUrl(QUrl("file://" SRCDIR "/data/badtype1.qml")); + + view->execute(); + qApp->processEvents(); + + delete view; + } + + //make sure we get a compiler error + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badtype2.qml")); + QTest::ignoreMessage(QtWarningMsg, "QmlComponent: Component is not ready"); + c.create(); + + QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().at(0).description(), QLatin1String("Cannot convert value \"blue\" to double number")); + } + + //make sure we get a compiler error + { + QmlEngine engine; + QmlComponent c(&engine, QUrl("file://" SRCDIR "/data/badtype3.qml")); + QTest::ignoreMessage(QtWarningMsg, "QmlComponent: Component is not ready"); + c.create(); + + QVERIFY(c.errors().count() == 1); + QCOMPARE(c.errors().at(0).description(), QLatin1String("Cannot convert value \"10\" to color")); + } +} + +/*//test animating mixed types with property animation + //for example, int + real; color + real; etc +void tst_animations::mixedTypes() +{ + //### this one isn't real robust because width will likely change to real as well + { + QFxView *view = new QFxView; + view->setUrl(QUrl("file://" SRCDIR "/data/mixedtype1.qml")); + + view->execute(); + qApp->processEvents(); + + delete view; + } + + { + QFxView *view = new QFxView; + view->setUrl(QUrl("file://" SRCDIR "/data/mixedtype2.qml")); + + view->execute(); + qApp->processEvents(); + + delete view; + } +}*/ + +QTEST_MAIN(tst_animations) + +#include "tst_animations.moc" |