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, 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
151 static QQmlType qmlType(QMetaType metaType);
152 static QQmlType qmlListType(QMetaType metaType);
153
154 static QQmlType qmlType(const QUrl &unNormalizedUrl);
155
156 static QQmlPropertyCache::ConstPtr propertyCache(
157 QObject *object, QTypeRevision version = QTypeRevision());
158 static QQmlPropertyCache::ConstPtr propertyCache(
159 const QMetaObject *metaObject, QTypeRevision version = QTypeRevision());
160 static QQmlPropertyCache::ConstPtr propertyCache(
161 const QQmlType &type, QTypeRevision version);
162
163 // These methods may be called from the loader thread
164 static QQmlMetaObject rawMetaObjectForType(QMetaType metaType);
165 static QQmlMetaObject metaObjectForType(QMetaType metaType);
166 static QQmlPropertyCache::ConstPtr propertyCacheForType(QMetaType metaType);
167 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(QMetaType metaType);
168 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(
169 QMetaType metaType, QTypeRevision version);
170
171 static void freeUnusedTypesAndCaches();
172
173 static QMetaProperty defaultProperty(const QMetaObject *);
174 static QMetaProperty defaultProperty(QObject *);
175 static QMetaMethod defaultMethod(const QMetaObject *);
176 static QMetaMethod defaultMethod(QObject *);
177
178 static QObject *toQObject(const QVariant &, bool *ok = nullptr);
179
180 static QMetaType listValueType(QMetaType type);
181 static QQmlAttachedPropertiesFunc attachedPropertiesFunc(
182 QQmlTypeLoader *typeLoader, const QMetaObject *);
183 static bool isInterface(QMetaType type);
184 static const char *interfaceIId(QMetaType type);
185 static bool isList(QMetaType type);
186
187 static QTypeRevision latestModuleVersion(const QString &uri);
188 static bool isStronglyLockedModule(const QString &uri, QTypeRevision version);
189 static QTypeRevision matchingModuleVersion(const QString &module, QTypeRevision version);
190 static QQmlTypeModule *typeModule(const QString &uri, QTypeRevision version);
191
192 static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
193
194 enum class CachedUnitLookupError {
195 NoError,
196 NoUnitFound,
197 VersionMismatch,
198 NotFullyTyped
199 };
200
201 enum CacheMode { RejectAll, AcceptUntyped, RequireFullyTyped };
202 static const QQmlPrivate::CachedQmlUnit *findCachedCompilationUnit(
203 const QUrl &uri, CacheMode mode, CachedUnitLookupError *status);
204
205 // used by tst_qqmlcachegen.cpp
206 static void prependCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
207 static void removeCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
208
209 static QString prettyTypeName(const QObject *object);
210
211 template <typename QQmlTypeContainer>
212 static void removeQQmlTypePrivate(QQmlTypeContainer &container,
213 const QQmlTypePrivate *reference)
214 {
215 for (typename QQmlTypeContainer::iterator it = container.begin(); it != container.end();) {
216 if (*it == reference)
217 it = container.erase(it);
218 else
219 ++it;
220 }
221 }
222
223 template <typename InlineComponentContainer>
224 static void removeFromInlineComponents(
225 InlineComponentContainer &container, const QQmlTypePrivate *reference)
226 {
227 const QUrl referenceUrl = QQmlType(reference).sourceUrl();
228 for (auto it = container.begin(), end = container.end(); it != end;) {
229 if (equalBaseUrls(it.key(), referenceUrl))
230 it = container.erase(it);
231 else
232 ++it;
233 }
234 }
235
236 static void registerTypeAlias(int typeId, const QString &name);
237
238 static int registerAutoParentFunction(const QQmlPrivate::RegisterAutoParent &autoparent);
239 static void unregisterAutoParentFunction(const QQmlPrivate::AutoParentFunction &function);
240
241 static QQmlType registerSequentialContainer(
242 const QQmlPrivate::RegisterSequentialContainer &sequenceRegistration);
243 static void unregisterSequentialContainer(int id);
244
245 static int registerUnitCacheHook(const QQmlPrivate::RegisterQmlUnitCacheHook &hookRegistration);
246 static void clearTypeRegistrations();
247
248 static QList<QQmlProxyMetaObject::ProxyData> proxyData(const QMetaObject *mo,
249 const QMetaObject *baseMetaObject,
250 QMetaObject *lastMetaObject);
251
252 enum ClonePolicy {
253 CloneAll, // default
254 CloneEnumsOnly, // skip properties and methods
255 };
256 static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
257 const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd,
258 ClonePolicy policy);
259
260 static void qmlInsertModuleRegistration(const QString &uri, void (*registerFunction)());
261 static void qmlRemoveModuleRegistration(const QString &uri);
262
263 static bool qmlRegisterModuleTypes(const QString &uri);
264
265 static bool isValueType(QMetaType type);
266 static QQmlValueType *valueType(QMetaType metaType);
267 static const QMetaObject *metaObjectForValueType(QMetaType type);
268
269 static QQmlPropertyCache::ConstPtr findPropertyCacheInCompositeTypes(QMetaType t);
270 static void registerInternalCompositeType(
271 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
272 static void unregisterInternalCompositeType(
273 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
274 static int countInternalCompositeTypeSelfReferences(
275 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
276 static QQmlRefPointer<QV4::CompiledData::CompilationUnit> obtainCompilationUnit(
277 QMetaType type);
278 static QQmlRefPointer<QV4::CompiledData::CompilationUnit> obtainCompilationUnit(
279 const QUrl &url);
280};
281
282Q_DECLARE_TYPEINFO(QQmlMetaType, Q_RELOCATABLE_TYPE);
283
284// used in QQmlListMetaType to tag the metatpye
285inline const QMetaObject *dynamicQmlListMarker(const QtPrivate::QMetaTypeInterface *) {
286 return nullptr;
287};
288
289inline const QMetaObject *dynamicQmlMetaObject(const QtPrivate::QMetaTypeInterface *iface) {
290 return QQmlMetaType::metaObjectForType(QMetaType(iface)).metaObject();
291};
292
293// metatype interface for composite QML types
295{
297 QQmlMetaTypeInterface(QByteArray name)
299 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
300 /*.alignment=*/ alignof(QObject *),
301 /*.size=*/ sizeof(QObject *),
302 /*.flags=*/ QtPrivate::QMetaTypeForType<QObject *>::flags(),
303 /*.typeId=*/ 0,
304 /*.metaObjectFn=*/ &dynamicQmlMetaObject,
305 /*.name=*/ name.constData(),
306 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
307 *static_cast<QObject **>(addr) = nullptr;
308 },
309 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
310 *static_cast<QObject **>(addr) = *static_cast<QObject *const *>(other);
311 },
312 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
313 *static_cast<QObject **>(addr) = *static_cast<QObject **>(other);
314 },
315 /*.dtor=*/ [](const QMetaTypeInterface *, void *) {},
316 /*.equals*/ nullptr,
317 /*.lessThan*/ nullptr,
318 /*.debugStream=*/ nullptr,
319 /*.dataStreamOut=*/ nullptr,
320 /*.dataStreamIn=*/ nullptr,
321 /*.legacyRegisterOp=*/ nullptr
322 }
323 , name(std::move(name)) { }
324};
325
326// metatype for qml list types
328{
330 // if this interface is for list<type>; valueType stores the interface for type
332 QQmlListMetaTypeInterface(QByteArray name, const QtPrivate::QMetaTypeInterface *valueType)
334 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
335 /*.alignment=*/ alignof(QQmlListProperty<QObject>),
336 /*.size=*/ sizeof(QQmlListProperty<QObject>),
338 /*.typeId=*/ 0,
339 /*.metaObjectFn=*/ &dynamicQmlListMarker,
340 /*.name=*/ name.constData(),
341 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
342 new (addr) QQmlListProperty<QObject> ();
343 },
344 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
346 *static_cast<const QQmlListProperty<QObject> *>(other));
347 },
348 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
350 std::move(*static_cast<QQmlListProperty<QObject> *>(other)));
351 },
352 /*.dtor=*/ [](const QMetaTypeInterface *, void *addr) {
354 },
355 /*.equals*/ nullptr,
356 /*.lessThan*/ nullptr,
357 /*.debugStream=*/ nullptr,
358 /*.dataStreamOut=*/ nullptr,
359 /*.dataStreamIn=*/ nullptr,
360 /*.legacyRegisterOp=*/ nullptr
361 }
363};
364
365QT_END_NAMESPACE
366
367#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 QtCore
Definition qmutex.h:342
Definition qjsvalue.h:23
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)
QQmlListMetaTypeInterface(QByteArray name, const QtPrivate::QMetaTypeInterface *valueType)
const QtPrivate::QMetaTypeInterface * valueType
QQmlMetaTypeInterface(QByteArray name)