Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlmetatype_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QQMLMETATYPE_P_H
5#define QQMLMETATYPE_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/qqmldirparser_p.h>
19#include <private/qqmlmetaobject_p.h>
20#include <private/qqmlproxymetaobject_p.h>
21#include <private/qqmltype_p.h>
22#include <private/qtqmlglobal_p.h>
23
25
26class QQmlTypeModule;
27class QRecursiveMutex;
28class QQmlError;
29class QQmlValueType;
30
31namespace QV4 {
32namespace CompiledData {
33struct CompilationUnit;
34}
35}
36
37class Q_QML_EXPORT QQmlMetaType
38{
39 friend class QQmlDesignerMetaObject;
40
41public:
42
43 enum class RegistrationResult {
44 Success,
45 Failure,
46 NoRegistrationFunction
47 };
48
49 static QUrl inlineComponentUrl(const QUrl &baseUrl, const QString &name)
50 {
51 QUrl icUrl = baseUrl;
52 icUrl.setFragment(name);
53 return icUrl;
54 }
55
56 static bool equalBaseUrls(const QUrl &aUrl, const QUrl &bUrl)
57 {
58 // Everything but fragment has to match
59 return aUrl.port() == bUrl.port()
60 && aUrl.scheme() == bUrl.scheme()
61 && aUrl.userName() == bUrl.userName()
62 && aUrl.password() == bUrl.password()
63 && aUrl.host() == bUrl.host()
64 && aUrl.path() == bUrl.path()
65 && aUrl.query() == bUrl.query();
66 }
67
68 static QUrl normalizedUrl(const QUrl &unNormalizedUrl)
69 {
70 QUrl normalized(unNormalizedUrl);
71 if (normalized.scheme() == QLatin1String("qrc"))
72 normalized.setHost(QString()); // map qrc:///a.qml to qrc:/a.qml
73 return normalized;
74 }
75
76 enum CompositeTypeLookupMode {
77 NonSingleton,
78 Singleton,
79 JavaScript,
80 };
81
82 static QQmlType findCompositeType(
83 const QUrl &url,
84 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit,
85 CompositeTypeLookupMode mode = NonSingleton);
86 static QQmlType findInlineComponentType(
87 const QUrl &url,
88 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
89 static QQmlType findInlineComponentType(
90 const QUrl &baseUrl, const QString &name,
91 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit)
92 {
93 return findInlineComponentType(inlineComponentUrl(baseUrl, name), compilationUnit);
94 }
95
96 static QQmlType registerType(const QQmlPrivate::RegisterType &type);
97 static QQmlType registerInterface(const QQmlPrivate::RegisterInterface &type);
98 static QQmlType registerSingletonType(
99 const QQmlPrivate::RegisterSingletonType &type,
100 const QQmlType::SingletonInstanceInfo::ConstPtr &siinfo);
101 static QQmlType registerCompositeSingletonType(
102 const QQmlPrivate::RegisterCompositeSingletonType &type,
103 const QQmlType::SingletonInstanceInfo::ConstPtr &siinfo);
104 static QQmlType registerCompositeType(const QQmlPrivate::RegisterCompositeType &type);
105 static RegistrationResult registerPluginTypes(QObject *instance, const QString &basePath,
106 const QString &uri, const QString &typeNamespace,
107 QTypeRevision version, QList<QQmlError> *errors);
108
109 static QQmlType typeForUrl(
110 const QUrl &url, const QHashedStringRef &typeName, CompositeTypeLookupMode mode,
111 QList<QQmlError> *errors, QTypeRevision version = QTypeRevision());
112
113 static QQmlType fetchOrCreateInlineComponentTypeForUrl(const QUrl &url);
114 static QQmlType inlineComponentType(const QQmlType &outerType, const QString &name)
115 {
116 return outerType.isComposite()
117 ? fetchOrCreateInlineComponentTypeForUrl(
118 inlineComponentUrl(outerType.sourceUrl(), name))
119 : QQmlType();
120 }
121
122 static void unregisterType(int type);
123
124 static void registerMetaObjectForType(const QMetaObject *metaobject, const QQmlTypePrivate *type);
125
126 static void registerModule(const char *uri, QTypeRevision version);
127 static bool protectModule(const QString &uri, QTypeRevision version,
128 bool weakProtectAllVersions = false);
129
130 static void registerModuleImport(const QString &uri, QTypeRevision version,
131 const QQmlDirParser::Import &import);
132 static void unregisterModuleImport(const QString &uri, QTypeRevision version,
133 const QQmlDirParser::Import &import);
134 static QList<QQmlDirParser::Import> moduleImports(const QString &uri, QTypeRevision version);
135
136 static int typeId(const char *uri, QTypeRevision version, const char *qmlName);
137
138 static void registerUndeletableType(const QQmlType &dtype);
139
140 static QList<QString> qmlTypeNames();
141 static QList<QQmlType> qmlTypes();
142 static QList<QQmlType> qmlSingletonTypes();
143 static QList<QQmlType> qmlAllTypes();
144
145 static QQmlType qmlType(const QString &qualifiedName, QTypeRevision version);
146 static QQmlType qmlType(const QHashedStringRef &name, const QHashedStringRef &module, QTypeRevision version);
147 static QQmlType qmlType(const QMetaObject *);
148 static QQmlType qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, QTypeRevision version);
149 static QQmlType qmlTypeById(int qmlTypeId);
150 static QQmlType firstQmlTypeForAttachmentMetaObject(const QMetaObject *attachmentMetaObject);
151
152 static QQmlType qmlType(QMetaType metaType);
153 static QQmlType qmlListType(QMetaType metaType);
154
155 static QQmlType qmlType(const QUrl &unNormalizedUrl);
156
157 static QQmlPropertyCache::ConstPtr propertyCache(
158 QObject *object, QTypeRevision version = QTypeRevision());
159 static QQmlPropertyCache::ConstPtr propertyCache(
160 const QMetaObject *metaObject, QTypeRevision version = QTypeRevision());
161 static QQmlPropertyCache::ConstPtr propertyCache(
162 const QQmlType &type, QTypeRevision version);
163
164 // These methods may be called from the loader thread
165 static QQmlMetaObject rawMetaObjectForType(QMetaType metaType);
166 static QQmlMetaObject metaObjectForType(QMetaType metaType);
167 static QQmlPropertyCache::ConstPtr propertyCacheForType(QMetaType metaType);
168 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(QMetaType metaType);
169 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(
170 QMetaType metaType, QTypeRevision version);
171 static bool canConvert(QObject *o, QMetaType metaType);
172
173 static void freeUnusedTypesAndCaches();
174
175 static QMetaProperty defaultProperty(const QMetaObject *);
176 static QMetaProperty defaultProperty(QObject *);
177 static QMetaMethod defaultMethod(const QMetaObject *);
178 static QMetaMethod defaultMethod(QObject *);
179
180 static QObject *toQObject(const QVariant &, bool *ok = nullptr);
181
182 static QMetaType listValueType(QMetaType type);
183 static QQmlAttachedPropertiesFunc attachedPropertiesFunc(
184 QQmlTypeLoader *typeLoader, const QMetaObject *);
185 static bool isInterface(QMetaType type);
186 static const char *interfaceIId(QMetaType type);
187 static bool isList(QMetaType type);
188
189 static QTypeRevision latestModuleVersion(const QString &uri);
190 static bool isStronglyLockedModule(const QString &uri, QTypeRevision version);
191 static QTypeRevision matchingModuleVersion(const QString &module, QTypeRevision version);
192 static QQmlTypeModule *typeModule(const QString &uri, QTypeRevision version);
193
194 static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
195
196 enum class CachedUnitLookupError {
197 NoError,
198 NoUnitFound,
199 VersionMismatch,
200 NotFullyTyped
201 };
202
203 enum CacheMode { RejectAll, AcceptUntyped, RequireFullyTyped };
204 static const QQmlPrivate::CachedQmlUnit *findCachedCompilationUnit(
205 const QUrl &uri, CacheMode mode, CachedUnitLookupError *status);
206
207 // used by tst_qqmlcachegen.cpp
208 static void prependCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
209 static void removeCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
210
211 static QString prettyTypeName(const QObject *object);
212
213 template <typename QQmlTypeContainer>
214 static void removeQQmlTypePrivate(QQmlTypeContainer &container,
215 const QQmlTypePrivate *reference)
216 {
217 for (typename QQmlTypeContainer::iterator it = container.begin(); it != container.end();) {
218 if (*it == reference)
219 it = container.erase(it);
220 else
221 ++it;
222 }
223 }
224
225 template <typename InlineComponentContainer>
226 static void removeFromInlineComponents(
227 InlineComponentContainer &container, const QQmlTypePrivate *reference)
228 {
229 const QUrl referenceUrl = QQmlType(reference).sourceUrl();
230 for (auto it = container.begin(), end = container.end(); it != end;) {
231 if (equalBaseUrls(it.key(), referenceUrl))
232 it = container.erase(it);
233 else
234 ++it;
235 }
236 }
237
238 static void registerTypeAlias(int typeId, const QString &name);
239
240 static int registerAutoParentFunction(const QQmlPrivate::RegisterAutoParent &autoparent);
241 static void unregisterAutoParentFunction(const QQmlPrivate::AutoParentFunction &function);
242
243 static QQmlType registerSequentialContainer(
244 const QQmlPrivate::RegisterSequentialContainer &sequenceRegistration);
245 static void unregisterSequentialContainer(int id);
246
247 static int registerUnitCacheHook(const QQmlPrivate::RegisterQmlUnitCacheHook &hookRegistration);
248 static void clearTypeRegistrations();
249
250 static QList<QQmlProxyMetaObject::ProxyData> proxyData(const QMetaObject *mo,
251 const QMetaObject *baseMetaObject,
252 QMetaObject *lastMetaObject);
253
254 enum ClonePolicy {
255 CloneAll, // default
256 CloneEnumsOnly, // skip properties and methods
257 };
258 static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
259 const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd,
260 ClonePolicy policy);
261
262 static void qmlInsertModuleRegistration(const QString &uri, void (*registerFunction)());
263 static void qmlRemoveModuleRegistration(const QString &uri);
264
265 static bool qmlRegisterModuleTypes(const QString &uri);
266
267 static bool isValueType(QMetaType type);
268 static QQmlValueType *valueType(QMetaType metaType);
269 static const QMetaObject *metaObjectForValueType(QMetaType type);
270
271 static QQmlPropertyCache::ConstPtr findPropertyCacheInCompositeTypes(QMetaType t);
272 static void registerInternalCompositeType(
273 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
274 static void unregisterInternalCompositeType(
275 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
276 static int countInternalCompositeTypeSelfReferences(
277 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
278 static QQmlRefPointer<QV4::CompiledData::CompilationUnit> obtainCompilationUnit(
279 QMetaType type);
280 static QQmlRefPointer<QV4::CompiledData::CompilationUnit> obtainCompilationUnit(
281 const QUrl &url);
282};
283
284Q_DECLARE_TYPEINFO(QQmlMetaType, Q_RELOCATABLE_TYPE);
285
286// used in QQmlListMetaType to tag the metatpye
287inline const QMetaObject *dynamicQmlListMarker(const QtPrivate::QMetaTypeInterface *) {
288 return nullptr;
289};
290
291inline const QMetaObject *dynamicQmlMetaObject(const QtPrivate::QMetaTypeInterface *iface) {
292 return QQmlMetaType::metaObjectForType(QMetaType(iface)).metaObject();
293};
294
295// metatype interface for composite QML types
297{
299QT_WARNING_PUSH
300QT_WARNING_DISABLE_CLANG("-Wdangling-field") // for .name
303 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
304 /*.alignment=*/ alignof(QObject *),
305 /*.size=*/ sizeof(QObject *),
306 /*.flags=*/ QtPrivate::QMetaTypeForType<QObject *>::flags(),
307 /*.typeId=*/ 0,
308 /*.metaObjectFn=*/ &dynamicQmlMetaObject,
309 /*.name=*/ name.constData(),
310 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
311 *static_cast<QObject **>(addr) = nullptr;
312 },
313 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
314 *static_cast<QObject **>(addr) = *static_cast<QObject *const *>(other);
315 },
316 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
317 *static_cast<QObject **>(addr) = *static_cast<QObject **>(other);
318 },
319 /*.dtor=*/ [](const QMetaTypeInterface *, void *) {},
320 /*.equals*/ nullptr,
321 /*.lessThan*/ nullptr,
322 /*.debugStream=*/ nullptr,
323 /*.dataStreamOut=*/ nullptr,
324 /*.dataStreamIn=*/ nullptr,
325 /*.legacyRegisterOp=*/ nullptr
326 }
327 , name(std::move(name)) { }
329};
330
331// metatype for qml list types
333{
335 // if this interface is for list<type>; valueType stores the interface for type
337QT_WARNING_PUSH
338QT_WARNING_DISABLE_CLANG("-Wdangling-field") // for .name
341 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
342 /*.alignment=*/ alignof(QQmlListProperty<QObject>),
343 /*.size=*/ sizeof(QQmlListProperty<QObject>),
345 /*.typeId=*/ 0,
346 /*.metaObjectFn=*/ &dynamicQmlListMarker,
347 /*.name=*/ name.constData(),
348 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
349 new (addr) QQmlListProperty<QObject> ();
350 },
351 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
353 *static_cast<const QQmlListProperty<QObject> *>(other));
354 },
355 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
357 std::move(*static_cast<QQmlListProperty<QObject> *>(other)));
358 },
359 /*.dtor=*/ [](const QMetaTypeInterface *, void *addr) {
361 },
362 /*.equals*/ nullptr,
363 /*.lessThan*/ nullptr,
364 /*.debugStream=*/ nullptr,
365 /*.dataStreamOut=*/ nullptr,
366 /*.dataStreamIn=*/ nullptr,
367 /*.legacyRegisterOp=*/ nullptr
368 }
371};
372
373QT_END_NAMESPACE
374
375#endif // QQMLMETATYPE_P_H
QList< QQmlError > errors
Definition qqmlinfo.cpp:158
QQmlInfoPrivate(QtMsgType type)
Definition qqmlinfo.cpp:148
const QObject * object
Definition qqmlinfo.cpp:156
QtMsgType msgType
Definition qqmlinfo.cpp:155
\inmodule QtQml
\inmodule QtCore
Definition qmutex.h:342
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
#define MESSAGE_FUNCS(FuncName, MessageLevel)
Definition qqmlinfo.cpp:223
const QMetaObject * dynamicQmlListMarker(const QtPrivate::QMetaTypeInterface *)
const QMetaObject * dynamicQmlMetaObject(const QtPrivate::QMetaTypeInterface *iface)
const QtPrivate::QMetaTypeInterface * valueType