aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltyperegistrar/qmltypesclassdescription.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmltyperegistrar/qmltypesclassdescription.cpp')
-rw-r--r--src/qmltyperegistrar/qmltypesclassdescription.cpp84
1 files changed, 50 insertions, 34 deletions
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.cpp b/src/qmltyperegistrar/qmltypesclassdescription.cpp
index 15a8113ac8..e21abd97bc 100644
--- a/src/qmltyperegistrar/qmltypesclassdescription.cpp
+++ b/src/qmltyperegistrar/qmltypesclassdescription.cpp
@@ -27,18 +27,19 @@
****************************************************************************/
#include "qmltypesclassdescription.h"
+#include "qmltypescreator.h"
#include <QtCore/qjsonarray.h>
static void collectExtraVersions(const QJsonObject *component, const QString &key,
- QList<int> &extraVersions)
+ QList<QTypeRevision> &extraVersions)
{
const QJsonArray &items = component->value(key).toArray();
for (const QJsonValue &item : items) {
const QJsonObject obj = item.toObject();
const auto revision = obj.find(QLatin1String("revision"));
if (revision != obj.end()) {
- const int extraVersion = revision.value().toInt();
+ const auto extraVersion = QTypeRevision::fromEncodedVersion(revision.value().toInt());
if (!extraVersions.contains(extraVersion))
extraVersions.append(extraVersion);
}
@@ -60,7 +61,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, QTypeRevision defaultRevision)
{
const auto classInfos = classDef->value(QLatin1String("classInfos")).toArray();
for (const QJsonValue &classInfo : classInfos) {
@@ -69,18 +70,19 @@ 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) {
- addedInRevision = value.toInt();
- revisions.append(value.toInt());
+ } else if (name == QLatin1String("QML.AddedInVersion")) {
+ const QTypeRevision revision = QTypeRevision::fromEncodedVersion(value.toInt());
+ if (mode == TopLevel) {
+ addedInRevision = revision;
+ revisions.append(revision);
} else if (!elementName.isEmpty()) {
- revisions.append(value.toInt());
+ revisions.append(revision);
}
}
- if (!topLevel)
+ if (mode != TopLevel)
continue;
// These only apply to the original class
@@ -89,32 +91,28 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef,
elementName = classDef->value(QLatin1String("className")).toString();
else if (value != QLatin1String("anonymous"))
elementName = value;
- } else if (name == QLatin1String("QML.RemovedInMinorVersion")) {
- removedInRevision = value.toInt();
+ } else if (name == QLatin1String("QML.RemovedInVersion")) {
+ removedInRevision = QTypeRevision::fromEncodedVersion(value.toInt());
} 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, defaultRevision);
} 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, defaultRevision);
}
}
} else if (name == QLatin1String("QML.Root")) {
@@ -125,7 +123,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,19 +135,22 @@ 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;
+ const CollectMode superMode = (mode == TopLevel) ? SuperClass : AttachedType;
if (const QJsonObject *other = findType(types, superName))
- collect(other, types, foreign, false);
+ collect(other, types, foreign, superMode, defaultRevision);
else if (const QJsonObject *other = findType(foreign, superName))
- collect(other, types, foreign, false);
+ collect(other, types, foreign, superMode, defaultRevision);
}
}
- if (addedInRevision == -1) {
- revisions.append(0);
- addedInRevision = 0;
+ if (!addedInRevision.isValid()) {
+ revisions.append(defaultRevision);
+ addedInRevision = defaultRevision;
+ } else if (addedInRevision < defaultRevision) {
+ revisions.append(defaultRevision);
}
std::sort(revisions.begin(), revisions.end());
@@ -157,4 +158,19 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef,
revisions.erase(end, revisions.end());
resolvedClass = classDef;
+
+ // If it's not a QObject, it's not creatable
+ isCreatable = isCreatable && classDef->value(QLatin1String("object")).toBool();
+}
+
+void QmlTypesClassDescription::collectAttached(const QString &attached,
+ const QVector<QJsonObject> &types,
+ const QVector<QJsonObject> &foreign,
+ QTypeRevision defaultRevision)
+{
+ attachedType = attached;
+ if (const QJsonObject *other = findType(types, attachedType))
+ collect(other, types, foreign, AttachedType, defaultRevision);
+ else if (const QJsonObject *other = findType(foreign, attachedType))
+ collect(other, types, foreign, AttachedType, defaultRevision);
}