diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-09 10:34:48 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-02 13:21:09 +0200 |
commit | d621027babff9a30d56ab6af871a465108c9eaba (patch) | |
tree | 54a5ccff0410476538929e4ab1f1400075c0df81 /src/qml/qml/qqmlmetatype.cpp | |
parent | ed7719a3af58b9ba36a6fbaccd08c85b78f8a961 (diff) |
V4: Rewrite qv4sequenceobject based on QMetaSequence
This avoids the template explosion and makes the mechanism extendable.
You can now register additional anonymous sequential containers.
Fixes: QTBUG-71574
Task-number: QTBUG-82443
Change-Id: I5b9ed9af1533a3b7df8fc5bb37bbb73b8304e592
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index e3083ae278..6eaf2063b5 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -389,6 +389,8 @@ QString registrationTypeString(QQmlType::RegistrationType typeType) typeStr = QStringLiteral("singleton type"); else if (typeType == QQmlType::CompositeSingletonType) typeStr = QStringLiteral("composite singleton type"); + else if (typeType == QQmlType::SequentialContainerType) + typeStr = QStringLiteral("sequential container type"); else typeStr = QStringLiteral("type"); return typeStr; @@ -464,8 +466,10 @@ void addTypeToData(QQmlTypePrivate *type, QQmlMetaTypeData *data) if (type->typeId.isValid()) { data->idToType.insert(type->typeId.id(), type); - if (type->typeId.flags() & QMetaType::PointerToQObject) + if (type->typeId.flags() & QMetaType::PointerToQObject + && type->regType != QQmlType::RegistrationType::SequentialContainerType) { data->objects.insert(type->typeId.id()); + } } if (type->listId.isValid()) { @@ -648,6 +652,39 @@ int QQmlMetaType::registerUnitCacheHook( return 0; } +QQmlType QQmlMetaType::registerSequentialContainer( + const QQmlPrivate::RegisterSequentialContainer &container) +{ + if (container.structVersion > 0) + qFatal("qmlRegisterSequenceContainer(): Cannot mix incompatible QML versions."); + + QQmlMetaTypeDataPtr data; + + if (!checkRegistration(QQmlType::SequentialContainerType, data, container.uri, QString(), + container.version, {})) { + return QQmlType(); + } + + QQmlTypePrivate *priv = new QQmlTypePrivate(QQmlType::SequentialContainerType); + + data->registerType(priv); + priv->setName(QString::fromUtf8(container.uri), QString()); + priv->version = container.version; + priv->typeId = container.typeId; + *priv->extraData.ld = container.metaSequence; + + addTypeToData(priv, data); + if (!container.typeId.isValid()) + data->idToType.insert(priv->typeId.id(), priv); + + return QQmlType(priv); +} + +void QQmlMetaType::unregisterSequentialContainer(int id) +{ + unregisterType(id); +} + bool QQmlMetaType::protectModule(const QString &uri, QTypeRevision version, bool protectAllVersions) { QQmlMetaTypeDataPtr data; |