Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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{
40
41public:
42
43 enum class RegistrationResult {
44 Success,
45 Failure,
46 NoRegistrationFunction
47 };
48
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
72
73 static QQmlType findCompositeType(
74 const QUrl &url,
75 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit,
76 CompositeTypeLookupMode mode = NonSingleton);
77 static QQmlType findInlineComponentType(
78 const QUrl &url,
79 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
81 const QUrl &baseUrl, const QString &name,
82 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit)
83 {
84 return findInlineComponentType(inlineComponentUrl(baseUrl, name), compilationUnit);
85 }
86
87 static void unregisterInternalCompositeType(QMetaType metaType, QMetaType listMetaType);
88 static QQmlType registerType(const QQmlPrivate::RegisterType &type);
89 static QQmlType registerInterface(const QQmlPrivate::RegisterInterface &type);
90 static QQmlType registerSingletonType(
93 static QQmlType registerCompositeSingletonType(
96 static QQmlType registerCompositeType(const QQmlPrivate::RegisterCompositeType &type);
97 static RegistrationResult registerPluginTypes(QObject *instance, const QString &basePath,
98 const QString &uri, const QString &typeNamespace,
99 QTypeRevision version, QList<QQmlError> *errors);
100
101 static QQmlType typeForUrl(const QString &urlString, const QHashedStringRef& typeName,
102 CompositeTypeLookupMode mode, QList<QQmlError> *errors,
103 QTypeRevision version = QTypeRevision());
104
105 static QQmlType fetchOrCreateInlineComponentTypeForUrl(const QUrl &url);
106 static QQmlType inlineComponentType(const QQmlType &outerType, const QString &name)
107 {
108 return outerType.isComposite()
109 ? fetchOrCreateInlineComponentTypeForUrl(
110 inlineComponentUrl(outerType.sourceUrl(), name))
111 : QQmlType();
112 }
113
114 static void unregisterType(int type);
115
116 static void registerMetaObjectForType(const QMetaObject *metaobject, QQmlTypePrivate *type);
117
118 static void registerModule(const char *uri, QTypeRevision version);
119 static bool protectModule(const QString &uri, QTypeRevision version,
120 bool weakProtectAllVersions = false);
121
122 static void registerModuleImport(const QString &uri, QTypeRevision version,
123 const QQmlDirParser::Import &import);
124 static void unregisterModuleImport(const QString &uri, QTypeRevision version,
125 const QQmlDirParser::Import &import);
126 static QList<QQmlDirParser::Import> moduleImports(const QString &uri, QTypeRevision version);
127
128 static int typeId(const char *uri, QTypeRevision version, const char *qmlName);
129
130 static void registerUndeletableType(const QQmlType &dtype);
131
132 static QList<QString> qmlTypeNames();
133 static QList<QQmlType> qmlTypes();
134 static QList<QQmlType> qmlSingletonTypes();
135 static QList<QQmlType> qmlAllTypes();
136
137 static QQmlType qmlType(const QString &qualifiedName, QTypeRevision version);
138 static QQmlType qmlType(const QHashedStringRef &name, const QHashedStringRef &module, QTypeRevision version);
139 static QQmlType qmlType(const QMetaObject *);
140 static QQmlType qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, QTypeRevision version);
141 static QQmlType qmlTypeById(int qmlTypeId);
142
143 static QQmlType qmlType(QMetaType metaType);
144 static QQmlType qmlListType(QMetaType metaType);
145
146 static QQmlType qmlType(const QUrl &unNormalizedUrl, bool includeNonFileImports = false);
147
148 static QQmlPropertyCache::ConstPtr propertyCache(
149 QObject *object, QTypeRevision version = QTypeRevision());
150 static QQmlPropertyCache::ConstPtr propertyCache(
152 static QQmlPropertyCache::ConstPtr propertyCache(
153 const QQmlType &type, QTypeRevision version);
154
155 // These methods may be called from the loader thread
156 static QQmlMetaObject rawMetaObjectForType(QMetaType metaType);
157 static QQmlMetaObject metaObjectForType(QMetaType metaType);
158 static QQmlPropertyCache::ConstPtr propertyCacheForType(QMetaType metaType);
159 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(QMetaType metaType);
160 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(
161 QMetaType metaType, QTypeRevision version);
162
163 static void freeUnusedTypesAndCaches();
164
165 static QMetaProperty defaultProperty(const QMetaObject *);
166 static QMetaProperty defaultProperty(QObject *);
167 static QMetaMethod defaultMethod(const QMetaObject *);
168 static QMetaMethod defaultMethod(QObject *);
169
170 static QObject *toQObject(const QVariant &, bool *ok = nullptr);
171
172 static QMetaType listValueType(QMetaType type);
173 static QQmlAttachedPropertiesFunc attachedPropertiesFunc(QQmlEnginePrivate *,
174 const QMetaObject *);
175 static bool isInterface(QMetaType type);
176 static const char *interfaceIId(QMetaType type);
177 static bool isList(QMetaType type);
178
179 static QTypeRevision latestModuleVersion(const QString &uri);
180 static bool isStronglyLockedModule(const QString &uri, QTypeRevision version);
181 static QTypeRevision matchingModuleVersion(const QString &module, QTypeRevision version);
182 static QQmlTypeModule *typeModule(const QString &uri, QTypeRevision version);
183
184 static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
185
187 NoError,
188 NoUnitFound,
189 VersionMismatch,
190 NotFullyTyped
191 };
192
193 enum CacheMode { RejectAll, AcceptUntyped, RequireFullyTyped };
194 static const QQmlPrivate::CachedQmlUnit *findCachedCompilationUnit(
195 const QUrl &uri, CacheMode mode, CachedUnitLookupError *status);
196
197 // used by tst_qqmlcachegen.cpp
198 static void prependCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
199 static void removeCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
200
201 static QString prettyTypeName(const QObject *object);
202
203 template <typename QQmlTypeContainer>
204 static void removeQQmlTypePrivate(QQmlTypeContainer &container,
206 {
207 for (typename QQmlTypeContainer::iterator it = container.begin(); it != container.end();) {
208 if (*it == reference)
209 it = container.erase(it);
210 else
211 ++it;
212 }
213 }
214
215 template <typename InlineComponentContainer>
217 InlineComponentContainer &container, const QQmlTypePrivate *reference)
218 {
219 const QUrl referenceUrl = QQmlType(reference).sourceUrl();
220 for (auto it = container.begin(), end = container.end(); it != end;) {
221 if (equalBaseUrls(it.key(), referenceUrl))
222 it = container.erase(it);
223 else
224 ++it;
225 }
226 }
227
228 static void registerTypeAlias(int typeId, const QString &name);
229
230 static int registerAutoParentFunction(const QQmlPrivate::RegisterAutoParent &autoparent);
231 static void unregisterAutoParentFunction(const QQmlPrivate::AutoParentFunction &function);
232
233 static QQmlType registerSequentialContainer(
234 const QQmlPrivate::RegisterSequentialContainer &sequenceRegistration);
235 static void unregisterSequentialContainer(int id);
236
237 static int registerUnitCacheHook(const QQmlPrivate::RegisterQmlUnitCacheHook &hookRegistration);
238 static void clearTypeRegistrations();
239
240 static QList<QQmlProxyMetaObject::ProxyData> proxyData(const QMetaObject *mo,
241 const QMetaObject *baseMetaObject,
242 QMetaObject *lastMetaObject);
243
245 CloneAll, // default
246 CloneEnumsOnly, // skip properties and methods
247 };
248 static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
249 const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd,
250 ClonePolicy policy);
251
252 static void qmlInsertModuleRegistration(const QString &uri, void (*registerFunction)());
253 static void qmlRemoveModuleRegistration(const QString &uri);
254
255 static bool qmlRegisterModuleTypes(const QString &uri);
256
257 static bool isValueType(QMetaType type);
258 static QQmlValueType *valueType(QMetaType metaType);
259 static const QMetaObject *metaObjectForValueType(QMetaType type);
260
261 static QQmlPropertyCache::ConstPtr findPropertyCacheInCompositeTypes(QMetaType t);
262 static void registerInternalCompositeType(
263 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
264 static void unregisterInternalCompositeType(
265 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
266 static int countInternalCompositeTypeSelfReferences(
267 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &compilationUnit);
268 static QQmlRefPointer<QV4::CompiledData::CompilationUnit> obtainCompilationUnit(
270 static QQmlRefPointer<QV4::CompiledData::CompilationUnit> obtainCompilationUnit(
271 const QUrl &url);
272};
273
275
276// used in QQmlListMetaType to tag the metatpye
278 return nullptr;
279};
280
282 return QQmlMetaType::metaObjectForType(QMetaType(iface)).metaObject();
283};
284
285// metatype interface for composite QML types
287{
290 : QMetaTypeInterface {
291 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
292 /*.alignment=*/ alignof(QObject *),
293 /*.size=*/ sizeof(QObject *),
294 /*.flags=*/ QtPrivate::QMetaTypeTypeFlags<QObject *>::Flags,
295 /*.typeId=*/ 0,
296 /*.metaObjectFn=*/ &dynamicQmlMetaObject,
297 /*.name=*/ name.constData(),
298 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
299 *static_cast<QObject **>(addr) = nullptr;
300 },
301 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
302 *static_cast<QObject **>(addr) = *static_cast<QObject *const *>(other);
303 },
304 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
305 *static_cast<QObject **>(addr) = *static_cast<QObject **>(other);
306 },
307 /*.dtor=*/ [](const QMetaTypeInterface *, void *) {},
308 /*.equals*/ nullptr,
309 /*.lessThan*/ nullptr,
310 /*.debugStream=*/ nullptr,
311 /*.dataStreamOut=*/ nullptr,
312 /*.dataStreamIn=*/ nullptr,
313 /*.legacyRegisterOp=*/ nullptr
314 }
315 , name(name) { }
316};
317
318// metatype for qml list types
320{
322 // if this interface is for list<type>; valueType stores the interface for type
325 : QMetaTypeInterface {
326 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
327 /*.alignment=*/ alignof(QQmlListProperty<QObject>),
328 /*.size=*/ sizeof(QQmlListProperty<QObject>),
329 /*.flags=*/ QtPrivate::QMetaTypeTypeFlags<QQmlListProperty<QObject>>::Flags,
330 /*.typeId=*/ 0,
331 /*.metaObjectFn=*/ &dynamicQmlListMarker,
332 /*.name=*/ name.constData(),
333 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
334 new (addr) QQmlListProperty<QObject> ();
335 },
336 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
337 new (addr) QQmlListProperty<QObject>(
338 *static_cast<const QQmlListProperty<QObject> *>(other));
339 },
340 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
341 new (addr) QQmlListProperty<QObject>(
342 std::move(*static_cast<QQmlListProperty<QObject> *>(other)));
343 },
344 /*.dtor=*/ [](const QMetaTypeInterface *, void *addr) {
345 static_cast<QQmlListProperty<QObject> *>(addr)->~QQmlListProperty<QObject>();
346 },
347 /*.equals*/ nullptr,
348 /*.lessThan*/ nullptr,
349 /*.debugStream=*/ nullptr,
350 /*.dataStreamOut=*/ nullptr,
351 /*.dataStreamIn=*/ nullptr,
352 /*.legacyRegisterOp=*/ nullptr
353 }
354 , name(name), valueType(valueType) { }
355};
356
358
359#endif // QQMLMETATYPE_P_H
360
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qmetaobject.h:19
\inmodule QtCore
\inmodule QtCore
Definition qmetatype.h:341
\inmodule QtCore
Definition qobject.h:103
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
static bool equalBaseUrls(const QUrl &aUrl, const QUrl &bUrl)
static QQmlType inlineComponentType(const QQmlType &outerType, const QString &name)
static QQmlMetaObject metaObjectForType(QMetaType metaType)
static QUrl inlineComponentUrl(const QUrl &baseUrl, const QString &name)
static void removeFromInlineComponents(InlineComponentContainer &container, const QQmlTypePrivate *reference)
static QQmlType findInlineComponentType(const QUrl &baseUrl, const QString &name, const QQmlRefPointer< QV4::CompiledData::CompilationUnit > &compilationUnit)
static void removeQQmlTypePrivate(QQmlTypeContainer &container, const QQmlTypePrivate *reference)
QUrl sourceUrl() const
Definition qqmltype.cpp:767
\inmodule QtCore
Definition qmutex.h:309
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
\inmodule QtCore
Definition qurl.h:94
void setFragment(const QString &fragment, ParsingMode mode=TolerantMode)
Sets the fragment of the URL to fragment.
Definition qurl.cpp:2648
\inmodule QtCore
Definition qvariant.h:65
static constexpr ushort CurrentRevision
Definition qmetatype.h:275
QSet< QString >::iterator it
auto mo
[7]
const CachedQmlUnit *(* QmlUnitCacheLookupFunction)(const QUrl &url)
AutoParentResult(* AutoParentFunction)(QObject *object, QObject *parent)
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
Flags
const char * typeName
GLenum mode
GLuint GLuint end
GLint reference
GLenum type
GLuint name
GLenum const void * addr
GLdouble GLdouble t
Definition qopenglext.h:243
int qmlTypeId(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
Definition qqml.cpp:357
const QMetaObject * dynamicQmlListMarker(const QtPrivate::QMetaTypeInterface *)
const QMetaObject * dynamicQmlMetaObject(const QtPrivate::QMetaTypeInterface *iface)
QQmlPrivate::QQmlAttachedPropertiesFunc< QObject > QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:63
@ Success
Definition main.cpp:3325
@ NoError
Definition main.cpp:34
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
QUrl url("example.com")
[constructor-url-reference]
QUrl baseUrl
obj metaObject() -> className()
QSharedPointer< T > other(t)
[5]
QSizePolicy policy
\inmodule QtCore
QQmlListMetaTypeInterface(const QByteArray &name, const QtPrivate::QMetaTypeInterface *valueType)
const QtPrivate::QMetaTypeInterface * valueType
const QByteArray name
QQmlMetaTypeInterface(const QByteArray &name)