From 28102d1935dfd7fc88c4bb3b656aadc44942f562 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Nov 2011 13:01:56 +1000 Subject: [PATCH] Behavior on a value type should not cancel previous assignment. The call to read the value type value causes the previously assigned value to be overridden. This commit fixes the issue, but doesn't solve the root cause, which would require changes at the compiler/vme level. Task-number: QTBUG-20827 Change-Id: I1a53ee7b777bea81c5929ab7e47e2932e6901967 Reviewed-by: Martin Jones --- src/declarative/util/qdeclarativebehavior.cpp | 6 ++---- .../qdeclarativebehaviors/data/valueType.qml | 13 +++++++++++++ .../tst_qdeclarativebehaviors.cpp | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativebehaviors/data/valueType.qml diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp index 8ff1a06..6fb3619 100644 --- a/src/declarative/util/qdeclarativebehavior.cpp +++ b/src/declarative/util/qdeclarativebehavior.cpp @@ -60,7 +60,6 @@ public: , blockRunningChanged(false) {} QDeclarativeProperty property; - QVariant currentValue; QVariant targetValue; QDeclarativeGuard animation; bool enabled; @@ -185,7 +184,7 @@ void QDeclarativeBehavior::write(const QVariant &value) if (d->animation->isRunning() && value == d->targetValue) return; - d->currentValue = d->property.read(); + const QVariant ¤tValue = d->property.read(); d->targetValue = value; if (d->animation->qtAnimation()->duration() != -1 @@ -197,7 +196,7 @@ void QDeclarativeBehavior::write(const QVariant &value) QDeclarativeStateOperation::ActionList actions; QDeclarativeAction action; action.property = d->property; - action.fromValue = d->currentValue; + action.fromValue = currentValue; action.toValue = value; actions << action; @@ -213,7 +212,6 @@ void QDeclarativeBehavior::setTarget(const QDeclarativeProperty &property) { Q_D(QDeclarativeBehavior); d->property = property; - d->currentValue = property.read(); if (d->animation) d->animation->setDefaultTarget(property); diff --git a/tests/auto/declarative/qdeclarativebehaviors/data/valueType.qml b/tests/auto/declarative/qdeclarativebehaviors/data/valueType.qml new file mode 100644 index 0000000..7bc8297 --- /dev/null +++ b/tests/auto/declarative/qdeclarativebehaviors/data/valueType.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 +Rectangle { + width: 400 + height: 400 + + color.r: 1 + color.g: 0 + color.b: 1 + + Behavior on color.r { NumberAnimation { duration: 500; } } + + function changeR() { color.r = 0 } +} diff --git a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp index e84cd58..608cdac 100644 --- a/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp +++ b/tests/auto/declarative/qdeclarativebehaviors/tst_qdeclarativebehaviors.cpp @@ -66,6 +66,7 @@ private slots: void replaceBinding(); //void transitionOverrides(); void group(); + void valueType(); void emptyBehavior(); void explicitSelection(); void nonSelectingBehavior(); @@ -237,6 +238,19 @@ void tst_qdeclarativebehaviors::group() } } +void tst_qdeclarativebehaviors::valueType() +{ + QDeclarativeEngine engine; + QDeclarativeComponent c(&engine, QUrl::fromLocalFile(TESTDATA("valueType.qml"))); + QQuickRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + //QTBUG-20827 + QCOMPARE(rect->color(), QColor::fromRgb(255,0,255)); + + delete rect; +} + void tst_qdeclarativebehaviors::emptyBehavior() { QDeclarativeEngine engine; -- 1.7.2.5