diff options
| author | Patrick Stewart <patstew@gmail.com> | 2022-11-09 00:30:42 +0000 |
|---|---|---|
| committer | Patrick Stewart <patstew@gmail.com> | 2022-11-30 21:21:03 +0000 |
| commit | 4fb96669e33c9e1e3edc1cf2e472f921ddee6484 (patch) | |
| tree | 801c5c4256c2b8302760b3dcd3c118d2d12df93c /src/corelib/kernel/qobject.cpp | |
| parent | 84d4b21f697f6be064a9baef628d313a7f059ac2 (diff) | |
QBindable: Make ordinary Q_PROPERTYs bindable
Implements an adaptor from the notification signal of a Q_PROPERTY to
QBindable. The Q_PROPERTY does not need to be BINDABLE, but can still
be bound or used in a binding.
[ChangeLog][Core][Q_PROPERTY] Q_PROPERTYs without BINDABLE can be wrapped in QBindable to make them usable in bindings
Change-Id: Id0ca5444b93a371ba8720a38f3607925d393d98a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
| -rw-r--r-- | src/corelib/kernel/qobject.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index fd7439f3e2b..81bcf19114b 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -5358,6 +5358,31 @@ inline bool QObjectPrivate::removeConnection(QObjectPrivate::Connection *c) return true; } +/*! + \internal + + Used by QPropertyAdaptorSlotObject to get an existing instance for a property, if available + */ +QtPrivate::QPropertyAdaptorSlotObject * +QObjectPrivate::getPropertyAdaptorSlotObject(const QMetaProperty &property) +{ + if (auto conns = connections.loadRelaxed()) { + Q_Q(QObject); + const QMetaObject *metaObject = q->metaObject(); + int signal_index = methodIndexToSignalIndex(&metaObject, property.notifySignalIndex()); + auto connectionList = conns->connectionsForSignal(signal_index); + for (auto c = connectionList.first.loadRelaxed(); c; + c = c->nextConnectionList.loadRelaxed()) { + if (c->isSlotObject) { + if (auto p = QtPrivate::QPropertyAdaptorSlotObject::cast(c->slotObj, + property.propertyIndex())) + return p; + } + } + } + return nullptr; +} + /*! \class QMetaObject::Connection \inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection. |
