aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-04-13 15:42:03 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-25 18:50:14 +0000
commit2540a60e39bafaac3a0c373f52270003d4308bf5 (patch)
tree5f8cb7baf8dfa0eefdedae8389defc8f9a40e78e /src
parent4c365e4d4d125c8c874c3ffcbeefbdcd6453ea28 (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')
-rw-r--r--src/qml/debugger/qqmlenginedebugservice.cpp2
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp4
-rw-r--r--src/qml/qml/qqmlproperty.cpp49
-rw-r--r--src/qml/qml/qqmlproperty_p.h2
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp2
-rw-r--r--src/qml/types/qqmlbind.cpp3
-rw-r--r--src/quick/items/qquickstateoperations.cpp42
-rw-r--r--src/quick/util/qquickpropertychanges.cpp4
-rw-r--r--src/quick/util/qquickstate.cpp10
-rw-r--r--src/quick/util/qquicktransitionmanager.cpp6
10 files changed, 67 insertions, 57 deletions
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)
diff --git a/src/quick/items/qquickstateoperations.cpp b/src/quick/items/qquickstateoperations.cpp
index 579919db27..b2b9c75c25 100644
--- a/src/quick/items/qquickstateoperations.cpp
+++ b/src/quick/items/qquickstateoperations.cpp
@@ -1024,31 +1024,31 @@ void QQuickAnchorChanges::execute(Reason reason)
//reset any anchors that have been specified as "undefined"
if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::LeftAnchor) {
targetPrivate->anchors()->resetLeft();
- QQmlPropertyPrivate::setBinding(d->leftProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->leftProp);
}
if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::RightAnchor) {
targetPrivate->anchors()->resetRight();
- QQmlPropertyPrivate::setBinding(d->rightProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->rightProp);
}
if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::HCenterAnchor) {
targetPrivate->anchors()->resetHorizontalCenter();
- QQmlPropertyPrivate::setBinding(d->hCenterProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->hCenterProp);
}
if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::TopAnchor) {
targetPrivate->anchors()->resetTop();
- QQmlPropertyPrivate::setBinding(d->topProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->topProp);
}
if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::BottomAnchor) {
targetPrivate->anchors()->resetBottom();
- QQmlPropertyPrivate::setBinding(d->bottomProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->bottomProp);
}
if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::VCenterAnchor) {
targetPrivate->anchors()->resetVerticalCenter();
- QQmlPropertyPrivate::setBinding(d->vCenterProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->vCenterProp);
}
if (d->anchorSet->d_func()->resetAnchors & QQuickAnchors::BaselineAnchor) {
targetPrivate->anchors()->resetBaseline();
- QQmlPropertyPrivate::setBinding(d->baselineProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->baselineProp);
}
//set any anchors that have been specified
@@ -1083,49 +1083,49 @@ void QQuickAnchorChanges::reverse(Reason reason)
//reset any anchors set by the state
if (d->leftBinding) {
targetPrivate->anchors()->resetLeft();
- QQmlPropertyPrivate::setBinding(d->leftBinding->property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->leftBinding->property());
if (reason == ActualChange) {
d->leftBinding->destroy(); d->leftBinding = 0;
}
}
if (d->rightBinding) {
targetPrivate->anchors()->resetRight();
- QQmlPropertyPrivate::setBinding(d->rightBinding->property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->rightBinding->property());
if (reason == ActualChange) {
d->rightBinding->destroy(); d->rightBinding = 0;
}
}
if (d->hCenterBinding) {
targetPrivate->anchors()->resetHorizontalCenter();
- QQmlPropertyPrivate::setBinding(d->hCenterBinding->property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->hCenterBinding->property());
if (reason == ActualChange) {
d->hCenterBinding->destroy(); d->hCenterBinding = 0;
}
}
if (d->topBinding) {
targetPrivate->anchors()->resetTop();
- QQmlPropertyPrivate::setBinding(d->topBinding->property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->topBinding->property());
if (reason == ActualChange) {
d->topBinding->destroy(); d->topBinding = 0;
}
}
if (d->bottomBinding) {
targetPrivate->anchors()->resetBottom();
- QQmlPropertyPrivate::setBinding(d->bottomBinding->property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->bottomBinding->property());
if (reason == ActualChange) {
d->bottomBinding->destroy(); d->bottomBinding = 0;
}
}
if (d->vCenterBinding) {
targetPrivate->anchors()->resetVerticalCenter();
- QQmlPropertyPrivate::setBinding(d->vCenterBinding->property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->vCenterBinding->property());
if (reason == ActualChange) {
d->vCenterBinding->destroy(); d->vCenterBinding = 0;
}
}
if (d->baselineBinding) {
targetPrivate->anchors()->resetBaseline();
- QQmlPropertyPrivate::setBinding(d->baselineBinding->property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->baselineBinding->property());
if (reason == ActualChange) {
d->baselineBinding->destroy(); d->baselineBinding = 0;
}
@@ -1333,31 +1333,31 @@ void QQuickAnchorChanges::clearBindings()
d->anchorSet->d_func()->usedAnchors;
if (d->applyOrigLeft || (combined & QQuickAnchors::LeftAnchor)) {
targetPrivate->anchors()->resetLeft();
- QQmlPropertyPrivate::setBinding(d->leftProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->leftProp);
}
if (d->applyOrigRight || (combined & QQuickAnchors::RightAnchor)) {
targetPrivate->anchors()->resetRight();
- QQmlPropertyPrivate::setBinding(d->rightProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->rightProp);
}
if (d->applyOrigHCenter || (combined & QQuickAnchors::HCenterAnchor)) {
targetPrivate->anchors()->resetHorizontalCenter();
- QQmlPropertyPrivate::setBinding(d->hCenterProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->hCenterProp);
}
if (d->applyOrigTop || (combined & QQuickAnchors::TopAnchor)) {
targetPrivate->anchors()->resetTop();
- QQmlPropertyPrivate::setBinding(d->topProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->topProp);
}
if (d->applyOrigBottom || (combined & QQuickAnchors::BottomAnchor)) {
targetPrivate->anchors()->resetBottom();
- QQmlPropertyPrivate::setBinding(d->bottomProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->bottomProp);
}
if (d->applyOrigVCenter || (combined & QQuickAnchors::VCenterAnchor)) {
targetPrivate->anchors()->resetVerticalCenter();
- QQmlPropertyPrivate::setBinding(d->vCenterProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->vCenterProp);
}
if (d->applyOrigBaseline || (combined & QQuickAnchors::BaselineAnchor)) {
targetPrivate->anchors()->resetBaseline();
- QQmlPropertyPrivate::setBinding(d->baselineProp, 0);
+ QQmlPropertyPrivate::removeBinding(d->baselineProp);
}
}
diff --git a/src/quick/util/qquickpropertychanges.cpp b/src/quick/util/qquickpropertychanges.cpp
index 6c333c6b13..b190557c96 100644
--- a/src/quick/util/qquickpropertychanges.cpp
+++ b/src/quick/util/qquickpropertychanges.cpp
@@ -560,7 +560,7 @@ void QQuickPropertyChanges::changeValue(const QString &name, const QVariant &val
if (state() && state()->isStateActive()) {
QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(d->property(name));
if (oldBinding) {
- QQmlPropertyPrivate::setBinding(d->property(name), 0);
+ QQmlPropertyPrivate::removeBinding(d->property(name));
oldBinding->destroy();
}
d->property(name).write(value);
@@ -626,7 +626,7 @@ void QQuickPropertyChanges::changeExpression(const QString &name, const QString
if (state() && state()->isStateActive()) {
QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(d->property(name));
if (oldBinding) {
- QQmlPropertyPrivate::setBinding(d->property(name), 0);
+ QQmlPropertyPrivate::removeBinding(d->property(name));
oldBinding->destroy();
}
diff --git a/src/quick/util/qquickstate.cpp b/src/quick/util/qquickstate.cpp
index 98d7a76c7e..684b0687c1 100644
--- a/src/quick/util/qquickstate.cpp
+++ b/src/quick/util/qquickstate.cpp
@@ -361,7 +361,7 @@ void QQuickState::cancel()
void QQuickStateAction::deleteFromBinding()
{
if (fromBinding) {
- QQmlPropertyPrivate::setBinding(property, 0);
+ QQmlPropertyPrivate::removeBinding(property);
fromBinding->destroy();
fromBinding = 0;
}
@@ -437,7 +437,7 @@ bool QQuickState::removeEntryFromRevertList(QObject *target, const QString &name
if (simpleAction.property().object() == target && simpleAction.property().name() == name) {
QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(simpleAction.property());
if (oldBinding) {
- QQmlPropertyPrivate::setBinding(simpleAction.property(), 0);
+ QQmlPropertyPrivate::removeBinding(simpleAction.property());
oldBinding->destroy();
}
@@ -475,7 +475,7 @@ void QQuickState::removeAllEntriesFromRevertList(QObject *target)
if (simpleAction.property().object() == target) {
QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(simpleAction.property());
if (oldBinding) {
- QQmlPropertyPrivate::setBinding(simpleAction.property(), 0);
+ QQmlPropertyPrivate::removeBinding(simpleAction.property());
oldBinding->destroy();
}
@@ -503,7 +503,7 @@ void QQuickState::addEntriesToRevertList(const QList<QQuickStateAction> &actionL
if (!action.toBinding.isNull()) {
QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::binding(simpleAction.property());
if (oldBinding)
- QQmlPropertyPrivate::setBinding(simpleAction.property(), 0);
+ QQmlPropertyPrivate::removeBinding(simpleAction.property());
QQmlPropertyPrivate::setBinding(simpleAction.property(), action.toBinding.data(), QQmlPropertyPrivate::DontRemoveBinding);
}
@@ -664,7 +664,7 @@ void QQuickState::apply(QQuickTransition *trans, QQuickState *revert)
if (!found) {
QVariant cur = d->revertList.at(ii).property().read();
QQmlAbstractBinding *delBinding =
- QQmlPropertyPrivate::setBinding(d->revertList.at(ii).property(), 0);
+ QQmlPropertyPrivate::removeBinding(d->revertList.at(ii).property());
if (delBinding)
delBinding->destroy();
diff --git a/src/quick/util/qquicktransitionmanager.cpp b/src/quick/util/qquicktransitionmanager.cpp
index 832596d9a2..81a3c34dc0 100644
--- a/src/quick/util/qquicktransitionmanager.cpp
+++ b/src/quick/util/qquicktransitionmanager.cpp
@@ -131,7 +131,7 @@ void QQuickTransitionManager::transition(const QList<QQuickStateAction> &list,
if (action.toBinding)
d->bindingsList << action;
if (action.fromBinding)
- QQmlPropertyPrivate::setBinding(action.property, 0); // Disable current binding
+ QQmlPropertyPrivate::removeBinding(action.property); // Disable current binding
if (action.event && action.event->changesBindings()) { //### assume isReversable()?
d->bindingsList << action;
action.event->clearBindings();
@@ -192,7 +192,7 @@ void QQuickTransitionManager::transition(const QList<QQuickStateAction> &list,
}
if (action.toBinding)
- QQmlPropertyPrivate::setBinding(action.property, 0); // Make sure this is disabled during the transition
+ QQmlPropertyPrivate::removeBinding(action.property); // Make sure this is disabled during the transition
QQmlPropertyPrivate::write(action.property, action.fromValue, QQmlPropertyPrivate::BypassInterceptor | QQmlPropertyPrivate::DontRemoveBinding);
}
@@ -270,7 +270,7 @@ void QQuickTransitionManager::cancel()
for(int i = 0; i < d->bindingsList.count(); ++i) {
QQuickStateAction action = d->bindingsList[i];
if (!action.toBinding.isNull() && action.deletableToBinding) {
- QQmlPropertyPrivate::setBinding(action.property, 0);
+ QQmlPropertyPrivate::removeBinding(action.property);
action.toBinding.data()->destroy();
action.toBinding.clear();
action.deletableToBinding = false;