summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-03-07 20:26:56 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-04-16 20:33:02 +0200
commite835bccb1e53c2eeb20b5f95a2c0ea4beb547b7c (patch)
tree2ddab4af3bab9cfbce9e00c387b3aaa96b98f59b /src
parenta794c5e287381bd056008b20ae55f9b1e0acf138 (diff)
QPropertyBinding: Add sticky mode
A sticky QPropertyBinding is a binding that does not get removed when a write occurs. This is used in the QML engine to implement support for the QQmlPropertyData::DontRemoveBinding flag. Task-number: QTBUG-91689 Change-Id: Ib575b49abe634215318ccc7ba46212cc21eb4dad Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qproperty.cpp3
-rw-r--r--src/corelib/kernel/qproperty_p.h8
2 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp
index a5354532d2..7c8477e31a 100644
--- a/src/corelib/kernel/qproperty.cpp
+++ b/src/corelib/kernel/qproperty.cpp
@@ -508,6 +508,9 @@ void QPropertyBindingData::removeBinding_helper()
auto *existingBinding = d.binding();
Q_ASSERT(existingBinding);
+ if (existingBinding->isSticky()) {
+ return;
+ }
auto observer = existingBinding->takeObservers();
d_ref() = 0;
diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h
index 58a000e9bf..6a074efebb 100644
--- a/src/corelib/kernel/qproperty_p.h
+++ b/src/corelib/kernel/qproperty_p.h
@@ -184,6 +184,11 @@ private:
bool hasBindingWrapper:1;
// used to detect binding loops for eagerly evaluated properties
bool isQQmlPropertyBinding:1;
+ /* a sticky binding does not get removed in removeBinding
+ this is used to support QQmlPropertyData::DontRemoveBinding
+ in qtdeclarative
+ */
+ bool m_sticky:1;
const QtPrivate::BindingFunctionVTable *vtable;
@@ -234,11 +239,14 @@ public:
size_t dependencyObserverCount = 0;
bool isUpdating() {return updating;}
+ void setSticky(bool keep = true) {m_sticky = keep;}
+ bool isSticky() {return m_sticky;}
QPropertyBindingPrivate(QMetaType metaType, const QtPrivate::BindingFunctionVTable *vtable,
const QPropertyBindingSourceLocation &location, bool isQQmlPropertyBinding=false)
: hasBindingWrapper(false)
, isQQmlPropertyBinding(isQQmlPropertyBinding)
+ , m_sticky(false)
, vtable(vtable)
, location(location)
, metaType(metaType)