From 2540a60e39bafaac3a0c373f52270003d4308bf5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 13 Apr 2015 15:42:03 +0200 Subject: Make removal of bindings explicit This simplifies the code for further refactoring. Change-Id: I6bcb5ce397f642242af80ce37dc8bba1fa9bf3f5 Reviewed-by: Simon Hausmann --- src/qml/debugger/qqmlenginedebugservice.cpp | 2 +- src/qml/qml/qqmlobjectcreator.cpp | 4 +-- src/qml/qml/qqmlproperty.cpp | 49 +++++++++++++++++------------ src/qml/qml/qqmlproperty_p.h | 2 ++ src/qml/qml/qqmlvmemetaobject.cpp | 2 +- src/qml/types/qqmlbind.cpp | 3 +- 6 files changed, 36 insertions(+), 26 deletions(-) (limited to 'src/qml') diff --git a/src/qml/debugger/qqmlenginedebugservice.cpp b/src/qml/debugger/qqmlenginedebugservice.cpp index da01d00f17..6f8a67573c 100644 --- a/src/qml/debugger/qqmlenginedebugservice.cpp +++ b/src/qml/debugger/qqmlenginedebugservice.cpp @@ -681,7 +681,7 @@ bool QQmlEngineDebugService::resetBinding(int objectId, const QString &propertyN QQmlProperty property(object, propertyName); QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(property); if (oldBinding) { - QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::setBinding(property, 0); + QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::removeBinding(property); if (oldBinding) oldBinding->destroy(); } diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index ba18967150..a1787f67fd 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -66,7 +66,7 @@ static void removeBindingOnProperty(QObject *o, int index) { int coreIndex; int valueTypeIndex = QQmlPropertyData::decodeValueTypePropertyIndex(index, &coreIndex); - QQmlAbstractBinding *binding = QQmlPropertyPrivate::setBinding(o, coreIndex, valueTypeIndex, 0); + QQmlAbstractBinding *binding = QQmlPropertyPrivate::removeBinding(o, coreIndex, valueTypeIndex); if (binding) binding->destroy(); } @@ -664,7 +664,7 @@ void QQmlObjectCreator::setupBindings(const QBitArray &bindingsToSkip) QQmlPropertyPrivate::binding(_bindingTarget, _valueTypeProperty->coreIndex, -1); if (binding && binding->bindingType() != QQmlAbstractBinding::ValueTypeProxy) { - QQmlPropertyPrivate::setBinding(_bindingTarget, _valueTypeProperty->coreIndex, -1, 0); + QQmlPropertyPrivate::removeBinding(_bindingTarget, _valueTypeProperty->coreIndex, -1); binding->destroy(); } else if (binding) { QQmlValueTypeProxyBinding *proxy = diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 55f4def6a8..3ab312036b 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -719,30 +719,35 @@ QQmlPropertyPrivate::binding(const QQmlProperty &that) */ QQmlAbstractBinding * QQmlPropertyPrivate::setBinding(const QQmlProperty &that, - QQmlAbstractBinding *newBinding, - WriteFlags flags) + QQmlAbstractBinding *newBinding, + WriteFlags flags) { + if (!newBinding) + removeBinding(that); + if (!that.d || !that.isProperty() || !that.d->object) { - if (newBinding) - newBinding->destroy(); + newBinding->destroy(); return 0; } - if (newBinding) { - // In the case that the new binding is provided, we must target the property it - // is associated with. If we don't do this, retargetBinding() can fail. - QObject *object = newBinding->object(); - int pi = newBinding->propertyIndex(); + // In the case that the new binding is provided, we must target the property it + // is associated with. If we don't do this, retargetBinding() can fail. + QObject *object = newBinding->object(); + int pi = newBinding->propertyIndex(); - int core; - int vt = QQmlPropertyData::decodeValueTypePropertyIndex(pi, &core); + int core; + int vt = QQmlPropertyData::decodeValueTypePropertyIndex(pi, &core); - return setBinding(object, core, vt, newBinding, flags); - } else { - return setBinding(that.d->object, that.d->core.coreIndex, - that.d->core.getValueTypeCoreIndex(), - newBinding, flags); - } + return setBinding(object, core, vt, newBinding, flags); +} + +QQmlAbstractBinding *QQmlPropertyPrivate::removeBinding(const QQmlProperty &that) +{ + if (!that.d || !that.isProperty() || !that.d->object) + return 0; + + return removeBinding(that.d->object, that.d->core.coreIndex, + that.d->core.getValueTypeCoreIndex()); } QQmlAbstractBinding * @@ -877,6 +882,11 @@ QQmlPropertyPrivate::setBinding(QObject *object, int coreIndex, int valueTypeInd return binding; } +QQmlAbstractBinding *QQmlPropertyPrivate::removeBinding(QObject *object, int coreIndex, int valueTypeIndex) +{ + return setBinding(object, coreIndex, valueTypeIndex, 0); +} + QQmlAbstractBinding * QQmlPropertyPrivate::setBindingNoEnable(QObject *object, int coreIndex, int valueTypeIndex, QQmlAbstractBinding *newBinding) @@ -1212,9 +1222,8 @@ QQmlPropertyPrivate::writeValueProperty(QObject *object, { // Remove any existing bindings on this property if (!(flags & DontRemoveBinding) && object) { - QQmlAbstractBinding *binding = setBinding(object, core.coreIndex, - core.getValueTypeCoreIndex(), - 0, flags); + QQmlAbstractBinding *binding = removeBinding(object, core.coreIndex, + core.getValueTypeCoreIndex()); if (binding) binding->destroy(); } diff --git a/src/qml/qml/qqmlproperty_p.h b/src/qml/qml/qqmlproperty_p.h index ece168925b..4b51128fef 100644 --- a/src/qml/qml/qqmlproperty_p.h +++ b/src/qml/qml/qqmlproperty_p.h @@ -108,6 +108,7 @@ public: int valueTypeIndex /* -1 */, QQmlAbstractBinding *, WriteFlags flags = DontRemoveBinding); + static QQmlAbstractBinding *removeBinding(QObject *object, int coreIndex, int valueTypeIndex /* -1 */); static QQmlAbstractBinding *setBindingNoEnable(QObject *, int coreIndex, int valueTypeIndex /* -1 */, QQmlAbstractBinding *); @@ -132,6 +133,7 @@ public: static QQmlAbstractBinding *setBinding(const QQmlProperty &that, QQmlAbstractBinding *, WriteFlags flags = DontRemoveBinding); + static QQmlAbstractBinding *removeBinding(const QQmlProperty &that); static QQmlBoundSignalExpression *signalExpression(const QQmlProperty &that); static QQmlBoundSignalExpressionPointer setSignalExpression(const QQmlProperty &that, QQmlBoundSignalExpression *); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 01b37798f8..12600229a9 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -875,7 +875,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) if (flags & QQmlPropertyPrivate::RemoveBindingOnAliasWrite) { QQmlData *targetData = QQmlData::get(target); if (targetData && targetData->hasBindingBit(d->propertyIndex())) { - QQmlAbstractBinding *binding = QQmlPropertyPrivate::setBinding(target, d->propertyIndex(), d->isValueTypeAlias()?d->valueTypeIndex():-1, 0); + QQmlAbstractBinding *binding = QQmlPropertyPrivate::removeBinding(target, d->propertyIndex(), d->isValueTypeAlias() ? d->valueTypeIndex() : -1); if (binding) binding->destroy(); } } diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp index 7814fa6d56..efa182bf87 100644 --- a/src/qml/types/qqmlbind.cpp +++ b/src/qml/types/qqmlbind.cpp @@ -287,8 +287,7 @@ void QQmlBind::eval() } //save any set binding for restoration - QQmlAbstractBinding *tmp; - tmp = QQmlPropertyPrivate::setBinding(d->prop, 0); + QQmlAbstractBinding *tmp = QQmlPropertyPrivate::removeBinding(d->prop); if (tmp && d->prevBind) tmp->destroy(); else if (!d->prevBind) -- cgit v1.2.3