summaryrefslogtreecommitdiffstats
path: root/src/interfaceframework
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2024-08-06 13:59:23 +0200
committerDominik Holland <dominik.holland@qt.io>2024-08-07 15:00:18 +0200
commit7797b789a49fcc20fc7733b55306cf225d7ffd1a (patch)
tree78f12a667acf6f42f0c9cf438e874db6576101ba /src/interfaceframework
parent04933fcf676573ad6b78e562958192da3e66d9d0 (diff)
Register QIfPendingReply as a value type for QML
Although QIfPendingReply is a template class, only it's base class QIfPendingReplyBase is usable from QML. But as we use the template class in the C++ signature, we need to go some extra miles for the QML registration. This is now done by QIF_DECLARE_PENDINGREPLY which needs to be called for new types and is now automatically done for auto generated structs. All basic types are already registered and can be used without any additional steps. Pick-to: 6.8 Change-Id: Ibd82a1dd5dcd9bae0e32ca996f37d1dcafe4cbaa Reviewed-by: Robert Griebl <robert.griebl@qt.io>
Diffstat (limited to 'src/interfaceframework')
-rw-r--r--src/interfaceframework/qifpendingreply.cpp30
-rw-r--r--src/interfaceframework/qifpendingreply.h24
2 files changed, 54 insertions, 0 deletions
diff --git a/src/interfaceframework/qifpendingreply.cpp b/src/interfaceframework/qifpendingreply.cpp
index 3b2b8151..cfbefea4 100644
--- a/src/interfaceframework/qifpendingreply.cpp
+++ b/src/interfaceframework/qifpendingreply.cpp
@@ -862,6 +862,36 @@ void QIfPendingReplyBase::setSuccessNoCheck(const QVariant &value)
Please see qRegisterMetaType for more information.
*/
+/*!
+ \macro QIF_DECLARE_PENDINGREPLY(TYPE)
+ \relates QIfPendingReply
+ \since 6.8
+
+ Declares the type \a TYPE to be used in a QIfPendingReply. This macro is used to make sure
+ that QIfPendingReply<TYPE> can be used in QML.
+
+ This macro should be used in the header file directly after the definition of the type.
+
+ \sa QIF_DECLARE_PENDINGREPLY_WITH_NAME
+*/
+
+/*!
+ \macro QIF_DECLARE_PENDINGREPLY_WITH_NAME(NAME, TYPE)
+ \relates QIfPendingReply
+ \since 6.8
+
+ Declares the type \a TYPE to be used in a QIfPendingReply. This macro is used to make sure
+ that QIfPendingReply<TYPE> can be used in QML.
+ The passed \a NAME is part of the struct name used to do the QML registration.
+
+ This macro should be used in the header file directly after the definition of the type.
+
+ \note Most of the time QIF_DECLARE_PENDINGREPLY should be used instead of this macro. This
+ macro is useful for enums or types inside namespaces.
+
+ \sa QIF_DECLARE_PENDINGREPLY
+*/
+
QT_END_NAMESPACE
#include "moc_qifpendingreply.cpp"
diff --git a/src/interfaceframework/qifpendingreply.h b/src/interfaceframework/qifpendingreply.h
index 4627d8f9..67ee97c2 100644
--- a/src/interfaceframework/qifpendingreply.h
+++ b/src/interfaceframework/qifpendingreply.h
@@ -12,6 +12,7 @@
#include <QtCore/QVariant>
#include <QtCore/QDebug>
#include <QtCore/QMetaEnum>
+#include <QtQml/QQmlEngine>
#include <QtInterfaceFramework/qtifglobal.h>
@@ -54,6 +55,7 @@ private:
class Q_QTINTERFACEFRAMEWORK_EXPORT QIfPendingReplyBase
{
Q_GADGET
+ QML_VALUE_TYPE(PendingReplyBase)
Q_PROPERTY(QIfPendingReplyWatcher* watcher READ watcher FINAL)
Q_PROPERTY(QVariant value READ value FINAL)
Q_PROPERTY(bool valid READ isValid FINAL)
@@ -252,6 +254,28 @@ template <typename T> Q_INLINE_TEMPLATE typename std::enable_if<!QtPrivate::IsQE
qRegisterMetaType<QIfPendingReplyBase>(qPrintable(t_name));
}
+#define QIF_DECLARE_PENDINGREPLY(TYPE) \
+QIF_DECLARE_PENDINGREPLY_WITH_NAME(TYPE, TYPE)
+
+#define QIF_DECLARE_PENDINGREPLY_WITH_NAME(NAME, TYPE) \
+struct PendingReplyRegistration##NAME \
+{ \
+ Q_GADGET \
+ QML_FOREIGN(QIfPendingReply<TYPE>) \
+ QML_USING(QIfPendingReplyBase) \
+}; \
+
+#define QTIF_ADD_QML_REGISTRATION(MetaTypeName, MetaTypeId, AliasingType) \
+QIF_DECLARE_PENDINGREPLY_WITH_NAME(MetaTypeName, AliasingType)
+
+namespace qtif_private {
+ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QTIF_ADD_QML_REGISTRATION)
+ QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QTIF_ADD_QML_REGISTRATION)
+ QT_FOR_EACH_STATIC_CORE_POINTER(QTIF_ADD_QML_REGISTRATION)
+ QT_FOR_EACH_STATIC_CORE_TEMPLATE(QTIF_ADD_QML_REGISTRATION)
+ QT_FOR_EACH_STATIC_CORE_CLASS(QTIF_ADD_QML_REGISTRATION)
+}
+
QT_END_NAMESPACE
#endif // QIFPENDINGREPLY_H