Smaller cleanups
authorLars Knoll <lars.knoll@theqtcompany.com>
Thu, 16 Apr 2015 12:30:17 +0000 (14:30 +0200)
committerSimon Hausmann <simon.hausmann@theqtcompany.com>
Mon, 27 Apr 2015 07:45:49 +0000 (07:45 +0000)
Change-Id: Ib8a222c26316ad31699d3becaa945ac4035e437b
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/qml/qqmlabstractbinding.cpp
src/qml/qml/qqmlabstractbinding_p.h
src/qml/qml/qqmlobjectcreator.cpp
src/qml/qml/qqmlproperty.cpp
src/qml/qml/qqmlproperty_p.h

index 877ded7..04fbb16 100644 (file)
@@ -110,59 +110,60 @@ Remove the binding from the object.
 */
 void QQmlAbstractBinding::removeFromObject()
 {
-    if (isAddedToObject()) {
-        QObject *obj = targetObject();
-        QQmlData *data = QQmlData::get(obj, false);
-        Q_ASSERT(data);
-
-        int coreIndex;
-        if (QQmlPropertyData::decodeValueTypePropertyIndex(targetPropertyIndex(), &coreIndex) != -1) {
-
-            // Find the value type binding
-            QQmlAbstractBinding *vtbinding = data->bindings;
-            while (vtbinding->targetPropertyIndex() != coreIndex) {
-                vtbinding = vtbinding->nextBinding();
-                Q_ASSERT(vtbinding);
-            }
-            Q_ASSERT(vtbinding->bindingType() == QQmlAbstractBinding::ValueTypeProxy);
-
-            QQmlValueTypeProxyBinding *vtproxybinding =
-                static_cast<QQmlValueTypeProxyBinding *>(vtbinding);
-
-            QQmlAbstractBinding *binding = vtproxybinding->m_bindings;
-            if (binding == this) {
-                vtproxybinding->m_bindings = nextBinding();
-            } else {
-               while (binding->nextBinding() != this) {
-                  binding = binding->nextBinding();
-                  Q_ASSERT(binding);
-               }
-               binding->setNextBinding(nextBinding());
-            }
+    if (!isAddedToObject())
+        return;
+
+    QObject *obj = targetObject();
+    QQmlData *data = QQmlData::get(obj, false);
+    Q_ASSERT(data);
+
+    int coreIndex;
+    if (QQmlPropertyData::decodeValueTypePropertyIndex(targetPropertyIndex(), &coreIndex) != -1) {
+
+        // Find the value type binding
+        QQmlAbstractBinding *vtbinding = data->bindings;
+        while (vtbinding->targetPropertyIndex() != coreIndex) {
+            vtbinding = vtbinding->nextBinding();
+            Q_ASSERT(vtbinding);
+        }
+        Q_ASSERT(vtbinding->bindingType() == QQmlAbstractBinding::ValueTypeProxy);
 
-            // Value type - we don't remove the proxy from the object.  It will sit their happily
-            // doing nothing until it is removed by a write, a binding change or it is reused
-            // to hold more sub-bindings.
+        QQmlValueTypeProxyBinding *vtproxybinding =
+            static_cast<QQmlValueTypeProxyBinding *>(vtbinding);
 
+        QQmlAbstractBinding *binding = vtproxybinding->m_bindings;
+        if (binding == this) {
+            vtproxybinding->m_bindings = nextBinding();
         } else {
+           while (binding->nextBinding() != this) {
+              binding = binding->nextBinding();
+              Q_ASSERT(binding);
+           }
+           binding->setNextBinding(nextBinding());
+        }
 
-            if (data->bindings == this) {
-                data->bindings = nextBinding();
-            } else {
-                QQmlAbstractBinding *binding = data->bindings;
-                while (binding->nextBinding() != this) {
-                    binding = binding->nextBinding();
-                    Q_ASSERT(binding);
-                }
-                binding->setNextBinding(nextBinding());
-            }
+        // Value type - we don't remove the proxy from the object.  It will sit their happily
+        // doing nothing until it is removed by a write, a binding change or it is reused
+        // to hold more sub-bindings.
+
+    } else {
 
-            data->clearBindingBit(coreIndex);
+        if (data->bindings == this) {
+            data->bindings = nextBinding();
+        } else {
+            QQmlAbstractBinding *binding = data->bindings;
+            while (binding->nextBinding() != this) {
+                binding = binding->nextBinding();
+                Q_ASSERT(binding);
+            }
+            binding->setNextBinding(nextBinding());
         }
 
-        setNextBinding(0);
-        setAddedToObject(false);
+        data->clearBindingBit(coreIndex);
     }
+
+    setNextBinding(0);
+    setAddedToObject(false);
 }
 
 void QQmlAbstractBinding::printBindingLoopError(QQmlProperty &prop)
index 2a04dac..d4cb4e0 100644 (file)
@@ -95,16 +95,12 @@ protected:
     void clear();
 
 private:
-    Pointer weakPointer();
-
     friend class QQmlData;
-    friend class QQmlComponentPrivate;
     friend class QQmlValueTypeProxyBinding;
-    friend class QQmlPropertyPrivate;
-    friend class QtSharedPointer::ExternalRefCount<QQmlAbstractBinding>;
-    friend class QV4Bindings;
     friend class QQmlObjectCreator;
 
+    Pointer weakPointer();
+
     typedef QSharedPointer<QQmlAbstractBinding> SharedPointer;
     // To save memory, we also store the rarely used weakPointer() instance in here
     // We also use the flag bits:
index cf438cd..72ff115 100644 (file)
@@ -652,14 +652,12 @@ void QQmlObjectCreator::setupBindings(const QBitArray &bindingsToSkip)
 
     // ### this is best done through type-compile-time binding skip lists.
     if (_valueTypeProperty) {
-        QQmlAbstractBinding *binding =
-            QQmlPropertyPrivate::binding(_bindingTarget, _valueTypeProperty->coreIndex, -1);
+        QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(_bindingTarget, _valueTypeProperty->coreIndex);
 
         if (binding && binding->bindingType() != QQmlAbstractBinding::ValueTypeProxy) {
             QQmlPropertyPrivate::removeBinding(_bindingTarget, _valueTypeProperty->coreIndex, QQmlPropertyPrivate::DestroyOldBinding);
         } else if (binding) {
-            QQmlValueTypeProxyBinding *proxy =
-                static_cast<QQmlValueTypeProxyBinding *>(binding);
+            QQmlValueTypeProxyBinding *proxy = static_cast<QQmlValueTypeProxyBinding *>(binding);
 
             if (qmlTypeForObject(_bindingTarget)) {
                 quint32 bindingSkipList = 0;
index 94b90e9..54dfd3a 100644 (file)
@@ -700,8 +700,7 @@ QQmlPropertyPrivate::binding(const QQmlProperty &that)
     if (!that.d || !that.isProperty() || !that.d->object)
         return 0;
 
-    return binding(that.d->object, that.d->core.coreIndex,
-                   that.d->core.getValueTypeCoreIndex());
+    return binding(that.d->object, that.d->core.encodedIndex());
 }
 
 /*!
@@ -792,26 +791,16 @@ QQmlAbstractBinding *QQmlPropertyPrivate::removeBinding(const QQmlProperty &that
 }
 
 QQmlAbstractBinding *
-QQmlPropertyPrivate::binding(QObject *object, int coreIndex, int valueTypeIndex)
+QQmlPropertyPrivate::binding(QObject *object, int index)
 {
     QQmlData *data = QQmlData::get(object);
     if (!data)
         return 0;
 
-    QQmlPropertyData *propertyData =
-        data->propertyCache?data->propertyCache->property(coreIndex):0;
-    if (propertyData && propertyData->isAlias()) {
-        QQmlVMEMetaObject *vme = QQmlVMEMetaObject::getForProperty(object, coreIndex);
+    findAliasTarget(object, index, &object, &index);
 
-        QObject *aObject = 0; int aCoreIndex = -1; int aValueTypeIndex = -1;
-        if (!vme->aliasTarget(coreIndex, &aObject, &aCoreIndex, &aValueTypeIndex) || aCoreIndex == -1)
-            return 0;
-
-        // This will either be a value type sub-reference or an alias to a value-type sub-reference not both
-        Q_ASSERT(valueTypeIndex == -1 || aValueTypeIndex == -1);
-        aValueTypeIndex = (valueTypeIndex == -1)?aValueTypeIndex:valueTypeIndex;
-        return binding(aObject, aCoreIndex, aValueTypeIndex);
-    }
+    int coreIndex;
+    int valueTypeIndex = QQmlPropertyData::decodeValueTypePropertyIndex(index, &coreIndex);
 
     if (!data->hasBindingBit(coreIndex))
         return 0;
index 9b73566..7bbb600 100644 (file)
@@ -116,8 +116,7 @@ public:
     static QQmlAbstractBinding *removeBinding(const QQmlProperty &that, BindingFlag flag = None);
     static QQmlAbstractBinding *removeBinding(QObject *o, int index, QQmlPropertyPrivate::BindingFlag flags = None);
     static QQmlAbstractBinding *removeBinding(QQmlAbstractBinding *b, BindingFlag flag = None);
-    static QQmlAbstractBinding *binding(QObject *, int coreIndex,
-                                                int valueTypeIndex /* -1 */);
+    static QQmlAbstractBinding *binding(QObject *, int index);
 
     static QQmlPropertyData saveValueType(const QQmlPropertyData &,
                                           const QMetaObject *, int,