diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-08-22 17:21:36 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-09-02 22:44:29 +0200 |
commit | ad32ac5b4f05c9eed1fb7a93ee7947050d840a19 (patch) | |
tree | 5f14ae7a6a588ad3c9400058943f675556a403a9 /src/corelib/kernel/qmetaobject.cpp | |
parent | 3e6c09279304fbde1860288717958e28377b9a9c (diff) |
Make bindings introspectable through moc
Add a new BINDABLE declaration to the Q_PROPERTY() macro that tells moc
where to find the QBindable for the property.
Add a QUntypedBindable base class to QBindable<T> that gives access to
generic functionality and checks argument compatibility at runtime.
QBindable<T> will still do static checking at compile time.
Add QMetaProperty::isBindable() and QMetaProperty::bindable()
to be able to dynamically access the binding functionality.
Change-Id: Ic7b08ae2cde83fd43e627d813a886e1de01fa3dc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index f0cef22b6f..ef042317c1 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -3251,6 +3251,23 @@ bool QMetaProperty::reset(QObject *object) const QMetaObject::metacall(object, QMetaObject::ResetProperty, data.index(mobj) + mobj->propertyOffset(), argv); return true; } + +/*! + \since 6.0 + Returns the bindable interface for the property on a given \a object. + + If the property doesn't support bindings, the returned interface will be + invalid. + + \sa QUntypedBindable, QProperty, isBindable() +*/ +QUntypedBindable QMetaProperty::bindable(QObject *object) const +{ + QUntypedBindable bindable; + void * argv[1] { &bindable }; + mobj->metacall(object, QMetaObject::BindableProperty, data.index(mobj) + mobj->propertyOffset(), argv); + return bindable; +} /*! \since 5.5 @@ -3509,16 +3526,18 @@ bool QMetaProperty::isRequired() const /*! \since 6.0 - Returns \c true if the property is implemented using a QProperty member; otherwise returns \c false. + Returns \c true if the \c{Q_PROPERTY()} exposes binding functionality; otherwise returns false. + + This implies that you can create bindings that use this property as a dependency or install QPropertyObserver + objects on this property. Unless the property is readonly, you can also set a binding on this property. - This can be used to detect the availability of QProperty related meta-call types ahead of - performing the call itself. + \sa QProperty, isReadOnly(), bindable() */ -bool QMetaProperty::isQProperty() const +bool QMetaProperty::isBindable() const { if (!mobj) return false; - return data.flags() & IsQProperty; + return (data.flags() & Bindable); } /*! |