aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlprivate.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-28 16:48:53 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-02 14:00:17 +0100
commit6f968781c4c8a278a7743b0904fb2bdf4c6ddf1a (patch)
tree0d5944f74c10bf3223cb374234c7f6d78706714f /src/qml/qml/qqmlprivate.h
parent2b99430671e37427a990973df37e62ad8cdebe8b (diff)
QML: Allow namespaces as extensions to types
This way we can access the enums of namespaces as properties of the primary type. This is achieved by: 1. Making enums of extended types available in the base type 2. Allowing the extension to be specified as plain metaObject rather than as type name. 3. Refraining from creating the extension if the create function does not exist. The goal of this is to declare the Qt namespace in a civilized way, but will also help with cleaning up the QtQuick value types and their enums. Change-Id: I13399741d30ce38d1bff753cfa1b11e72ccfbf6a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlprivate.h')
-rw-r--r--src/qml/qml/qqmlprivate.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlprivate.h b/src/qml/qml/qqmlprivate.h
index 6639ecbd26..2beeacd20f 100644
--- a/src/qml/qml/qqmlprivate.h
+++ b/src/qml/qml/qqmlprivate.h
@@ -625,6 +625,18 @@ namespace QQmlPrivate
};
template<class T, class = std::void_t<>>
+ struct QmlExtendedNamespace
+ {
+ static constexpr const QMetaObject *metaObject() { return nullptr; }
+ };
+
+ template<class T>
+ struct QmlExtendedNamespace<T, std::void_t<decltype(T::qmlExtendedNamespace())>>
+ {
+ static constexpr const QMetaObject *metaObject() { return T::qmlExtendedNamespace(); }
+ };
+
+ template<class T, class = std::void_t<>>
struct QmlResolved
{
using Type = T;
@@ -718,7 +730,7 @@ namespace QQmlPrivate
template<typename T, typename E>
void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
const QMetaObject *classInfoMetaObject,
- QVector<int> *qmlTypeIds)
+ QVector<int> *qmlTypeIds, const QMetaObject *extension)
{
RegisterTypeAndRevisions type = {
0,
@@ -742,7 +754,7 @@ namespace QQmlPrivate
StaticCastSelector<T, QQmlPropertyValueInterceptor>::cast(),
ExtendedType<E>::createParent,
- ExtendedType<E>::staticMetaObject(),
+ extension ? extension : ExtendedType<E>::staticMetaObject(),
&qmlCreateCustomParser<T>,
qmlTypeIds
@@ -754,7 +766,7 @@ namespace QQmlPrivate
template<>
void Q_QML_EXPORT qmlRegisterTypeAndRevisions<QQmlTypeNotAvailable, void>(
const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
- QVector<int> *qmlTypeIds);
+ QVector<int> *qmlTypeIds, const QMetaObject *);
} // namespace QQmlPrivate