aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-11-06 15:13:27 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-11 11:37:49 +0100
commitf0908255c9921371d886eff0b8ce245929b50d88 (patch)
treeb246bca2fcdae9ee906acc6e2b54a874b36734ea /src/qmlcompiler
parent40c0cbda771e9888999d8b78179e9600de4e7795 (diff)
QtQml: Integrate sequences with registration macros
You get to write QML_SEQUENTIAL_CONTAINER(value_type) now, and qmltyperegistrar will generate a sensible registration call from that. A registration might look like this: struct MyStringListForeign { Q_GADGET QML_ANONYMOUS QML_SEQUENTIAL_CONTAINER(QString) QML_FOREIGN(MyStringList) QML_ADDED_IN_VERSION(3, 1) }; It's unfortunate that we need to use a metaobject to transfer all of this information, but there is no other sensible way. Transform the containers defined in qv4sequenceobject.cpp to use the new style, and move them out of the builtins, into QtQml. Recognize that only one of them was ever tested, and add tests for the rest. Task-number: QTBUG-82443 Change-Id: I3a30f9e27266bb575eea26c5daf5dad1ec461cc5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qqmljsscope.cpp1
-rw-r--r--src/qmlcompiler/qqmljsscope_p.h10
-rw-r--r--src/qmlcompiler/qqmljstypedescriptionreader.cpp6
3 files changed, 15 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp
index 0787e1062e..ed029208dc 100644
--- a/src/qmlcompiler/qqmljsscope.cpp
+++ b/src/qmlcompiler/qqmljsscope.cpp
@@ -152,6 +152,7 @@ void QQmlJSScope::resolveTypes(const QHash<QString, QQmlJSScope::ConstPtr> &cont
m_baseType = findType(m_baseTypeName);
m_attachedType = findType(m_attachedTypeName);
+ m_valueType = findType(m_valueTypeName);
for (auto it = m_properties.begin(), end = m_properties.end(); it != end; ++it)
it->setType(findType(it->typeName()));
diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h
index 99645a8071..24e401fa0a 100644
--- a/src/qmlcompiler/qqmljsscope_p.h
+++ b/src/qmlcompiler/qqmljsscope_p.h
@@ -101,7 +101,8 @@ public:
enum class AccessSemantics {
Reference,
Value,
- None
+ None,
+ Sequence
};
enum Flag {
@@ -200,6 +201,10 @@ public:
void setAttachedTypeName(const QString &name) { m_attachedTypeName = name; }
QQmlJSScope::ConstPtr attachedType() const { return m_attachedType; }
+ QString valueTypeName() const { return m_valueTypeName; }
+ void setValueTypeName(const QString &name) { m_valueTypeName = name; }
+ QQmlJSScope::ConstPtr valueType() const { return m_valueType; }
+
bool isSingleton() const { return m_flags & Singleton; }
bool isCreatable() const { return m_flags & Creatable; }
bool isComposite() const { return m_flags & Composite; }
@@ -258,6 +263,9 @@ private:
QString m_attachedTypeName;
QQmlJSScope::WeakConstPtr m_attachedType;
+ QString m_valueTypeName;
+ QQmlJSScope::WeakConstPtr m_valueType;
+
Flags m_flags;
AccessSemantics m_semantics = AccessSemantics::Reference;
diff --git a/src/qmlcompiler/qqmljstypedescriptionreader.cpp b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
index 215a82b4bc..fd875dd715 100644
--- a/src/qmlcompiler/qqmljstypedescriptionreader.cpp
+++ b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
@@ -224,6 +224,8 @@ void QQmlJSTypeDescriptionReader::readComponent(UiObjectDefinition *ast)
readMetaObjectRevisions(script, scope);
} else if (name == QLatin1String("attachedType")) {
scope->setAttachedTypeName(readStringBinding(script));
+ } else if (name == QLatin1String("valueType")) {
+ scope->setValueTypeName(readStringBinding(script));
} else if (name == QLatin1String("isSingleton")) {
scope->setIsSingleton(readBoolBinding(script));
} else if (name == QLatin1String("isCreatable")) {
@@ -238,6 +240,8 @@ void QQmlJSTypeDescriptionReader::readComponent(UiObjectDefinition *ast)
scope->setAccessSemantics(QQmlJSScope::AccessSemantics::Value);
} else if (semantics == QLatin1String("none")) {
scope->setAccessSemantics(QQmlJSScope::AccessSemantics::None);
+ } else if (semantics == QLatin1String("sequence")) {
+ scope->setAccessSemantics(QQmlJSScope::AccessSemantics::Sequence);
} else {
addWarning(script->firstSourceLocation(),
tr("Unknown access semantics \"%1\".").arg(semantics));
@@ -245,7 +249,7 @@ void QQmlJSTypeDescriptionReader::readComponent(UiObjectDefinition *ast)
} else {
addWarning(script->firstSourceLocation(),
tr("Expected only name, prototype, defaultProperty, attachedType, "
- "exports, isSingleton, isCreatable, isComposite and "
+ "valueType, exports, isSingleton, isCreatable, isComposite and "
"exportMetaObjectRevisions script bindings, not \"%1\".").arg(name));
}
} else {