diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-11 06:35:41 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-03-11 06:39:48 (GMT) |
commit | 54bdab8b88777488f9f0d944698fbb155cf703af (patch) | |
tree | 3e143e77e22e68a13ca7fd81178899bdd91b0a30 /src/declarative/qml/qdeclarativeproperty.cpp | |
parent | fef9bb355f964f7a520da0c5e24d165644be1473 (diff) | |
download | Qt-54bdab8b88777488f9f0d944698fbb155cf703af.zip Qt-54bdab8b88777488f9f0d944698fbb155cf703af.tar.gz Qt-54bdab8b88777488f9f0d944698fbb155cf703af.tar.bz2 |
Improve value type binding behavior
Changing value type bindings in state changes, and implicitly removing
them on property assignment was not reliable. Internally the system
considered a binding on "font" and one on "font.x" as a binding on two
separate properties, even though the "font" binding completely
overrides the "font.x" property.
Following this change a binding to "font.x" creates a proxy binding object
on the "font" property in addition to the "font.x" binding itself. This
allows behavior to be consistent across all operations.
QT-2920
Diffstat (limited to 'src/declarative/qml/qdeclarativeproperty.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativeproperty.cpp | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index 945d098..8ca5406 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -598,7 +598,6 @@ QMetaMethod QDeclarativeProperty::method() const return QMetaMethod(); } - /*! Returns the binding associated with this property, or 0 if no binding exists. @@ -617,13 +616,18 @@ QDeclarativePropertyPrivate::binding(const QDeclarativeProperty &that) return 0; QDeclarativeAbstractBinding *binding = data->bindings; - while (binding) { - // ### This wont work for value types - if (binding->propertyIndex() == that.d->core.coreIndex) - return binding; + while (binding && binding->propertyIndex() != that.d->core.coreIndex) binding = binding->m_nextBinding; + + if (binding && that.d->valueType.valueTypeCoreIdx != -1) { + if (binding->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy) { + QDeclarativeValueTypeProxyBinding *proxy = static_cast<QDeclarativeValueTypeProxyBinding *>(binding); + + binding = proxy->binding(bindingIndex(that)); + } } - return 0; + + return binding; } /*! @@ -650,36 +654,36 @@ QDeclarativePropertyPrivate::setBinding(const QDeclarativeProperty &that, return 0; } - return that.d->setBinding(that.d->object, that.d->core, newBinding, flags); + return that.d->setBinding(that.d->object, that.d->core.coreIndex, + that.d->valueType.valueTypeCoreIdx, newBinding, flags); } QDeclarativeAbstractBinding * -QDeclarativePropertyPrivate::setBinding(QObject *object, const QDeclarativePropertyCache::Data &core, - QDeclarativeAbstractBinding *newBinding, WriteFlags flags) +QDeclarativePropertyPrivate::setBinding(QObject *object, int coreIndex, int valueTypeIndex, + QDeclarativeAbstractBinding *newBinding, WriteFlags flags) { QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, 0 != newBinding); + QDeclarativeAbstractBinding *binding = 0; - if (data && data->hasBindingBit(core.coreIndex)) { - QDeclarativeAbstractBinding *binding = data->bindings; - while (binding) { - // ### This wont work for value types - if (binding->propertyIndex() == core.coreIndex) { - binding->setEnabled(false); + if (data && data->hasBindingBit(coreIndex)) { + binding = data->bindings; - if (newBinding) - newBinding->setEnabled(true, flags); + while (binding && binding->propertyIndex() != coreIndex) + binding = binding->m_nextBinding; + } - return binding; // ### QDeclarativeAbstractBinding; - } + if (binding && valueTypeIndex != -1 && binding->bindingType() == QDeclarativeAbstractBinding::ValueTypeProxy) { + int index = coreIndex | (valueTypeIndex << 24); + binding = static_cast<QDeclarativeValueTypeProxyBinding *>(binding)->binding(index); + } - binding = binding->m_nextBinding; - } - } + if (binding) + binding->setEnabled(false); - if (newBinding) + if (newBinding) newBinding->setEnabled(true, flags); - return 0; + return binding; } /*! @@ -1253,6 +1257,18 @@ int QDeclarativePropertyPrivate::valueTypeCoreIndex(const QDeclarativeProperty & return that.d->valueType.valueTypeCoreIdx; } +/*! + Returns the "property index" for use in bindings. The top 8 bits are the value type + offset, and 0 otherwise. The bottom 24-bits are the regular property index. +*/ +int QDeclarativePropertyPrivate::bindingIndex(const QDeclarativeProperty &that) +{ + int rv = that.d->core.coreIndex; + if (rv != -1 && that.d->valueType.valueTypeCoreIdx != -1) + rv = rv | (that.d->valueType.valueTypeCoreIdx << 24); + return rv; +} + struct SerializedData { bool isValueType; QDeclarativePropertyCache::Data core; |