summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-09-08 04:56:22 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-09-08 04:56:22 (GMT)
commit3d247e0ae09bcd1b75f92a587ab5b28569a3f0f6 (patch)
tree75389cd4a08bdb00694ba47002fa9665887b33a0
parentff9eebaa9adb9cd41e97ac806238888546e77294 (diff)
parent56776c574a4af02cfa529095a757b80adfb7d189 (diff)
downloadQt-3d247e0ae09bcd1b75f92a587ab5b28569a3f0f6.zip
Qt-3d247e0ae09bcd1b75f92a587ab5b28569a3f0f6.tar.gz
Qt-3d247e0ae09bcd1b75f92a587ab5b28569a3f0f6.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: SpringAnimation velocity animation stop logic was fragile. Document difference between property binding and assignment Remove unused object Fix Worker ListModel to emit the right signal when items change
-rw-r--r--doc/src/declarative/javascriptblocks.qdoc34
-rw-r--r--doc/src/declarative/propertybinding.qdoc33
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp1
-rw-r--r--src/declarative/util/qdeclarativelistmodelworkeragent.cpp2
-rw-r--r--src/declarative/util/qdeclarativespringanimation.cpp37
5 files changed, 89 insertions, 18 deletions
diff --git a/doc/src/declarative/javascriptblocks.qdoc b/doc/src/declarative/javascriptblocks.qdoc
index 18da3d2..d290690 100644
--- a/doc/src/declarative/javascriptblocks.qdoc
+++ b/doc/src/declarative/javascriptblocks.qdoc
@@ -173,6 +173,40 @@ handler to execute at startup, they are run sequentially in an undefined order.
Likewise, the \l {Component::onDestruction} attached property is triggered on
component destruction.
+
+\section1 Property Assignment vs Property Binding
+
+When working with both QML and JavaScript, it is important to differentiate between
+QML \l {Property Binding} and JavaScript value assignment. In QML, a property
+binding is created using the \e {property: value} syntax:
+
+\code
+Rectangle {
+ width: otherItem.width
+}
+\endcode
+
+The \c width of the above \l Rectangle is updated whenever \c otherItem.width changes. On the other
+hand, take the following JavaScript code snippet, that runs when the \l Rectangle is created:
+
+\code
+Rectangle {
+
+ Component.onCompleted: {
+ width = otherItem.width;
+ }
+}
+\endcode
+
+The \c width of this \l Rectangle is \e assigned the value of \c otherItem.width using the
+\e {property = value} syntax in JavaScript. Unlike the QML \e {property: value} syntax, this
+does not invoke QML property binding; the \c rectangle.width property is set to the value
+of \c otherItem.width at the time of the assignment and will not be updated if that value
+changes.
+
+See \l {Property Binding} for more information.
+
+
\section1 QML JavaScript Restrictions
QML executes standard JavaScript code, with the following restrictions:
diff --git a/doc/src/declarative/propertybinding.qdoc b/doc/src/declarative/propertybinding.qdoc
index 552b9e4..314bf67 100644
--- a/doc/src/declarative/propertybinding.qdoc
+++ b/doc/src/declarative/propertybinding.qdoc
@@ -94,10 +94,29 @@ Rectangle {
}
\endcode
-Imperatively assigning a value directly to a property will also implicitly remove a binding
-on a property. A property can only have one value at a time, and if code explicitly sets
-this value the binding must be removed. The \l Rectangle in the example below will have
-a width of 13, regardless of the otherItem's width.
+
+\section1 Effects of Property Assignment in JavaScript
+
+Assigning a property value from JavaScript does \e not create a property binding.
+For example:
+
+\code
+Rectangle {
+
+ Component.onCompleted: {
+ width = otherItem.width;
+ }
+}
+\endcode
+
+Instead of creating a property binding, this simply sets the \c width of the \l Rectangle
+to the value of \c other.width at the time the JavaScript code is invoked. See
+\l {Property Assignment vs Property Binding} for more details.
+
+Also note that assigning a value to a property that is currently bound will remove the binding.
+A property can only have one value at a time, and if any code explicitly sets
+this value, the binding is removed. The \l Rectangle in the example below will have
+a width of 13, regardless of the \c otherItem's width.
\code
Rectangle {
@@ -109,7 +128,9 @@ Rectangle {
}
\endcode
-There is no way to create a property binding directly from imperative JavaScript code.
+There is no way to create a property binding directly from imperative JavaScript code,
+although it is possible to set up a \l Binding object (shown below).
+
\section1 Binding Element
@@ -126,5 +147,7 @@ Binding {
value: slider.value
}
\endqml
+
+
*/
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 60d8aa9..f290ab2 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -1247,7 +1247,6 @@ void ModelNode::setObjectValue(const QScriptValue& valuemap) {
}
void ModelNode::setListValue(const QScriptValue& valuelist) {
- QScriptValueIterator it(valuelist);
values.clear();
int size = valuelist.property(QLatin1String("length")).toInt32();
for (int i=0; i<size; i++) {
diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
index 498de6d..d9df169 100644
--- a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
+++ b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
@@ -232,7 +232,7 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e)
emit m_orig->itemsMoved(change.index, change.to, change.count);
break;
case Change::Changed:
- emit m_orig->itemsMoved(change.index, change.to, change.count);
+ emit m_orig->itemsChanged(change.index, change.to, orig->m_roles.keys());
break;
}
}
diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp
index fce4097..e0fc45d 100644
--- a/src/declarative/util/qdeclarativespringanimation.cpp
+++ b/src/declarative/util/qdeclarativespringanimation.cpp
@@ -62,10 +62,12 @@ public:
struct SpringAnimation {
SpringAnimation()
- : currentValue(0), to(0), velocity(0){}
+ : currentValue(0), to(0), velocity(0), start(0), duration(0) {}
qreal currentValue;
qreal to;
qreal velocity;
+ int start;
+ int duration;
};
QHash<QDeclarativeProperty, SpringAnimation> activeAnimations;
@@ -135,7 +137,6 @@ void QDeclarativeSpringAnimationPrivate::tick(int time)
bool QDeclarativeSpringAnimationPrivate::animate(const QDeclarativeProperty &property, SpringAnimation &animation, int elapsed)
{
-
qreal srcVal = animation.to;
bool stop = false;
@@ -192,18 +193,14 @@ bool QDeclarativeSpringAnimationPrivate::animate(const QDeclarativeProperty &pro
animation.currentValue += moveBy;
if (haveModulus)
animation.currentValue = fmod(animation.currentValue, modulus);
- if (animation.currentValue > animation.to) {
- animation.currentValue = animation.to;
- stop = true;
- }
} else {
animation.currentValue -= moveBy;
if (haveModulus && animation.currentValue < 0.0)
animation.currentValue = fmod(animation.currentValue, modulus) + modulus;
- if (animation.currentValue < animation.to) {
- animation.currentValue = animation.to;
- stop = true;
- }
+ }
+ if (lastTime - animation.start >= animation.duration) {
+ animation.currentValue = animation.to;
+ stop = true;
}
}
@@ -222,8 +219,18 @@ void QDeclarativeSpringAnimationPrivate::updateMode()
mode = Track;
else if (spring > 0.)
mode = Spring;
- else
+ else {
mode = Velocity;
+ QHash<QDeclarativeProperty, SpringAnimation>::iterator it;
+ for (it = activeAnimations.begin(); it != activeAnimations.end(); ++it) {
+ SpringAnimation &animation = *it;
+ animation.start = lastTime;
+ qreal dist = qAbs(animation.currentValue - animation.to);
+ if (haveModulus && dist > modulus / 2)
+ dist = modulus - fmod(dist, modulus);
+ animation.duration = dist / velocityms;
+ }
+ }
}
/*!
@@ -378,6 +385,7 @@ void QDeclarativeSpringAnimation::setModulus(qreal modulus)
if (d->modulus != modulus) {
d->haveModulus = modulus != 0.0;
d->modulus = modulus;
+ d->updateMode();
emit modulusChanged();
}
}
@@ -429,10 +437,17 @@ void QDeclarativeSpringAnimation::transition(QDeclarativeStateActions &actions,
QDeclarativeSpringAnimationPrivate::SpringAnimation &animation
= d->activeAnimations[property];
animation.to = d->actions->at(i).toValue.toReal();
+ animation.start = d->lastTime;
if (d->fromIsDefined)
animation.currentValue = d->actions->at(i).fromValue.toReal();
else
animation.currentValue = property.read().toReal();
+ if (d->mode == QDeclarativeSpringAnimationPrivate::Velocity) {
+ qreal dist = qAbs(animation.currentValue - animation.to);
+ if (d->haveModulus && dist > d->modulus / 2)
+ dist = d->modulus - fmod(dist, d->modulus);
+ animation.duration = dist / d->velocityms;
+ }
}
}
}