1 | // Copyright (C) 2019 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQMLTYPE_P_P_H |
5 | #define QQMLTYPE_P_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <private/qqmltype_p.h> |
19 | #include <private/qstringhash_p.h> |
20 | #include <private/qqmlproxymetaobject_p.h> |
21 | #include <private/qqmlrefcount_p.h> |
22 | #include <private/qqmlpropertycache_p.h> |
23 | #include <private/qqmlmetatype_p.h> |
24 | |
25 | #include <QAtomicInteger> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QQmlTypePrivate : public QQmlRefCounted<QQmlTypePrivate> |
30 | { |
31 | Q_DISABLE_COPY_MOVE(QQmlTypePrivate) |
32 | public: |
33 | QQmlTypePrivate(QQmlType::RegistrationType type); |
34 | |
35 | void init() const; |
36 | void initEnums(QQmlEnginePrivate *engine) const; |
37 | void insertEnums(const QMetaObject *metaObject) const; |
38 | void insertEnumsFromPropertyCache(const QQmlPropertyCache::ConstPtr &cache) const; |
39 | void setContainingType(QQmlType *containingType); |
40 | |
41 | QUrl sourceUrl() const |
42 | { |
43 | switch (regType) { |
44 | case QQmlType::CompositeType: |
45 | return extraData.fd->url; |
46 | case QQmlType::CompositeSingletonType: |
47 | return extraData.sd->singletonInstanceInfo->url; |
48 | case QQmlType::InlineComponentType: |
49 | return extraData.id->url; |
50 | default: |
51 | return QUrl(); |
52 | } |
53 | } |
54 | |
55 | const QQmlTypePrivate *attachedPropertiesBase(QQmlEnginePrivate *engine) const |
56 | { |
57 | for (const QQmlTypePrivate *d = this; d; d = d->resolveCompositeBaseType(engine).d.data()) { |
58 | if (d->regType == QQmlType::CppType) |
59 | return d->extraData.cd->attachedPropertiesType ? d : nullptr; |
60 | |
61 | if (d->regType != QQmlType::CompositeType) |
62 | return nullptr; |
63 | } |
64 | return nullptr; |
65 | } |
66 | |
67 | bool isComposite() const |
68 | { |
69 | return regType == QQmlType::CompositeType || regType == QQmlType::CompositeSingletonType; |
70 | } |
71 | |
72 | QQmlType resolveCompositeBaseType(QQmlEnginePrivate *engine) const; |
73 | QQmlPropertyCache::ConstPtr compositePropertyCache(QQmlEnginePrivate *engine) const; |
74 | |
75 | QQmlType::RegistrationType regType; |
76 | |
77 | struct QQmlCppTypeData |
78 | { |
79 | int allocationSize; |
80 | void (*newFunc)(void *, void *); |
81 | void *userdata = nullptr; |
82 | QString noCreationReason; |
83 | QVariant (*createValueTypeFunc)(const QJSValue &); |
84 | int parserStatusCast; |
85 | QObject *(*extFunc)(QObject *); |
86 | const QMetaObject *extMetaObject; |
87 | QQmlCustomParser *customParser; |
88 | QQmlAttachedPropertiesFunc attachedPropertiesFunc; |
89 | const QMetaObject *attachedPropertiesType; |
90 | int propertyValueSourceCast; |
91 | int propertyValueInterceptorCast; |
92 | int finalizerCast; |
93 | bool registerEnumClassesUnscoped; |
94 | bool registerEnumsFromRelatedTypes; |
95 | bool constructValueType; |
96 | bool populateValueType; |
97 | }; |
98 | |
99 | struct QQmlSingletonTypeData |
100 | { |
101 | QQmlType::SingletonInstanceInfo *singletonInstanceInfo; |
102 | QObject *(*extFunc)(QObject *); |
103 | const QMetaObject *extMetaObject; |
104 | }; |
105 | |
106 | struct QQmlCompositeTypeData |
107 | { |
108 | QUrl url; |
109 | }; |
110 | |
111 | struct QQmlInlineTypeData |
112 | { |
113 | QUrl url; |
114 | // The containing type stores a pointer to the inline component type |
115 | // Using QQmlType here would create a reference cycle |
116 | // As the inline component type cannot outlive the containing type |
117 | // this should still be fine |
118 | QQmlTypePrivate const * containingType = nullptr; |
119 | }; |
120 | |
121 | using QQmlSequenceTypeData = QMetaSequence; |
122 | |
123 | union extraData { |
124 | QQmlCppTypeData* cd; |
125 | QQmlSingletonTypeData* sd; |
126 | QQmlCompositeTypeData* fd; |
127 | QQmlInlineTypeData* id; |
128 | QQmlSequenceTypeData* ld; |
129 | } extraData; |
130 | |
131 | const char *iid; |
132 | QHashedString module; |
133 | QString name; |
134 | QString elementName; |
135 | QMetaType typeId; |
136 | QMetaType listId; |
137 | QTypeRevision version; |
138 | QTypeRevision revision; |
139 | mutable bool containsRevisionedAttributes; |
140 | mutable QQmlType superType; |
141 | const QMetaObject *baseMetaObject; |
142 | |
143 | int index; |
144 | mutable QAtomicInteger<bool> isSetup; |
145 | mutable QAtomicInteger<bool> isEnumFromCacheSetup; |
146 | mutable QAtomicInteger<bool> isEnumFromBaseSetup; |
147 | mutable bool haveSuperType; |
148 | mutable QList<QQmlProxyMetaObject::ProxyData> metaObjects; |
149 | mutable QStringHash<int> enums; |
150 | mutable QStringHash<int> scopedEnumIndex; // maps from enum name to index in scopedEnums |
151 | mutable QList<QStringHash<int>*> scopedEnums; |
152 | |
153 | void setName(const QString &uri, const QString &element); |
154 | |
155 | private: |
156 | ~QQmlTypePrivate() override; |
157 | |
158 | struct EnumInfo { |
159 | QStringList path; |
160 | QString metaObjectName; |
161 | QString enumName; |
162 | QString enumKey; |
163 | QString metaEnumScope; |
164 | bool scoped; |
165 | }; |
166 | |
167 | void createListOfPossibleConflictingItems(const QMetaObject *metaObject, QList<EnumInfo> &enumInfoList, QStringList path) const; |
168 | void createEnumConflictReport(const QMetaObject *metaObject, const QString &conflictingKey) const; |
169 | }; |
170 | |
171 | QT_END_NAMESPACE |
172 | |
173 | #endif // QQMLTYPE_P_P_H |
174 |