diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-04-28 16:55:22 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-05-18 18:57:56 +0200 |
commit | 79b742fb84abe699ff726eec548793880cfa7527 (patch) | |
tree | 2947c614ac2453e44cbc3a6f45dca438d6486e8b | |
parent | 1e30ec77aaedcc29ba7ac1c3ec3937ee0b8287e9 (diff) |
Preserve access semantics in qmltypes
gadget types are accessed with value semantics, object types are
accessed with reference semantics, and namespaces are not accessed.
Change-Id: I5eb8f132d729416f28bf94e651f877fc4a9a5c77
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qmltyperegistrar/qmltypesclassdescription.cpp | 10 | ||||
-rw-r--r-- | src/qmltyperegistrar/qmltypesclassdescription.h | 1 | ||||
-rw-r--r-- | src/qmltyperegistrar/qmltypescreator.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h | 1 | ||||
-rw-r--r-- | tools/shared/scopetree.h | 34 | ||||
-rw-r--r-- | tools/shared/typedescriptionreader.cpp | 12 |
7 files changed, 56 insertions, 11 deletions
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.cpp b/src/qmltyperegistrar/qmltypesclassdescription.cpp index 2214758f38..2529951d7e 100644 --- a/src/qmltyperegistrar/qmltypesclassdescription.cpp +++ b/src/qmltyperegistrar/qmltypesclassdescription.cpp @@ -179,8 +179,14 @@ void QmlTypesClassDescription::collect(const QJsonObject *classDef, if (className.isEmpty() && mode == TopLevel) className = classDef->value(QLatin1String("qualifiedClassName")).toString(); - // If it's not a QObject, it's not creatable - isCreatable = isCreatable && classDef->value(QLatin1String("object")).toBool(); + if (classDef->value(QLatin1String("object")).toBool()) { + accessSemantics = QLatin1String("reference"); + } else { + isCreatable = false; + accessSemantics = classDef->value(QLatin1String("gadget")).toBool() + ? QLatin1String("value") + : QLatin1String("none"); + } } void QmlTypesClassDescription::collectAttached(const QString &attached, diff --git a/src/qmltyperegistrar/qmltypesclassdescription.h b/src/qmltyperegistrar/qmltypesclassdescription.h index ed4ba49592..60f7c92893 100644 --- a/src/qmltyperegistrar/qmltypesclassdescription.h +++ b/src/qmltyperegistrar/qmltypesclassdescription.h @@ -44,6 +44,7 @@ struct QmlTypesClassDescription QString defaultProp; QString superClass; QString attachedType; + QString accessSemantics; QList<QTypeRevision> revisions; QTypeRevision addedInRevision; QTypeRevision removedInRevision; diff --git a/src/qmltyperegistrar/qmltypescreator.cpp b/src/qmltyperegistrar/qmltypescreator.cpp index a9885b03fa..d74d59062f 100644 --- a/src/qmltyperegistrar/qmltypescreator.cpp +++ b/src/qmltyperegistrar/qmltypescreator.cpp @@ -50,6 +50,9 @@ void QmlTypesCreator::writeClassProperties(const QmlTypesClassDescription &colle m_qml.writeScriptBinding(QLatin1String("file"), enquote(collector.file)); m_qml.writeScriptBinding(QLatin1String("name"), enquote(collector.className)); + if (!collector.accessSemantics.isEmpty()) + m_qml.writeScriptBinding(QLatin1String("accessSemantics"), enquote(collector.accessSemantics)); + if (!collector.defaultProp.isEmpty()) m_qml.writeScriptBinding(QLatin1String("defaultProperty"), enquote(collector.defaultProp)); diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp index 1cfcd689c6..bf71835e43 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp @@ -75,4 +75,10 @@ void tst_qmltyperegistrar::superAndForeignTypes() QVERIFY(qmltypesData.contains("Method { name: \"sizeToString\"; type: \"string\" }")); } +void tst_qmltyperegistrar::accessSemantics() +{ + QVERIFY(qmltypesData.contains("accessSemantics: \"reference\"")); + QVERIFY(qmltypesData.contains("accessSemantics: \"value\"")); +} + QTEST_MAIN(tst_qmltyperegistrar) diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h index 09485ab0b6..c8d6e04f0a 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h @@ -88,6 +88,7 @@ private slots: void qmltypesHasFileNames(); void qmltypesHasFlags(); void superAndForeignTypes(); + void accessSemantics(); private: QByteArray qmltypesData; diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h index 92e60d6d0a..08d529acc9 100644 --- a/tools/shared/scopetree.h +++ b/tools/shared/scopetree.h @@ -71,6 +71,20 @@ public: using ConstPtr = QSharedPointer<const ScopeTree>; using WeakConstPtr = QWeakPointer<const ScopeTree>; + enum class AccessSemantics { + Reference, + Value, + None + }; + + enum Flag { + Creatable = 0x1, + Composite = 0x2, + Singleton = 0x4 + }; + Q_DECLARE_FLAGS(Flags, Flag) + Q_FLAGS(Flags); + class Export { public: Export() = default; @@ -149,12 +163,15 @@ public: QString attachedTypeName() const { return m_attachedTypeName; } void setAttachedTypeName(const QString &name) { m_attachedTypeName = name; } - bool isSingleton() const { return m_isSingleton; } - bool isCreatable() const { return m_isCreatable; } - bool isComposite() const { return m_isComposite; } - void setIsSingleton(bool value) { m_isSingleton = value; } - void setIsCreatable(bool value) { m_isCreatable = value; } - void setIsComposite(bool value) { m_isSingleton = value; } + bool isSingleton() const { return m_flags & Singleton; } + bool isCreatable() const { return m_flags & Creatable; } + bool isComposite() const { return m_flags & Composite; } + void setIsSingleton(bool v) { m_flags = v ? (m_flags | Singleton) : (m_flags & ~Singleton); } + void setIsCreatable(bool v) { m_flags = v ? (m_flags | Creatable) : (m_flags & ~Creatable); } + void setIsComposite(bool v) { m_flags = v ? (m_flags | Composite) : (m_flags & ~Composite); } + + void setAccessSemantics(AccessSemantics semantics) { m_semantics = semantics; } + AccessSemantics accessSemantics() const { return m_semantics; } struct FieldMember { @@ -214,9 +231,8 @@ private: QString m_defaultPropertyName; QString m_attachedTypeName; - bool m_isSingleton = false; - bool m_isCreatable = true; - bool m_isComposite = false; + Flags m_flags; + AccessSemantics m_semantics = AccessSemantics::Reference; }; #endif // SCOPETREE_H diff --git a/tools/shared/typedescriptionreader.cpp b/tools/shared/typedescriptionreader.cpp index 7831c1ad10..b1738b94e8 100644 --- a/tools/shared/typedescriptionreader.cpp +++ b/tools/shared/typedescriptionreader.cpp @@ -228,6 +228,18 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast) scope->setIsCreatable(readBoolBinding(script)); } else if (name == QLatin1String("isComposite")) { scope->setIsComposite(readBoolBinding(script)); + } else if (name == QLatin1String("accessSemantics")) { + const QString semantics = readStringBinding(script); + if (semantics == QLatin1String("reference")) { + scope->setAccessSemantics(ScopeTree::AccessSemantics::Reference); + } else if (semantics == QLatin1String("value")) { + scope->setAccessSemantics(ScopeTree::AccessSemantics::Value); + } else if (semantics == QLatin1String("none")) { + scope->setAccessSemantics(ScopeTree::AccessSemantics::None); + } else { + addWarning(script->firstSourceLocation(), + tr("Unknown access semantics \"%1\".").arg(semantics)); + } } else { addWarning(script->firstSourceLocation(), tr("Expected only name, prototype, defaultProperty, attachedType, " |