diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-02-25 11:20:07 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-02-25 11:58:52 +0100 |
commit | a4b25aa3c16ba9ce6e2821e591f7c35bf675d961 (patch) | |
tree | fbc044f20e0bccfd6c2dc27d589c3e1e157c1bc2 /src | |
parent | bbe3f976c3426fea5dd305feff79288b9719fcd5 (diff) |
qmltyperegistrar: Correctly collect attached types
Their revisions were missing from the qmltypes.
Change-Id: Iec7a5ad1c56135c761f6a1fe66904cf25d039850
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmltyperegistrar/qmltypesclassdescription.cpp | 53 | ||||
-rw-r--r-- | src/qmltyperegistrar/qmltypesclassdescription.h | 10 | ||||
-rw-r--r-- | src/qmltyperegistrar/qmltypescreator.cpp | 3 |
3 files changed, 41 insertions, 25 deletions
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.cpp b/src/qmltyperegistrar/qmltypesclassdescription.cpp index 8189bcd52e..c6279998b7 100644 --- a/src/qmltyperegistrar/qmltypesclassdescription.cpp +++ b/src/qmltyperegistrar/qmltypesclassdescription.cpp @@ -60,7 +60,7 @@ const QJsonObject *QmlTypesClassDescription::findType(const QVector<QJsonObject> void QmlTypesClassDescription::collect(const QJsonObject *classDef, const QVector<QJsonObject> &types, const QVector<QJsonObject> &foreign, - bool topLevel) + CollectMode mode) { const auto classInfos = classDef->value(QLatin1String("classInfos")).toArray(); for (const QJsonValue &classInfo : classInfos) { @@ -69,10 +69,10 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef, const QString value = obj[QLatin1String("value")].toString(); if (name == QLatin1String("DefaultProperty")) { - if (defaultProp.isEmpty()) + if (mode != AttachedType && defaultProp.isEmpty()) defaultProp = value; } else if (name == QLatin1String("QML.AddedInMinorVersion")) { - if (topLevel) { + if (mode == TopLevel) { addedInRevision = value.toInt(); revisions.append(value.toInt()); } else if (!elementName.isEmpty()) { @@ -80,7 +80,7 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef, } } - if (!topLevel) + if (mode != TopLevel) continue; // These only apply to the original class @@ -94,27 +94,23 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef, } else if (name == QLatin1String("QML.Creatable")) { isCreatable = (value != QLatin1String("false")); } else if (name == QLatin1String("QML.Attached")) { - attachedType = value; - if (const QJsonObject *other = findType(types, attachedType)) - collect(other, types, foreign, false); - else if (const QJsonObject *other = findType(foreign, attachedType)) - collect(other, types, foreign, false); + collectAttached(value, types, foreign); } else if (name == QLatin1String("QML.Singleton")) { if (value == QLatin1String("true")) isSingleton = true; } else if (name == QLatin1String("QML.Foreign")) { if (const QJsonObject *other = findType(foreign, value)) { classDef = other; - if (defaultProp.isEmpty()) { - // Foreign type can have a default property - const auto classInfos = classDef->value(QLatin1String("classInfos")).toArray(); - for (const QJsonValue &classInfo : classInfos) { - QJsonObject obj = classInfo.toObject(); - if (obj[QLatin1String("name")].toString() == QLatin1String("DefaultProperty")) { - defaultProp = obj[QLatin1String("value")].toString(); - break; - } - } + // Foreign type can have a default property or an attached types + const auto classInfos = classDef->value(QLatin1String("classInfos")).toArray(); + for (const QJsonValue &classInfo : classInfos) { + const QJsonObject obj = classInfo.toObject(); + const QString foreignName = obj[QLatin1String("name")].toString(); + const QString foreignValue = obj[QLatin1String("value")].toString(); + if (defaultProp.isEmpty() && foreignName == QLatin1String("DefaultProperty")) + defaultProp = foreignValue; + else if (foreignName == QLatin1String("QML.Attached")) + collectAttached(foreignValue, types, foreign); } } } else if (name == QLatin1String("QML.Root")) { @@ -125,7 +121,7 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef, } } - if (!elementName.isEmpty()) { + if (mode == AttachedType || !elementName.isEmpty()) { collectExtraVersions(classDef, QString::fromLatin1("properties"), revisions); collectExtraVersions(classDef, QString::fromLatin1("slots"), revisions); collectExtraVersions(classDef, QString::fromLatin1("methods"), revisions); @@ -137,13 +133,13 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef, const QJsonObject superObject = supers.first().toObject(); if (superObject[QLatin1String("access")].toString() == QLatin1String("public")) { const QString superName = superObject[QLatin1String("name")].toString(); - if (topLevel && superClass.isEmpty()) + if (mode == TopLevel && superClass.isEmpty()) superClass = superName; if (const QJsonObject *other = findType(types, superName)) - collect(other, types, foreign, false); + collect(other, types, foreign, mode == TopLevel ? SuperClass : AttachedType); else if (const QJsonObject *other = findType(foreign, superName)) - collect(other, types, foreign, false); + collect(other, types, foreign, mode == TopLevel ? SuperClass : AttachedType); } } @@ -159,3 +155,14 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef, resolvedClass = classDef; } + +void QmlTypesClassDescription::collectAttached(const QString &attached, + const QVector<QJsonObject> &types, + const QVector<QJsonObject> &foreign) +{ + attachedType = attached; + if (const QJsonObject *other = findType(types, attachedType)) + collect(other, types, foreign, AttachedType); + else if (const QJsonObject *other = findType(foreign, attachedType)) + collect(other, types, foreign, AttachedType); +} diff --git a/src/qmltyperegistrar/qmltypesclassdescription.h b/src/qmltyperegistrar/qmltypesclassdescription.h index 8f3a6ea124..d468612beb 100644 --- a/src/qmltyperegistrar/qmltypesclassdescription.h +++ b/src/qmltyperegistrar/qmltypesclassdescription.h @@ -49,8 +49,16 @@ struct QmlTypesClassDescription bool isRootClass = false; bool isBuiltin = false; + enum CollectMode { + TopLevel, + SuperClass, + AttachedType + }; + void collect(const QJsonObject *classDef, const QVector<QJsonObject> &types, - const QVector<QJsonObject> &foreign, bool topLevel); + const QVector<QJsonObject> &foreign, CollectMode mode); + void collectAttached(const QString &attached, const QVector<QJsonObject> &types, + const QVector<QJsonObject> &foreign); static const QJsonObject *findType(const QVector<QJsonObject> &types, const QString &name); }; diff --git a/src/qmltyperegistrar/qmltypescreator.cpp b/src/qmltyperegistrar/qmltypescreator.cpp index 911120027e..292841541b 100644 --- a/src/qmltyperegistrar/qmltypescreator.cpp +++ b/src/qmltyperegistrar/qmltypescreator.cpp @@ -245,7 +245,8 @@ void QmlTypesCreator::writeComponents() m_qml.writeStartObject(componentElement); QmlTypesClassDescription collector; - collector.collect(&component, m_ownTypes, m_foreignTypes, true); + collector.collect(&component, m_ownTypes, m_foreignTypes, + QmlTypesClassDescription::TopLevel); writeClassProperties(collector); |