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/qml/qqmltype_p_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/qml/qqmltype_p_p.h')
-rw-r--r-- | src/qml/qml/qqmltype_p_p.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/qml/qml/qqmltype_p_p.h b/src/qml/qml/qqmltype_p_p.h index 51f776178c..43344827db 100644 --- a/src/qml/qml/qqmltype_p_p.h +++ b/src/qml/qml/qqmltype_p_p.h @@ -56,6 +56,7 @@ #include <private/qqmlproxymetaobject_p.h> #include <private/qqmlrefcount_p.h> #include <private/qqmlpropertycache_p.h> +#include <private/qqmlmetatype_p.h> QT_BEGIN_NAMESPACE @@ -69,6 +70,7 @@ public: void initEnums(QQmlEnginePrivate *engine) const; void insertEnums(const QMetaObject *metaObject) const; void insertEnumsFromPropertyCache(const QQmlPropertyCache *cache) const; + void setContainingType(QQmlType *containingType); QUrl sourceUrl() const { @@ -77,6 +79,8 @@ public: return extraData.fd->url; case QQmlType::CompositeSingletonType: return extraData.sd->singletonInstanceInfo->url; + case QQmlType::InlineComponentType: + return extraData.id->url; default: return QUrl(); } @@ -130,10 +134,23 @@ public: QUrl url; }; + struct QQmlInlineTypeData + { + QUrl url = QUrl(); + // The containing type stores a pointer to the inline component type + // Using QQmlType here would create a reference cycle + // As the inline component type cannot outlive the containing type + // this should still be fine + QQmlTypePrivate const * containingType = nullptr; + QString inlineComponentName = QString(); + int objectId = -1; + }; + union extraData { QQmlCppTypeData* cd; QQmlSingletonTypeData* sd; QQmlCompositeTypeData* fd; + QQmlInlineTypeData* id; } extraData; const char *iid; @@ -160,6 +177,8 @@ public: mutable QList<QStringHash<int>*> scopedEnums; void setName(const QString &uri, const QString &element); + mutable QHash<QString, int> namesToInlineComponentObjectIndex; + mutable QHash<int, QQmlType> objectIdToICType; private: ~QQmlTypePrivate() override; |