aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlproperty.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-04-21 16:42:56 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-10 07:55:36 +0000
commit37d02d62d8d14fdaa0884f96f7840661413a95c2 (patch)
tree8e3f3dd9dafd574b99ca686e657d7e73f8f7eef5 /src/qml/qml/qqmlproperty.cpp
parenteb7db5934b453eea2946ed7ae9a188c44467cf23 (diff)
Make bindings refcounted
Refcounting our bindings greatly simplifies our memory management of the objects and ensures we safely clean them all up. In addition, it allows us to remove the m_mePtr and weak reference handling from QQmlAbstractBinding as we can safely handle this through the same mechanism. Change-Id: If23ebc8be276096146952b0008b62018f5d57faf Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r--src/qml/qml/qqmlproperty.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index e4b2743b9b..0181d138af 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -725,13 +725,14 @@ QQmlPropertyPrivate::setBinding(const QQmlProperty &that, QQmlAbstractBinding *n
}
if (!that.d || !that.isProperty() || !that.d->object) {
- newBinding->destroy();
+ if (!newBinding->ref)
+ delete newBinding;
return;
}
setBinding(newBinding);
}
-static QQmlAbstractBinding *removeOldBinding(QObject *object, int index, QQmlPropertyPrivate::BindingFlags flags)
+static void removeOldBinding(QObject *object, int index, QQmlPropertyPrivate::BindingFlags flags = QQmlPropertyPrivate::None)
{
int coreIndex;
int valueTypeIndex = QQmlPropertyData::decodeValueTypePropertyIndex(index, &coreIndex);
@@ -739,55 +740,49 @@ static QQmlAbstractBinding *removeOldBinding(QObject *object, int index, QQmlPro
QQmlData *data = QQmlData::get(object, false);
if (!data || !data->hasBindingBit(coreIndex))
- return 0;
+ return;
- QQmlAbstractBinding *oldBinding = data->bindings;
+ QQmlAbstractBinding::Ptr oldBinding;
+ oldBinding = data->bindings;
while (oldBinding && oldBinding->targetPropertyIndex() != coreIndex)
oldBinding = oldBinding->nextBinding();
if (!oldBinding)
- return 0;
+ return;
if (valueTypeIndex != -1 && oldBinding->isValueTypeProxy())
- oldBinding = static_cast<QQmlValueTypeProxyBinding *>(oldBinding)->binding(index);
+ oldBinding = static_cast<QQmlValueTypeProxyBinding *>(oldBinding.data())->binding(index);
if (!oldBinding)
- return 0;
+ return;
- oldBinding->removeFromObject();
if (!(flags & QQmlPropertyPrivate::DontEnable))
oldBinding->setEnabled(false, 0);
-
- if (flags & QQmlPropertyPrivate::DestroyOldBinding) {
- oldBinding->destroy();
- return 0;
- }
-
- return oldBinding;
+ oldBinding->removeFromObject();
}
-QQmlAbstractBinding *QQmlPropertyPrivate::removeBinding(QQmlAbstractBinding *b, QQmlPropertyPrivate::BindingFlag flags)
+void QQmlPropertyPrivate::removeBinding(QQmlAbstractBinding *b)
{
- return removeBinding(b->targetObject(), b->targetPropertyIndex(), flags);
+ removeBinding(b->targetObject(), b->targetPropertyIndex());
}
-QQmlAbstractBinding *QQmlPropertyPrivate::removeBinding(QObject *o, int index, QQmlPropertyPrivate::BindingFlag flags)
+void QQmlPropertyPrivate::removeBinding(QObject *o, int index)
{
Q_ASSERT(o);
QObject *target;
int targetIndex;
findAliasTarget(o, index, &target, &targetIndex);
- return removeOldBinding(target, targetIndex, flags);
+ removeOldBinding(target, targetIndex);
}
-QQmlAbstractBinding *QQmlPropertyPrivate::removeBinding(const QQmlProperty &that, BindingFlag flags)
+void QQmlPropertyPrivate::removeBinding(const QQmlProperty &that)
{
if (!that.d || !that.isProperty() || !that.d->object)
- return 0;
+ return;
- return removeBinding(that.d->object, that.d->core.encodedIndex(), flags);
+ removeBinding(that.d->object, that.d->core.encodedIndex());
}
QQmlAbstractBinding *
@@ -1164,7 +1159,7 @@ QQmlPropertyPrivate::writeValueProperty(QObject *object,
{
// Remove any existing bindings on this property
if (!(flags & DontRemoveBinding) && object)
- removeBinding(object, core.encodedIndex(), DestroyOldBinding);
+ removeBinding(object, core.encodedIndex());
bool rv = false;
if (core.isValueTypeVirtual()) {