From: Michael Brasser Date: Wed, 9 May 2012 01:50:01 +0000 (+1000) Subject: ScriptAction without scriptName shouldn't match a StateChangeScript X-Git-Tag: 071012131707~441 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f9eb1d4ed610b6a96a247d9da7316ed8b83a077b;p=profile%2Fivi%2Fqtdeclarative.git ScriptAction without scriptName shouldn't match a StateChangeScript Change-Id: Idfce9b25fd2396771f45fc2487bc363edb56ddd6 Reviewed-by: Yunqiao Yin --- diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index 3a5674f..2fca7ba 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -937,15 +937,17 @@ QAbstractAnimationJob* QQuickScriptAction::transition(QQuickStateActions &action d->hasRunScriptScript = false; d->reversing = (direction == Backward); - for (int ii = 0; ii < actions.count(); ++ii) { - QQuickAction &action = actions[ii]; - - if (action.event && action.event->type() == QQuickActionEvent::Script - && static_cast(action.event)->name() == d->name) { - d->runScriptScript = static_cast(action.event)->script(); - d->hasRunScriptScript = true; - action.actionDone = true; - break; //only match one (names should be unique) + if (!d->name.isEmpty()) { + for (int ii = 0; ii < actions.count(); ++ii) { + QQuickAction &action = actions[ii]; + + if (action.event && action.event->type() == QQuickActionEvent::Script + && static_cast(action.event)->name() == d->name) { + d->runScriptScript = static_cast(action.event)->script(); + d->hasRunScriptScript = true; + action.actionDone = true; + break; //only match one (names should be unique) + } } } return initInstance(new QActionAnimation(d->createAction())); diff --git a/tests/auto/quick/qquickanimations/data/scriptActionBug.qml b/tests/auto/quick/qquickanimations/data/scriptActionBug.qml new file mode 100644 index 0000000..48566db --- /dev/null +++ b/tests/auto/quick/qquickanimations/data/scriptActionBug.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Item { + property bool actionTriggered: false + property bool stateChangeScriptTriggered: false + + states: State { + name: "state1" + StateChangeScript { script: stateChangeScriptTriggered = true } + } + + transitions: Transition { + ScriptAction { script: actionTriggered = true } + } + + Component.onCompleted: state = "state1" +} diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 60b0465..8cfdf74 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -108,6 +108,7 @@ private slots: void loopingBug(); void anchorBug(); void pathAnimationInOutBackBug(); + void scriptActionBug(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -1377,6 +1378,18 @@ void tst_qquickanimations::anchorBug() QCOMPARE(static_cast(animation.qtAnimation())->easingCurve(), QEasingCurve(QEasingCurve::InOutBack)); } +//ScriptAction should not match a StateChangeScript if no scriptName has been specified +void tst_qquickanimations::scriptActionBug() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("scriptActionBug.qml")); + QObject *obj = c.create(); + + //Both the ScriptAction and StateChangeScript should be triggered + QCOMPARE(obj->property("actionTriggered").toBool(), true); + QCOMPARE(obj->property("actionTriggered").toBool(), true); +} + QTEST_MAIN(tst_qquickanimations) #include "tst_qquickanimations.moc"