diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-04-13 15:42:03 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-25 18:50:14 +0000 |
commit | 2540a60e39bafaac3a0c373f52270003d4308bf5 (patch) | |
tree | 5f8cb7baf8dfa0eefdedae8389defc8f9a40e78e /src/qml/qml/qqmlproperty.cpp | |
parent | 4c365e4d4d125c8c874c3ffcbeefbdcd6453ea28 (diff) |
Make removal of bindings explicit
This simplifies the code for further refactoring.
Change-Id: I6bcb5ce397f642242af80ce37dc8bba1fa9bf3f5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 49 |
1 files changed, 29 insertions, 20 deletions
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(); } |