aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlmetatype.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-09-08 14:41:42 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-24 07:54:29 +0000
commit3195b44e1c9678584c05ed823aab2eb32518d868 (patch)
tree7c13d0ee0b6f9074841862e160d19d744daeda58 /src/qml/qml/qqmlmetatype.cpp
parentb101be9be64b6cc82dc357da0faeffbaab771b8f (diff)
Allow more options for creating value types from JS objects
We allow value types to be created 1. by calling Q_INVOKABLE constructors 2. by setting their values from properties of a JS object Both have to be opted into by setting a class info. If opted into, these options override the existing methods. When a a type can be created by setting its properties, that implies you can also initialize it using an invokable constructor. However, when given a JS object, the properties method is used. We keep this internal and undocumented for now. As the last try (the create(QJSValue) methods and QJSValue ctors) was not that stellar, let's first wait a bit and see if we're getting it right this time around. Fixes: QTBUG-106480 Change-Id: I767230924afcba032d501846cc3263dad57b7bf0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r--src/qml/qml/qqmlmetatype.cpp23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index e3ff358c1d..b5cddd112b 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -152,6 +152,10 @@ static QQmlTypePrivate *createQQmlType(QQmlMetaTypeData *data, const QString &el
d->extraData.cd->customParser = reinterpret_cast<QQmlCustomParser *>(type.customParser);
d->extraData.cd->registerEnumClassesUnscoped = true;
d->extraData.cd->registerEnumsFromRelatedTypes = true;
+ d->extraData.cd->constructValueType = type.has(QQmlPrivate::RegisterType::CreationMethod)
+ && type.creationMethod != QQmlPrivate::ValueTypeCreationMethod::None;
+ d->extraData.cd->populateValueType = type.has(QQmlPrivate::RegisterType::CreationMethod)
+ && type.creationMethod == QQmlPrivate::ValueTypeCreationMethod::Structured;
if (type.extensionMetaObject)
d->extraData.cd->extMetaObject = type.extensionMetaObject;
@@ -1707,23 +1711,8 @@ const QMetaObject *QQmlMetaType::metaObjectForValueType(QMetaType metaType)
// call QObject pointers value types. Explicitly registered types also override
// the implicit use of gadgets.
if (!(metaType.flags() & QMetaType::PointerToQObject)) {
- const QQmlType qmlType = QQmlMetaType::qmlType(metaType);
-
- // Prefer the extension meta object, if any.
- // Extensions allow registration of non-gadget value types.
- if (const QMetaObject *extensionMetaObject = qmlType.extensionMetaObject()) {
- // 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 (const QMetaObject *qmlTypeMetaObject = qmlType.metaObject()) {
- // This may be a namespace even if the original metaType isn't.
- // You can do such things with QML_FOREIGN declarations.
- if (qmlTypeMetaObject->metaType().flags() & QMetaType::IsGadget)
- return qmlTypeMetaObject;
- }
+ if (const QMetaObject *mo = metaObjectForValueType(QQmlMetaType::qmlType(metaType)))
+ return mo;
}
// If it _is_ a gadget, we can just use it.