diff options
author | Thomas McGuire <thomas.mcguire@kdab.com> | 2012-07-17 17:35:53 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-22 12:25:33 +0200 |
commit | 26ea8e01e9ee2a8c8c09266147b94c9ac92d09f9 (patch) | |
tree | c058873b0082b18a09dde27f7ee124285e696807 /src/qml/qml/qqmlabstractbinding_p.h | |
parent | 2cc57f1e33cc4d739b1b76c605e6241fa0f134a8 (diff) |
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 <kent.hansen@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlabstractbinding_p.h')
-rw-r--r-- | src/qml/qml/qqmlabstractbinding_p.h | 30 |
1 files changed, 26 insertions, 4 deletions
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<typename T> - 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<typename T> -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<T *>(This); |