diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-02-14 17:44:58 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-02-15 22:34:49 +0100 |
commit | 4d13ed6a598c142f9ed9928fa0bdcb395e4b94cc (patch) | |
tree | f7b3c2fd6e2407446494c072426a7033dcb1de2d /src/qml/qml/qqmltype_p_p.h | |
parent | 6b609c796b59e548854888e2c82d46eab9fcc083 (diff) |
QtQml: Consider value types when looking for metaobjects
We have quite a few types with only extension metaobjects now. Move the
functionality to retrieve the metaobject into QQmlType where it belongs.
Pick-to: 6.7 6.6
Fixes: QTBUG-119829
Change-Id: I2b99b1a305d8726547ae0512d3c832799a4e4b04
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qml/qml/qqmltype_p_p.h')
-rw-r--r-- | src/qml/qml/qqmltype_p_p.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/qml/qml/qqmltype_p_p.h b/src/qml/qml/qqmltype_p_p.h index bd77eb5509..8f614eeac2 100644 --- a/src/qml/qml/qqmltype_p_p.h +++ b/src/qml/qml/qqmltype_p_p.h @@ -86,6 +86,11 @@ public: return regType == QQmlType::CompositeType || regType == QQmlType::CompositeSingletonType; } + bool isValueType() const + { + return regType == QQmlType::CppType && !(typeId.flags() & QMetaType::PointerToQObject); + } + QQmlType resolveCompositeBaseType(QQmlEnginePrivate *engine) const; QQmlPropertyCache::ConstPtr compositePropertyCache(QQmlEnginePrivate *engine) const; @@ -192,6 +197,40 @@ public: }, ok); } + const QMetaObject *metaObject() const + { + if (isValueType()) + return metaObjectForValueType(); + + const QQmlTypePrivate::ProxyMetaObjects *proxies = init(); + return proxies->data.isEmpty() + ? baseMetaObject + : proxies->data.constFirst().metaObject; + } + + const QMetaObject *metaObjectForValueType() const + { + Q_ASSERT(isValueType()); + + // Prefer the extension meta object, if any. + // Extensions allow registration of non-gadget value types. + if (const QMetaObject *extensionMetaObject = extraData.cppTypeData->extMetaObject) { + // This may be a namespace even if the original metaType isn't. + // You can do such things with QML_FOREIGN declarations. + if (extensionMetaObject->metaType().flags() & QMetaType::IsGadget) + return extensionMetaObject; + } + + if (baseMetaObject) { + // This may be a namespace even if the original metaType isn't. + // You can do such things with QML_FOREIGN declarations. + if (baseMetaObject->metaType().flags() & QMetaType::IsGadget) + return baseMetaObject; + } + + return nullptr; + } + private: mutable QAtomicPointer<const ProxyMetaObjects> proxyMetaObjects; mutable QAtomicPointer<const Enums> enums; |