diff options
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); |