1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2019 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQml module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QQMLTYPE_P_P_H |
41 | #define QQMLTYPE_P_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists purely as an |
48 | // implementation detail. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <private/qqmltype_p.h> |
55 | #include <private/qstringhash_p.h> |
56 | #include <private/qqmlproxymetaobject_p.h> |
57 | #include <private/qqmlrefcount_p.h> |
58 | #include <private/qqmlpropertycache_p.h> |
59 | #include <private/qqmlmetatype_p.h> |
60 | |
61 | QT_BEGIN_NAMESPACE |
62 | |
63 | class QQmlTypePrivate : public QQmlRefCount |
64 | { |
65 | Q_DISABLE_COPY_MOVE(QQmlTypePrivate) |
66 | public: |
67 | QQmlTypePrivate(QQmlType::RegistrationType type); |
68 | |
69 | void init() const; |
70 | void initEnums(QQmlEnginePrivate *engine) const; |
71 | void insertEnums(const QMetaObject *metaObject) const; |
72 | void insertEnumsFromPropertyCache(const QQmlPropertyCache *cache) const; |
73 | void setContainingType(QQmlType *containingType); |
74 | |
75 | QUrl sourceUrl() const |
76 | { |
77 | switch (regType) { |
78 | case QQmlType::CompositeType: |
79 | return extraData.fd->url; |
80 | case QQmlType::CompositeSingletonType: |
81 | return extraData.sd->singletonInstanceInfo->url; |
82 | case QQmlType::InlineComponentType: |
83 | return extraData.id->url; |
84 | default: |
85 | return QUrl(); |
86 | } |
87 | } |
88 | |
89 | const QQmlTypePrivate *attachedPropertiesBase(QQmlEnginePrivate *engine) const |
90 | { |
91 | for (const QQmlTypePrivate *d = this; d; d = d->resolveCompositeBaseType(engine).d.data()) { |
92 | if (d->regType == QQmlType::CppType) |
93 | return d->extraData.cd->attachedPropertiesType ? d : nullptr; |
94 | |
95 | if (d->regType != QQmlType::CompositeType) |
96 | return nullptr; |
97 | } |
98 | return nullptr; |
99 | } |
100 | |
101 | bool isComposite() const |
102 | { |
103 | return regType == QQmlType::CompositeType || regType == QQmlType::CompositeSingletonType; |
104 | } |
105 | |
106 | QQmlType resolveCompositeBaseType(QQmlEnginePrivate *engine) const; |
107 | QQmlPropertyCache *compositePropertyCache(QQmlEnginePrivate *engine) const; |
108 | |
109 | QQmlType::RegistrationType regType; |
110 | |
111 | struct QQmlCppTypeData |
112 | { |
113 | int allocationSize; |
114 | void (*newFunc)(void *); |
115 | QString noCreationReason; |
116 | int parserStatusCast; |
117 | QObject *(*extFunc)(QObject *); |
118 | const QMetaObject *extMetaObject; |
119 | QQmlCustomParser *customParser; |
120 | QQmlAttachedPropertiesFunc attachedPropertiesFunc; |
121 | const QMetaObject *attachedPropertiesType; |
122 | int propertyValueSourceCast; |
123 | int propertyValueInterceptorCast; |
124 | bool registerEnumClassesUnscoped; |
125 | }; |
126 | |
127 | struct QQmlSingletonTypeData |
128 | { |
129 | QQmlType::SingletonInstanceInfo *singletonInstanceInfo; |
130 | }; |
131 | |
132 | struct QQmlCompositeTypeData |
133 | { |
134 | QUrl url; |
135 | }; |
136 | |
137 | struct QQmlInlineTypeData |
138 | { |
139 | QUrl url = QUrl(); |
140 | // The containing type stores a pointer to the inline component type |
141 | // Using QQmlType here would create a reference cycle |
142 | // As the inline component type cannot outlive the containing type |
143 | // this should still be fine |
144 | QQmlTypePrivate const * containingType = nullptr; |
145 | QString inlineComponentName = QString(); |
146 | int objectId = -1; |
147 | }; |
148 | |
149 | union { |
150 | QQmlCppTypeData* ; |
151 | QQmlSingletonTypeData* ; |
152 | QQmlCompositeTypeData* ; |
153 | QQmlInlineTypeData* ; |
154 | } ; |
155 | |
156 | const char *iid; |
157 | QHashedString module; |
158 | QString name; |
159 | QString elementName; |
160 | int version_maj; |
161 | int version_min; |
162 | int typeId; |
163 | int listId; |
164 | int revision; |
165 | mutable bool containsRevisionedAttributes; |
166 | mutable QQmlType superType; |
167 | const QMetaObject *baseMetaObject; |
168 | |
169 | int index; |
170 | mutable volatile bool isSetup:1; |
171 | mutable volatile bool isEnumFromCacheSetup:1; |
172 | mutable volatile bool isEnumFromBaseSetup:1; |
173 | mutable bool haveSuperType:1; |
174 | mutable QList<QQmlProxyMetaObject::ProxyData> metaObjects; |
175 | mutable QStringHash<int> enums; |
176 | mutable QStringHash<int> scopedEnumIndex; // maps from enum name to index in scopedEnums |
177 | mutable QList<QStringHash<int>*> scopedEnums; |
178 | |
179 | void setName(const QString &uri, const QString &element); |
180 | mutable QHash<QString, int> namesToInlineComponentObjectIndex; |
181 | mutable QHash<int, QQmlType> objectIdToICType; |
182 | |
183 | private: |
184 | ~QQmlTypePrivate() override; |
185 | |
186 | struct EnumInfo { |
187 | QStringList path; |
188 | QString metaObjectName; |
189 | QString enumName; |
190 | QString enumKey; |
191 | QString metaEnumScope; |
192 | bool scoped; |
193 | }; |
194 | |
195 | void createListOfPossibleConflictingItems(const QMetaObject *metaObject, QList<EnumInfo> &enumInfoList, QStringList path) const; |
196 | void createEnumConflictReport(const QMetaObject *metaObject, const QString &conflictingKey) const; |
197 | }; |
198 | |
199 | QT_END_NAMESPACE |
200 | |
201 | #endif // QQMLTYPE_P_P_H |
202 | |