diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-01-15 14:47:35 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-01-23 15:58:10 +0100 |
commit | 684f9df7849bc79f1f02a60844fb43c7a3927d2f (patch) | |
tree | 531be4d102388395e4ddd2d14f38a679e15c283d /src/qml/jsruntime/qv4executablecompilationunit_p.h | |
parent | 020a6e67766595351bcf911e965b26952a7c81b8 (diff) |
Long live QML inline components
[ChangeLog][QtQml] It is now possible to declare new QML components in
a QML file via the component keyword. They can be used just as if they
were declared in another file, with the only difference that the type
name needs to be prefixed with the name of the containing type outside
of the file were the inline component has been declared.
Notably, inline components are not closures: In the following
example, the output would be 42
// MyItem.qml
Item {
property int i: 33
component IC: Item {
Component.onCompleted: console.log(i)
}
}
// user.qml
Item {
property int i: 42
MyItem.IC {}
}
Fixes: QTBUG-79382
Change-Id: I6a5ffc43f093a76323f435cfee9bab217781b8f5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4executablecompilationunit_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4executablecompilationunit_p.h | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/qml/jsruntime/qv4executablecompilationunit_p.h b/src/qml/jsruntime/qv4executablecompilationunit_p.h index 1272e7a2c3..8cad18a3dc 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit_p.h +++ b/src/qml/jsruntime/qv4executablecompilationunit_p.h @@ -64,6 +64,26 @@ QT_BEGIN_NAMESPACE class QQmlScriptData; class QQmlEnginePrivate; + +struct InlineComponentData { + + InlineComponentData() = default; + InlineComponentData(const CompositeMetaTypeIds &typeIds, int objectIndex, int nameIndex, int totalObjectCount, int totalBindingCount, int totalParserStatusCount) + : typeIds(typeIds) + , objectIndex(objectIndex) + , nameIndex(nameIndex) + , totalObjectCount(totalObjectCount) + , totalBindingCount(totalBindingCount) + , totalParserStatusCount(totalParserStatusCount) {} + + CompositeMetaTypeIds typeIds; + int objectIndex = -1; + int nameIndex = -1; + int totalObjectCount = 0; + int totalBindingCount = 0; + int totalParserStatusCount = 0; +}; + namespace QV4 { // index is per-object binding index @@ -143,11 +163,16 @@ public: QHash<int, IdentifierHash> namedObjectsPerComponentCache; inline IdentifierHash namedObjectsPerComponent(int componentObjectIndex); - void finalizeCompositeType(QQmlEnginePrivate *qmlEngine, QQmlMetaType::CompositeMetaTypeIds typeIds); + void finalizeCompositeType(QQmlEnginePrivate *qmlEngine, CompositeMetaTypeIds typeIdsForComponent); - int totalBindingsCount = 0; // Number of bindings used in this type - int totalParserStatusCount = 0; // Number of instantiated types that are QQmlParserStatus subclasses - int totalObjectCount = 0; // Number of objects explicitly instantiated + int m_totalBindingsCount = 0; // Number of bindings used in this type + int m_totalParserStatusCount = 0; // Number of instantiated types that are QQmlParserStatus subclasses + int m_totalObjectCount = 0; // Number of objects explicitly instantiated + int icRoot = -1; + + int totalBindingsCount() const; + int totalParserStatusCount() const; + int totalObjectCount() const; QVector<QQmlRefPointer<QQmlScriptData>> dependentScripts; ResolvedTypeReferenceMap resolvedTypes; @@ -155,12 +180,14 @@ public: bool verifyChecksum(const CompiledData::DependentTypesHasher &dependencyHasher) const; - QQmlMetaType::CompositeMetaTypeIds typeIds() const { return {metaTypeId, listMetaTypeId}; } + CompositeMetaTypeIds typeIdsForComponent(int objectid = 0) const; int metaTypeId = -1; int listMetaTypeId = -1; bool isRegisteredWithEngine = false; + QHash<int, InlineComponentData> inlineComponentData; + QScopedPointer<CompilationUnitMapper> backingFile; // --- interface for QQmlPropertyCacheCreator |