diff options
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/qmlbindablevalue.cpp | 35 | ||||
-rw-r--r-- | src/declarative/qml/qmlbindablevalue.h | 10 | ||||
-rw-r--r-- | src/declarative/qml/qmlbindablevalue_p.h | 6 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 47 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/qmlvme.cpp | 4 | ||||
-rw-r--r-- | src/declarative/util/qmlanimation.cpp | 6 | ||||
-rw-r--r-- | src/declarative/util/qmlsetproperties.cpp | 28 | ||||
-rw-r--r-- | src/declarative/util/qmlsetproperties.h | 4 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.cpp | 84 | ||||
-rw-r--r-- | src/declarative/util/qmlstate.h | 13 | ||||
-rw-r--r-- | src/declarative/util/qmlstate_p.h | 8 | ||||
-rw-r--r-- | src/declarative/util/qmlstateoperations.cpp | 10 |
13 files changed, 191 insertions, 68 deletions
diff --git a/src/declarative/qml/qmlbindablevalue.cpp b/src/declarative/qml/qmlbindablevalue.cpp index d1835cf..222ea87 100644 --- a/src/declarative/qml/qmlbindablevalue.cpp +++ b/src/declarative/qml/qmlbindablevalue.cpp @@ -53,18 +53,18 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(scriptWarnings, QML_SCRIPT_WARNINGS); QmlBindableValuePrivate::QmlBindableValuePrivate() -: inited(false), updating(false), mePtr(0) +: inited(false), updating(false), enabled(true), mePtr(0) { } QML_DEFINE_NOCREATE_TYPE(QmlBindableValue); -QmlBindableValue::QmlBindableValue(void *data, QmlRefCount *rc, QObject *obj, QObject *parent) -: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(QmlContext::activeContext(), data, rc, obj) +QmlBindableValue::QmlBindableValue(void *data, QmlRefCount *rc, QObject *obj, QmlContext *ctxt, QObject *parent) +: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(ctxt, data, rc, obj) { } -QmlBindableValue::QmlBindableValue(const QString &str, QObject *obj, QObject *parent) -: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(QmlContext::activeContext(), str, obj) +QmlBindableValue::QmlBindableValue(const QString &str, QObject *obj, QmlContext *ctxt, QObject *parent) +: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(ctxt, str, obj) { } @@ -105,6 +105,15 @@ void QmlBindableValue::setExpression(const QString &expr) update(); } +void QmlBindableValue::forceUpdate() +{ + Q_D(QmlBindableValue); + if (!d->inited) + init(); + else + update(); +} + Q_DECLARE_METATYPE(QList<QObject *>); void QmlBindableValue::update() { @@ -113,7 +122,7 @@ void QmlBindableValue::update() #ifdef Q_ENABLE_PERFORMANCE_LOG QFxPerfTimer<QFxPerf::BindableValueUpdate> bu; #endif - if (!d->inited) + if (!d->inited || !d->enabled) return; if (!d->updating) { @@ -159,4 +168,18 @@ void QmlBindableValue::valueChanged() update(); } +void QmlBindableValue::setEnabled(bool e) +{ + Q_D(QmlBindableValue); + d->enabled = e; + setTrackChange(e); +} + +bool QmlBindableValue::enabled() const +{ + Q_D(const QmlBindableValue); + + return d->enabled; +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlbindablevalue.h b/src/declarative/qml/qmlbindablevalue.h index f54481a..50bbf36 100644 --- a/src/declarative/qml/qmlbindablevalue.h +++ b/src/declarative/qml/qmlbindablevalue.h @@ -62,8 +62,8 @@ class Q_DECLARATIVE_EXPORT QmlBindableValue : public QmlPropertyValueSource, { Q_OBJECT public: - QmlBindableValue(const QString &, QObject *, QObject *parent=0); - QmlBindableValue(void *, QmlRefCount *, QObject *, QObject *parent); + QmlBindableValue(const QString &, QObject *, QmlContext *, QObject *parent=0); + QmlBindableValue(void *, QmlRefCount *, QObject *, QmlContext *, QObject *parent); ~QmlBindableValue(); virtual void setTarget(const QmlMetaProperty &); @@ -74,8 +74,12 @@ public: virtual void setExpression(const QString &); void init(); + void forceUpdate(); -private Q_SLOTS: + void setEnabled(bool); + bool enabled() const; + +public Q_SLOTS: void update(); protected: diff --git a/src/declarative/qml/qmlbindablevalue_p.h b/src/declarative/qml/qmlbindablevalue_p.h index 9476b80..b55a314 100644 --- a/src/declarative/qml/qmlbindablevalue_p.h +++ b/src/declarative/qml/qmlbindablevalue_p.h @@ -54,8 +54,10 @@ class QmlBindableValuePrivate : public QObjectPrivate public: QmlBindableValuePrivate(); - bool inited; - bool updating; + bool inited:1; + bool updating:1; + bool enabled:1; + QmlMetaProperty property; QmlBindableValue **mePtr; diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 52036c2..30e818b 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -519,7 +519,7 @@ QMetaProperty QmlMetaProperty::property() const Returns the binding associated with this property, or 0 if no binding exists. */ -QmlBindableValue *QmlMetaProperty::binding() +QmlBindableValue *QmlMetaProperty::binding() const { if (!isProperty() || type() & Attached) return 0; @@ -537,6 +537,51 @@ QmlBindableValue *QmlMetaProperty::binding() return 0; } +/*! + Set the binding associated with this property to \a binding. Returns + the existing binding (if any), otherwise 0. + + \a binding will be enabled, and the returned binding (if any) will be + disabled. +*/ +QmlBindableValue *QmlMetaProperty::setBinding(QmlBindableValue *binding) const +{ + if (!isProperty() || type() & Attached) + return 0; + + const QObjectList &children = object()->children(); + for (QObjectList::ConstIterator iter = children.begin(); + iter != children.end(); ++iter) { + QObject *child = *iter; + if (child->metaObject() == &QmlBindableValue::staticMetaObject) { + QmlBindableValue *v = static_cast<QmlBindableValue *>(child); + if (v->property() == *this && v->enabled()) { + + v->setEnabled(false); + + if (binding) { + binding->setParent(object()); + binding->setTarget(*this); + binding->setEnabled(true); + binding->forceUpdate(); + } + + return v; + + } + } + } + + if (binding) { + binding->setParent(object()); + binding->setTarget(*this); + binding->setEnabled(true); + binding->forceUpdate(); + } + + return 0; +} + /*! \internal */ int QmlMetaProperty::findSignal(const QObject *obj, const char *name) { diff --git a/src/declarative/qml/qmlmetaproperty.h b/src/declarative/qml/qmlmetaproperty.h index 9daef59..ce2fbcf 100644 --- a/src/declarative/qml/qmlmetaproperty.h +++ b/src/declarative/qml/qmlmetaproperty.h @@ -123,7 +123,9 @@ public: QMetaProperty property() const; - QmlBindableValue *binding(); + QmlBindableValue *binding() const; + QmlBindableValue *setBinding(QmlBindableValue *) const; + static int findSignal(const QObject *, const char *); int coreIndex() const; diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index a3ee4e5..962d917 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -564,7 +564,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledComp QmlMetaProperty mp(target, instr.assignBinding.property, (QmlMetaProperty::PropertyCategory)instr.assignBinding.category); - QmlBindableValue *bind = new QmlBindableValue((void *)datas.at(instr.assignBinding.value).constData(), comp, context, 0); + QmlBindableValue *bind = new QmlBindableValue((void *)datas.at(instr.assignBinding.value).constData(), comp, context, QmlContext::activeContext(), 0); bindValues.append(bind); QmlBindableValuePrivate *p = static_cast<QmlBindableValuePrivate *>(QObjectPrivate::get(bind)); @@ -584,7 +584,7 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledComp QmlMetaProperty mp(target, instr.assignBinding.property, (QmlMetaProperty::PropertyCategory)instr.assignBinding.category); - QmlBindableValue *bind = new QmlBindableValue(primitives.at(instr.assignBinding.value), context, false); + QmlBindableValue *bind = new QmlBindableValue(primitives.at(instr.assignBinding.value), context, QmlContext::activeContext()); bindValues.append(bind); QmlBindableValuePrivate *p = static_cast<QmlBindableValuePrivate *>(QObjectPrivate::get(bind)); diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 2a6cad9..e5f1138 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -958,8 +958,6 @@ void QmlColorAnimation::transition(QmlStateActions &actions, myAction.fromValue = QVariant(d->fromValue); myAction.toValue = QVariant(d->toValue); - myAction.bv = 0; - myAction.event = 0; data->actions << myAction; } } @@ -1766,8 +1764,6 @@ void QmlNumericAnimation::transition(QmlStateActions &actions, myAction.fromValue = QVariant(d->from); myAction.toValue = QVariant(d->to); - myAction.bv = 0; - myAction.event = 0; data->actions << myAction; } } @@ -2332,8 +2328,6 @@ void QmlVariantAnimation::transition(QmlStateActions &actions, d->convertVariant(d->to, (QVariant::Type)myAction.property.propertyType()); myAction.toValue = d->to; - myAction.bv = 0; - myAction.event = 0; data->actions << myAction; } } diff --git a/src/declarative/util/qmlsetproperties.cpp b/src/declarative/util/qmlsetproperties.cpp index cb97ed9..240e37b 100644 --- a/src/declarative/util/qmlsetproperties.cpp +++ b/src/declarative/util/qmlsetproperties.cpp @@ -47,6 +47,7 @@ #include <private/qmlcustomparser_p.h> #include <private/qmlparser_p.h> #include <QtDeclarative/qmlexpression.h> +#include <QtDeclarative/qmlbindablevalue.h> QT_BEGIN_NAMESPACE @@ -113,7 +114,8 @@ class QmlSetPropertiesPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QmlSetProperties) public: - QmlSetPropertiesPrivate() : object(0), decoded(true), restore(true) {} + QmlSetPropertiesPrivate() : object(0), decoded(true), restore(true), + isExplicit(false) {} QObject *object; QByteArray data; @@ -121,6 +123,7 @@ public: void decode(); bool restore; + bool isExplicit; QList<QPair<QByteArray, QVariant> > properties; QList<QPair<QByteArray, QmlExpression *> > expressions; @@ -205,6 +208,7 @@ QmlSetPropertiesParser::compile(const QList<QmlCustomParserProperty> &props, void QmlSetPropertiesPrivate::decode() { + Q_Q(QmlSetProperties); if (decoded) return; @@ -221,7 +225,7 @@ void QmlSetPropertiesPrivate::decode() ds >> data; if (isScript) { - QmlExpression *expression = new QmlExpression(qmlContext(object), data.toString(), object); + QmlExpression *expression = new QmlExpression(qmlContext(q), data.toString(), object); expression->setTrackChange(false); expressions << qMakePair(name, expression); } else { @@ -347,7 +351,13 @@ QmlSetProperties::ActionList QmlSetProperties::actions() a.restore = restoreEntryValues(); a.property = prop; a.fromValue = a.property.read(); - a.toValue = d->expressions.at(ii).second->value(); + + if (d->isExplicit) { + a.toValue = d->expressions.at(ii).second->value(); + } else { + a.toBinding = new QmlBindableValue(d->expressions.at(ii).second->expression(), object(), qmlContext(this)); + a.toBinding->setTarget(prop); + } list << a; } @@ -357,6 +367,18 @@ QmlSetProperties::ActionList QmlSetProperties::actions() return list; } +bool QmlSetProperties::isExplicit() const +{ + Q_D(const QmlSetProperties); + return d->isExplicit; +} + +void QmlSetProperties::setIsExplicit(bool e) +{ + Q_D(QmlSetProperties); + d->isExplicit = e; +} + QML_DEFINE_CUSTOM_TYPE(QmlSetProperties,SetProperties,QmlSetPropertiesParser) QT_END_NAMESPACE diff --git a/src/declarative/util/qmlsetproperties.h b/src/declarative/util/qmlsetproperties.h index da5fcf2..fe98900 100644 --- a/src/declarative/util/qmlsetproperties.h +++ b/src/declarative/util/qmlsetproperties.h @@ -59,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QmlSetProperties : public QmlStateOperation Q_PROPERTY(QObject *target READ object WRITE setObject) Q_PROPERTY(bool restoreEntryValues READ restoreEntryValues WRITE setRestoreEntryValues) + Q_PROPERTY(bool explicit READ isExplicit WRITE setIsExplicit); public: QmlSetProperties(); ~QmlSetProperties(); @@ -69,6 +70,9 @@ public: bool restoreEntryValues() const; void setRestoreEntryValues(bool); + bool isExplicit() const; + void setIsExplicit(bool); + virtual ActionList actions(); }; QML_DECLARE_TYPE(QmlSetProperties) diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index 0574224..fe215e7 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(stateChangeDebug, STATECHANGE_DEBUG); -Action::Action() : restore(true), bv(0), event(0), actionDone(false) +Action::Action() : restore(true), actionDone(false), fromBinding(0), toBinding(0), event(0) { } @@ -237,8 +237,9 @@ QmlState &QmlState::operator<<(QmlStateOperation *op) void QmlStatePrivate::applyBindings() { foreach(const Action &action, bindingsList) { - if (action.bv && !action.toBinding.isEmpty()) { - action.bv->setExpression(action.toBinding); + if (action.toBinding) { + action.property.setBinding(action.toBinding); + action.toBinding->forceUpdate(); } } } @@ -246,6 +247,7 @@ void QmlStatePrivate::applyBindings() void QmlStatePrivate::complete() { Q_Q(QmlState); + //apply bindings (now that all transitions are complete) applyBindings(); @@ -316,6 +318,15 @@ void QmlState::cancel() } } +void Action::deleteFromBinding() +{ + if (fromBinding) { + property.setBinding(0); + delete fromBinding; + fromBinding = 0; + } +} + void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *revert) { Q_D(QmlState); @@ -341,20 +352,36 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever QmlStatePrivate::SimpleActionList additionalReverts; // First add the reverse of all the applyList actions for (int ii = 0; ii < applyList.count(); ++ii) { - const Action &action = applyList.at(ii); - if (action.event || !action.restore) + Action &action = applyList[ii]; + + if (action.event) continue; + action.fromBinding = action.property.binding(); + bool found = false; - for (int jj = 0; !found && jj < d->revertList.count(); ++jj) { - if (d->revertList.at(jj).property == action.property) + int jj; + for (jj = 0; jj < d->revertList.count(); ++jj) { + if (d->revertList.at(jj).property == action.property) { found = true; + break; + } } + if (!found) { - // Only need to revert the applyList action if the previous - // state doesn't have a higher priority revert already - SimpleAction r(action); - additionalReverts << r; + if (!action.restore) { + action.deleteFromBinding(); + } else { + // Only need to revert the applyList action if the previous + // state doesn't have a higher priority revert already + SimpleAction r(action); + additionalReverts << r; + } + } else { + + if (!found || d->revertList.at(jj).binding != action.fromBinding) { + action.deleteFromBinding(); + } } } @@ -369,15 +396,13 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever } if (!found) { QVariant cur = d->revertList.at(ii).property.read(); + delete d->revertList.at(ii).property.setBinding(0); + Action a; a.property = d->revertList.at(ii).property; a.fromValue = cur; a.toValue = d->revertList.at(ii).value; a.toBinding = d->revertList.at(ii).binding; - if (!a.toBinding.isEmpty()) { - a.fromBinding = d->revertList.at(ii).bv->expression(); - a.bv = d->revertList.at(ii).bv; - } applyList << a; // Store these special reverts in the reverting list d->reverting << d->revertList.at(ii).property; @@ -396,9 +421,12 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever // Determine which actions are binding changes. foreach(const Action &action, applyList) { - if (action.bv && !action.toBinding.isEmpty()) { + if (action.toBinding) { d->bindingsList << action; - action.bv->clearExpression(); + if (action.fromBinding) + action.property.setBinding(0); // Disable current binding + } else if (action.fromBinding) { + action.property.setBinding(0); // Disable current binding } } @@ -415,8 +443,9 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever // Apply all the property and binding changes foreach(const Action &action, applyList) { - if (action.bv && !action.toBinding.isEmpty()) { - action.bv->setExpression(action.toBinding); + if (action.toBinding) { + action.property.setBinding(action.toBinding); + action.toBinding->forceUpdate(); } else if (!action.event) { action.property.write(action.toValue); } @@ -429,9 +458,8 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever continue; const QmlMetaProperty &prop = action->property; - if (action->bv && !action->toBinding.isEmpty()) { + if (action->toBinding) action->toValue = prop.read(); - } } // Revert back to the original values @@ -439,8 +467,9 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever if (action.event) continue; - if (action.bv && !action.toBinding.isEmpty()) - action.bv->clearExpression(); + if (action.toBinding) + action.property.setBinding(0); + action.property.write(action.fromValue); } } @@ -480,12 +509,15 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever } // Any actions remaining have not been handled by the transition and should - // be applied immediately + // be applied immediately. We skip applying transitions, as they are all + // applied at the end in applyBindings() to avoid any nastiness mid + // transition foreach(const Action &action, applyList) { - if (action.event) + if (action.event) { action.event->execute(); - else + } else { action.property.write(action.toValue); + } } if (!trans) d->applyBindings(); //### merge into above foreach? diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index 59ef812..e9a173c 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -60,15 +60,18 @@ class Action public: Action(); + bool restore:1; + bool actionDone:1; + QmlMetaProperty property; - bool restore; QVariant fromValue; QVariant toValue; - QString fromBinding; - QString toBinding; - QmlBindableValue *bv; + + QmlBindableValue *fromBinding; + QmlBindableValue *toBinding; ActionEvent *event; - bool actionDone; + + void deleteFromBinding(); }; class ActionEvent diff --git a/src/declarative/util/qmlstate_p.h b/src/declarative/util/qmlstate_p.h index 7fcbcd7..b4ec476 100644 --- a/src/declarative/util/qmlstate_p.h +++ b/src/declarative/util/qmlstate_p.h @@ -52,23 +52,21 @@ class SimpleAction { public: enum State { StartState, EndState }; - SimpleAction(const Action &a, State state = StartState) : bv(0) + SimpleAction(const Action &a, State state = StartState) { property = a.property; if (state == StartState) { value = a.fromValue; - binding = a.fromBinding; + binding = property.binding(); } else { value = a.toValue; binding = a.toBinding; } - bv = a.bv; } QmlMetaProperty property; QVariant value; - QString binding; - QmlBindableValue *bv; + QmlBindableValue *binding; }; class QmlStatePrivate : public QObjectPrivate diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 02b54f8..b7398a3 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -417,14 +417,8 @@ QmlSetProperty::ActionList QmlSetProperty::actions() a.property = prop; a.fromValue = cur; a.toValue = d->value; - if (!d->binding.isEmpty()) { - QmlBindableValue *bv = prop.binding(); - if (bv) { - a.fromBinding = bv->expression(); - a.bv = bv; - } - } - a.toBinding = d->binding; + if (!d->binding.isEmpty()) + a.toBinding = new QmlBindableValue(d->binding, object(), qmlContext(this)); return ActionList() << a; } |