From 26ea8e01e9ee2a8c8c09266147b94c9ac92d09f9 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 17 Jul 2012 17:35:53 +0200 Subject: Make connectNotify() work with QML Call connectNotify() and disconnectNotify() in QQmlNotifierEndPoint, which works for QML signal handlers and for QML bindings. Task-number: QTBUG-11284 Change-Id: Ic9a08ee6687e5c7e606f315c8fb30eec1493cd83 Reviewed-by: Kent Hansen --- src/qml/qml/qqmlabstractbinding_p.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/qml/qml/qqmlabstractbinding_p.h') diff --git a/src/qml/qml/qqmlabstractbinding_p.h b/src/qml/qml/qqmlabstractbinding_p.h index ae92077add..1ce0a23149 100644 --- a/src/qml/qml/qqmlabstractbinding_p.h +++ b/src/qml/qml/qqmlabstractbinding_p.h @@ -63,8 +63,24 @@ QT_BEGIN_NAMESPACE class Q_QML_PRIVATE_EXPORT QQmlAbstractBinding { public: + enum DestroyMode { + + // The binding should disconnect itself upon destroy + DisconnectBinding, + + // The binding doesn't need to disconnect itself, but it can if it wants to. + // + // This is used in QQmlData::destroyed() - at the point at which the bindings are + // destroyed, the notifiers are already disconnected, so no need to disconnect each + // binding again. + // + // Bindings can use this flag to speed up destruction, especially for v4 bindings + // disconnecting a single binding might be slow. + KeepBindingConnected + }; + struct VTable { - void (*destroy)(QQmlAbstractBinding *); + void (*destroy)(QQmlAbstractBinding *, DestroyMode destroyMode); QString (*expression)(const QQmlAbstractBinding *); int (*propertyIndex)(const QQmlAbstractBinding *); QObject *(*object)(const QQmlAbstractBinding *); @@ -82,7 +98,9 @@ public: // Bindings are free to implement their own memory management, so the delete operator is // not necessarily safe. The default implementation clears the binding, removes it from // the object and calls delete. - void destroy() { vtable()->destroy(this); } + void destroy(DestroyMode destroyMode = DisconnectBinding) + { vtable()->destroy(this, destroyMode); } + QString expression() const { return vtable()->expression(this); } // Should return the encoded property index for the binding. Should return this value @@ -108,7 +126,7 @@ public: // Default implementation for some VTable functions template - static void default_destroy(QQmlAbstractBinding *); + static void default_destroy(QQmlAbstractBinding *, DestroyMode); static QString default_expression(const QQmlAbstractBinding *); static void default_retargetBinding(QQmlAbstractBinding *, QObject *, int); @@ -182,8 +200,12 @@ QQmlAbstractBinding::BindingType QQmlAbstractBinding::bindingType() const } template -void QQmlAbstractBinding::default_destroy(QQmlAbstractBinding *This) +void QQmlAbstractBinding::default_destroy(QQmlAbstractBinding *This, DestroyMode mode) { + // Assume the binding disconnects itself in the destructor, which for example QQmlBinding + // does in the destructor of its base class, QQmlJavaScriptExpression + Q_UNUSED(mode); + This->removeFromObject(); This->clear(); delete static_cast(This); -- cgit v1.2.3