diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-04-15 10:24:39 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-26 16:33:56 +0000 |
commit | 01c0c0963794f4dd8c3601e8340cc3dc4dec41bd (patch) | |
tree | 91dc7d0bc38d8f03ddf6a2aff97754c1e9183f33 | |
parent | f65f0d4e1da39a5f5fa92e0b8d9ba4ad346d78ef (diff) |
Get rid of QQmlBinding::retargetBinding()
Instead call setTarget directly and properly resolve the required
QQmlPropertyData. Saves some memory for bindings to value types.
Change-Id: I542b456685955add7d395764ff85cb3098b3f208
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r-- | src/qml/qml/qqmlabstractbinding.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmlabstractbinding_p.h | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 16 | ||||
-rw-r--r-- | src/qml/qml/qqmlbinding_p.h | 8 | ||||
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 36 |
5 files changed, 37 insertions, 33 deletions
diff --git a/src/qml/qml/qqmlabstractbinding.cpp b/src/qml/qml/qqmlabstractbinding.cpp index fd5a72eff8..051125a8d9 100644 --- a/src/qml/qml/qqmlabstractbinding.cpp +++ b/src/qml/qml/qqmlabstractbinding.cpp @@ -191,11 +191,6 @@ void QQmlAbstractBinding::clear() } } -void QQmlAbstractBinding::retargetBinding(QObject *, int) -{ - qFatal("QQmlAbstractBinding::retargetBinding() called on illegal binding."); -} - QString QQmlAbstractBinding::expression() const { return QLatin1String("<Unknown>"); diff --git a/src/qml/qml/qqmlabstractbinding_p.h b/src/qml/qml/qqmlabstractbinding_p.h index c7b9abc8f3..b9275dc2c3 100644 --- a/src/qml/qml/qqmlabstractbinding_p.h +++ b/src/qml/qml/qqmlabstractbinding_p.h @@ -94,11 +94,6 @@ protected: virtual ~QQmlAbstractBinding(); void clear(); - // Called by QQmlPropertyPrivate to "move" a binding to a different property. - // This is only used for alias properties. The default implementation qFatal()'s - // to ensure that the method is never called for binding types that don't support it. - virtual void retargetBinding(QObject *, int); - private: Pointer weakPointer(); diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index e021858509..33fea6bb54 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -183,7 +183,7 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) QQmlBinding *t = this; int status = -1; void *a[] = { &t, 0, &status, &flags }; - QMetaObject::metacall(*m_coreObject, QMetaObject::WriteProperty, idx, a); + QMetaObject::metacall(m_coreObject, QMetaObject::WriteProperty, idx, a); } else { ep->referenceScarceResources(); @@ -194,7 +194,7 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) bool needsErrorLocationData = false; if (!watcher.wasDeleted() && !hasError()) - needsErrorLocationData = !QQmlPropertyPrivate::writeBinding(*m_coreObject, m_core, context(), + needsErrorLocationData = !QQmlPropertyPrivate::writeBinding(m_coreObject, m_core, context(), this, result, isUndefined, flags); if (!watcher.wasDeleted()) { @@ -279,20 +279,12 @@ QString QQmlBinding::expression() const QObject *QQmlBinding::targetObject() const { - if (m_coreObject.hasValue()) return m_coreObject.constValue()->target; - else return *m_coreObject; + return m_coreObject; } int QQmlBinding::targetPropertyIndex() const { - if (m_coreObject.hasValue()) return m_coreObject.constValue()->targetProperty; - else return m_core.encodedIndex(); -} - -void QQmlBinding::retargetBinding(QObject *t, int i) -{ - m_coreObject.value().target = t; - m_coreObject.value().targetProperty = i; + return m_core.encodedIndex(); } void QQmlBinding::setTarget(const QQmlProperty &prop) diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h index 1d833cc72e..8c0a3fbe7e 100644 --- a/src/qml/qml/qqmlbinding_p.h +++ b/src/qml/qml/qqmlbinding_p.h @@ -84,7 +84,6 @@ public: // Inherited from QQmlAbstractBinding virtual void setEnabled(bool, QQmlPropertyPrivate::WriteFlags flags = QQmlPropertyPrivate::DontRemoveBinding); - virtual void retargetBinding(QObject *, int); virtual QString expression() const; virtual QObject *targetObject() const; virtual int targetPropertyIndex() const; @@ -110,12 +109,7 @@ private: inline bool enabledFlag() const; inline void setEnabledFlag(bool); - struct Retarget { - QObject *target; - int targetProperty; - }; - - QPointerValuePair<QObject, Retarget> m_coreObject; + QObject *m_coreObject; QQmlPropertyData m_core; uint m_updating : 1; uint m_enabled : 1; diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 25be1b05c2..8ee4a2d98e 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -869,8 +869,22 @@ QQmlPropertyPrivate::setBinding(QObject *object, int coreIndex, int valueTypeInd } if (newBinding) { - if (newBinding->targetPropertyIndex() != index || newBinding->targetObject() != object) - newBinding->retargetBinding(object, index); + if (newBinding->targetPropertyIndex() != index || newBinding->targetObject() != object) { + QQmlData *data = QQmlData::get(object, true); + if (data && data->propertyCache) { + QQmlPropertyData propertyData = *data->propertyCache->property(coreIndex); + if (valueTypeIndex != -1) { + const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(propertyData.propType); + Q_ASSERT(valueTypeMetaObject); + QMetaProperty vtProp = valueTypeMetaObject->property(valueTypeIndex); + propertyData.setFlags(propertyData.getFlags() | QQmlPropertyData::IsValueTypeVirtual); + propertyData.valueTypeFlags = QQmlPropertyData::flagsForProperty(vtProp); + propertyData.valueTypePropType = vtProp.userType(); + propertyData.valueTypeCoreIndex = valueTypeIndex; + } + static_cast<QQmlBinding *>(newBinding)->setTarget(object, propertyData); + } + } Q_ASSERT(newBinding->targetPropertyIndex() == index); Q_ASSERT(newBinding->targetObject() == object); @@ -931,8 +945,22 @@ QQmlPropertyPrivate::setBindingNoEnable(QObject *object, int coreIndex, int valu binding->removeFromObject(); if (newBinding) { - if (newBinding->targetPropertyIndex() != index || newBinding->targetObject() != object) - newBinding->retargetBinding(object, index); + if (newBinding->targetPropertyIndex() != index || newBinding->targetObject() != object) { + QQmlData *data = QQmlData::get(object, true); + if (data && data->propertyCache) { + QQmlPropertyData propertyData = *data->propertyCache->property(coreIndex); + if (valueTypeIndex != -1) { + const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(propertyData.propType); + Q_ASSERT(valueTypeMetaObject); + QMetaProperty vtProp = valueTypeMetaObject->property(valueTypeIndex); + propertyData.setFlags(propertyData.getFlags() | QQmlPropertyData::IsValueTypeVirtual); + propertyData.valueTypeFlags = QQmlPropertyData::flagsForProperty(vtProp); + propertyData.valueTypePropType = vtProp.userType(); + propertyData.valueTypeCoreIndex = valueTypeIndex; + } + static_cast<QQmlBinding *>(newBinding)->setTarget(object, propertyData); + } + } Q_ASSERT(newBinding->targetPropertyIndex() == index); Q_ASSERT(newBinding->targetObject() == object); |