diff options
Diffstat (limited to 'src/quick/util')
-rw-r--r-- | src/quick/util/qquickbehavior.cpp | 11 | ||||
-rw-r--r-- | src/quick/util/qquickglobal.cpp | 2 | ||||
-rw-r--r-- | src/quick/util/qquickpropertychanges.cpp | 61 | ||||
-rw-r--r-- | src/quick/util/qquickpropertychanges_p.h | 2 |
4 files changed, 74 insertions, 2 deletions
diff --git a/src/quick/util/qquickbehavior.cpp b/src/quick/util/qquickbehavior.cpp index 460e2ca554..407b80915d 100644 --- a/src/quick/util/qquickbehavior.cpp +++ b/src/quick/util/qquickbehavior.cpp @@ -185,7 +185,8 @@ void QQuickBehavior::write(const QVariant &value) return; } - if (d->animation->isRunning() && value == d->targetValue) + bool behaviorActive = d->animation->isRunning(); + if (behaviorActive && value == d->targetValue) return; d->targetValue = value; @@ -201,6 +202,14 @@ void QQuickBehavior::write(const QVariant &value) // to the item, so we need to read the value after. const QVariant ¤tValue = d->property.read(); + // Don't unnecessarily wake up the animation system if no real animation + // is needed (value has not changed). If the Behavior was already + // running, let it continue as normal to ensure correct behavior and state. + if (!behaviorActive && d->targetValue == currentValue) { + QQmlPropertyPrivate::write(d->property, value, QQmlPropertyPrivate::BypassInterceptor | QQmlPropertyPrivate::DontRemoveBinding); + return; + } + QQuickStateOperation::ActionList actions; QQuickStateAction action; action.property = d->property; diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 152d1f34c9..5ae74c2fec 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -398,7 +398,7 @@ public: if (!array) return QMatrix4x4(); - if (array->arrayLength() != 16) + if (array->getLength() != 16) return QMatrix4x4(); float matVals[16]; diff --git a/src/quick/util/qquickpropertychanges.cpp b/src/quick/util/qquickpropertychanges.cpp index 148c55bbcb..55ac85e64d 100644 --- a/src/quick/util/qquickpropertychanges.cpp +++ b/src/quick/util/qquickpropertychanges.cpp @@ -259,6 +259,29 @@ QQuickPropertyChangesParser::compileList(QList<QPair<QString, QVariant> > &list, } } +void QQuickPropertyChangesParser::compileList(QList<QPair<QString, const QV4::CompiledData::Binding*> > &list, const QString &pre, const QV4::CompiledData::QmlUnit *qmlUnit, const QV4::CompiledData::Binding *binding) +{ + QString propName = pre + qmlUnit->header.stringAt(binding->propertyNameIndex); + + if (binding->type == QV4::CompiledData::Binding::Type_Object) { + error(qmlUnit->objectAt(binding->value.objectIndex), QQuickPropertyChanges::tr("PropertyChanges does not support creating state-specific objects.")); + return; + } + + if (binding->type == QV4::CompiledData::Binding::Type_GroupProperty + || binding->type == QV4::CompiledData::Binding::Type_AttachedProperty) { + QString pre = propName + QLatin1Char('.'); + const QV4::CompiledData::Object *subObj = qmlUnit->objectAt(binding->value.objectIndex); + const QV4::CompiledData::Binding *subBinding = subObj->bindingTable(); + for (quint32 i = 0; i < subObj->nBindings; ++i, ++subBinding) { + compileList(list, pre, qmlUnit, subBinding); + } + return; + } + + list << qMakePair(propName, binding); +} + QByteArray QQuickPropertyChangesParser::compile(const QList<QQmlCustomParserProperty> &props) { @@ -303,6 +326,44 @@ QQuickPropertyChangesParser::compile(const QList<QQmlCustomParserProperty> &prop return rv; } +QByteArray QQuickPropertyChangesParser::compile(const QV4::CompiledData::QmlUnit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props) +{ + QList<QPair<QString, const QV4::CompiledData::Binding *> > data; + for (int ii = 0; ii < props.count(); ++ii) + compileList(data, QString(), qmlUnit, props.at(ii)); + + QByteArray rv; + QDataStream ds(&rv, QIODevice::WriteOnly); + + ds << data.count(); + for (int ii = 0; ii < data.count(); ++ii) { + const QV4::CompiledData::Binding *binding = data.at(ii).second; + QVariant var; + bool isScript = binding->type == QV4::CompiledData::Binding::Type_Script; + QQmlBinding::Identifier id = QQmlBinding::Invalid; + switch (binding->type) { + case QV4::CompiledData::Binding::Type_Script: + // ### pre-compile binding + case QV4::CompiledData::Binding::Type_String: + var = binding->valueAsString(&qmlUnit->header); + break; + case QV4::CompiledData::Binding::Type_Number: + var = binding->valueAsNumber(); + break; + case QV4::CompiledData::Binding::Type_Boolean: + var = binding->valueAsBoolean(); + break; + default: + break; + } + ds << data.at(ii).first << isScript << var; + if (isScript) + ds << id; + } + + return rv; +} + void QQuickPropertyChangesPrivate::decode() { Q_Q(QQuickPropertyChanges); diff --git a/src/quick/util/qquickpropertychanges_p.h b/src/quick/util/qquickpropertychanges_p.h index 0236e4529b..081ea72862 100644 --- a/src/quick/util/qquickpropertychanges_p.h +++ b/src/quick/util/qquickpropertychanges_p.h @@ -93,8 +93,10 @@ public: : QQmlCustomParser(AcceptsAttachedProperties) {} void compileList(QList<QPair<QString, QVariant> > &list, const QString &pre, const QQmlCustomParserProperty &prop); + void compileList(QList<QPair<QString, const QV4::CompiledData::Binding *> > &list, const QString &pre, const QV4::CompiledData::QmlUnit *qmlUnit, const QV4::CompiledData::Binding *binding); virtual QByteArray compile(const QList<QQmlCustomParserProperty> &); + virtual QByteArray compile(const QV4::CompiledData::QmlUnit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props); virtual void setCustomData(QObject *, const QByteArray &); }; |