Qt 6.x
The Qt SDK
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 { class ExecutableCompilationUnit; }
32
33class Q_QML_PRIVATE_EXPORT QQmlMetaType
34{
36
37public:
38
39 enum class RegistrationResult {
40 Success,
41 Failure,
42 NoRegistrationFunction
43 };
44
46 {
47 QUrl icUrl = baseUrl;
48 icUrl.setFragment(name);
49 return icUrl;
50 }
51
52 static bool equalBaseUrls(const QUrl &aUrl, const QUrl &bUrl)
53 {
54 // Everything but fragment has to match
55 return aUrl.port() == bUrl.port()
56 && aUrl.scheme() == bUrl.scheme()
57 && aUrl.userName() == bUrl.userName()
58 && aUrl.password() == bUrl.password()
59 && aUrl.host() == bUrl.host()
60 && aUrl.path() == bUrl.path()
61 && aUrl.query() == bUrl.query();
62 }
63
67 };
68
69 static QQmlType findCompositeType(
70 const QUrl &url, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit,
71 CompositeTypeLookupMode mode = NonSingleton);
72 static QQmlType findInlineComponentType(
73 const QUrl &url, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit);
75 const QUrl &baseUrl, const QString &name,
77 {
78 return findInlineComponentType(inlineComponentUrl(baseUrl, name), compilationUnit);
79 }
80
81 static void unregisterInternalCompositeType(QMetaType metaType, QMetaType listMetaType);
82 static QQmlType registerType(const QQmlPrivate::RegisterType &type);
83 static QQmlType registerInterface(const QQmlPrivate::RegisterInterface &type);
84 static QQmlType registerSingletonType(const QQmlPrivate::RegisterSingletonType &type);
85 static QQmlType registerCompositeSingletonType(const QQmlPrivate::RegisterCompositeSingletonType &type);
86 static QQmlType registerCompositeType(const QQmlPrivate::RegisterCompositeType &type);
87 static RegistrationResult registerPluginTypes(QObject *instance, const QString &basePath,
88 const QString &uri, const QString &typeNamespace,
89 QTypeRevision version, QList<QQmlError> *errors);
90
91 static QQmlType typeForUrl(const QString &urlString, const QHashedStringRef& typeName,
92 CompositeTypeLookupMode mode, QList<QQmlError> *errors,
93 QTypeRevision version = QTypeRevision());
94 static QQmlType inlineComponentTypeForUrl(const QUrl &url);
96 {
97 return inlineComponentTypeForUrl(inlineComponentUrl(baseUrl, name));
98 }
99
100 static void unregisterType(int type);
101
102 static void registerMetaObjectForType(const QMetaObject *metaobject, QQmlTypePrivate *type);
103
104 static void registerModule(const char *uri, QTypeRevision version);
105 static bool protectModule(const QString &uri, QTypeRevision version,
106 bool weakProtectAllVersions = false);
107
108 static void registerModuleImport(const QString &uri, QTypeRevision version,
109 const QQmlDirParser::Import &import);
110 static void unregisterModuleImport(const QString &uri, QTypeRevision version,
111 const QQmlDirParser::Import &import);
112 static QList<QQmlDirParser::Import> moduleImports(const QString &uri, QTypeRevision version);
113
114 static int typeId(const char *uri, QTypeRevision version, const char *qmlName);
115
116 static void registerUndeletableType(const QQmlType &dtype);
117
118 static QList<QString> qmlTypeNames();
119 static QList<QQmlType> qmlTypes();
120 static QList<QQmlType> qmlSingletonTypes();
121 static QList<QQmlType> qmlAllTypes();
122
123 static QQmlType qmlType(const QString &qualifiedName, QTypeRevision version);
124 static QQmlType qmlType(const QHashedStringRef &name, const QHashedStringRef &module, QTypeRevision version);
125 static QQmlType qmlType(const QMetaObject *);
126 static QQmlType qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, QTypeRevision version);
127 static QQmlType qmlTypeById(int qmlTypeId);
128
129 static QQmlType qmlType(QMetaType metaType);
130 static QQmlType qmlListType(QMetaType metaType);
131
132 static QQmlType qmlType(const QUrl &unNormalizedUrl, bool includeNonFileImports = false);
133
134 static QQmlPropertyCache::ConstPtr propertyCache(
135 QObject *object, QTypeRevision version = QTypeRevision());
136 static QQmlPropertyCache::ConstPtr propertyCache(
138 static QQmlPropertyCache::ConstPtr propertyCache(
139 const QQmlType &type, QTypeRevision version);
140
141 // These methods may be called from the loader thread
142 static QQmlMetaObject rawMetaObjectForType(QMetaType metaType);
143 static QQmlMetaObject metaObjectForType(QMetaType metaType);
144 static QQmlPropertyCache::ConstPtr propertyCacheForType(QMetaType metaType);
145 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(QMetaType metaType);
146 static QQmlPropertyCache::ConstPtr rawPropertyCacheForType(
147 QMetaType metaType, QTypeRevision version);
148
149 static void freeUnusedTypesAndCaches();
150
151 static QMetaProperty defaultProperty(const QMetaObject *);
152 static QMetaProperty defaultProperty(QObject *);
153 static QMetaMethod defaultMethod(const QMetaObject *);
154 static QMetaMethod defaultMethod(QObject *);
155
156 static QObject *toQObject(const QVariant &, bool *ok = nullptr);
157
158 static QMetaType listValueType(QMetaType type);
159 static QQmlAttachedPropertiesFunc attachedPropertiesFunc(QQmlEnginePrivate *,
160 const QMetaObject *);
161 static bool isInterface(QMetaType type);
162 static const char *interfaceIId(QMetaType type);
163 static bool isList(QMetaType type);
164
165 static QTypeRevision latestModuleVersion(const QString &uri);
166 static bool isStronglyLockedModule(const QString &uri, QTypeRevision version);
167 static QTypeRevision matchingModuleVersion(const QString &module, QTypeRevision version);
168 static QQmlTypeModule *typeModule(const QString &uri, QTypeRevision version);
169
170 static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
171
173 NoError,
174 NoUnitFound,
175 VersionMismatch,
176 NotFullyTyped
177 };
178
179 enum CacheMode { RejectAll, AcceptUntyped, RequireFullyTyped };
180 static const QQmlPrivate::CachedQmlUnit *findCachedCompilationUnit(
181 const QUrl &uri, CacheMode mode, CachedUnitLookupError *status);
182
183 // used by tst_qqmlcachegen.cpp
184 static void prependCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
185 static void removeCachedUnitLookupFunction(QQmlPrivate::QmlUnitCacheLookupFunction handler);
186
187 static QString prettyTypeName(const QObject *object);
188
189 template <typename QQmlTypeContainer>
190 static void removeQQmlTypePrivate(QQmlTypeContainer &container,
192 {
193 for (typename QQmlTypeContainer::iterator it = container.begin(); it != container.end();) {
194 if (*it == reference)
195 it = container.erase(it);
196 else
197 ++it;
198 }
199 }
200
201 template <typename InlineComponentContainer>
203 InlineComponentContainer &container, const QQmlTypePrivate *reference)
204 {
205 const QUrl referenceUrl = QQmlType(reference).sourceUrl();
206 for (auto it = container.begin(), end = container.end(); it != end;) {
207 if (equalBaseUrls(it.key(), referenceUrl))
208 it = container.erase(it);
209 else
210 ++it;
211 }
212 }
213
214 static void registerTypeAlias(int typeId, const QString &name);
215
216 static int registerAutoParentFunction(const QQmlPrivate::RegisterAutoParent &autoparent);
217 static void unregisterAutoParentFunction(const QQmlPrivate::AutoParentFunction &function);
218
219 static QQmlType registerSequentialContainer(
220 const QQmlPrivate::RegisterSequentialContainer &sequenceRegistration);
221 static void unregisterSequentialContainer(int id);
222
223 static int registerUnitCacheHook(const QQmlPrivate::RegisterQmlUnitCacheHook &hookRegistration);
224 static void clearTypeRegistrations();
225
227 const QMetaObject *baseMetaObject,
228 QMetaObject *lastMetaObject);
229
231 CloneAll, // default
232 CloneEnumsOnly, // skip properties and methods
233 };
234 static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
235 const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd,
236 ClonePolicy policy);
237
238 static void qmlInsertModuleRegistration(const QString &uri, void (*registerFunction)());
239 static void qmlRemoveModuleRegistration(const QString &uri);
240
241 static bool qmlRegisterModuleTypes(const QString &uri);
242
243 static bool isValueType(QMetaType type);
244 static QQmlValueType *valueType(QMetaType metaType);
245 static const QMetaObject *metaObjectForValueType(QMetaType type);
246 static const QMetaObject *metaObjectForValueType(const QQmlType &qmlType)
247 {
248 // Prefer the extension meta object, if any.
249 // Extensions allow registration of non-gadget value types.
250 if (const QMetaObject *extensionMetaObject = qmlType.extensionMetaObject()) {
251 // This may be a namespace even if the original metaType isn't.
252 // You can do such things with QML_FOREIGN declarations.
253 if (extensionMetaObject->metaType().flags() & QMetaType::IsGadget)
254 return extensionMetaObject;
255 }
256
257 if (const QMetaObject *qmlTypeMetaObject = qmlType.metaObject()) {
258 // This may be a namespace even if the original metaType isn't.
259 // You can do such things with QML_FOREIGN declarations.
260 if (qmlTypeMetaObject->metaType().flags() & QMetaType::IsGadget)
261 return qmlTypeMetaObject;
262 }
263
264 return nullptr;
265 }
266
267 static QQmlPropertyCache::ConstPtr findPropertyCacheInCompositeTypes(QMetaType t);
268 static void registerInternalCompositeType(
270 static void unregisterInternalCompositeType(
272 static int countInternalCompositeTypeSelfReferences(
274 static QQmlRefPointer<QV4::ExecutableCompilationUnit> obtainExecutableCompilationUnit(
276};
277
279
280// used in QQmlListMetaType to tag the metatpye
282 return nullptr;
283};
284
287};
288
289// metatype interface for composite QML types
291{
294 : QMetaTypeInterface {
295 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
296 /*.alignment=*/ alignof(QObject *),
297 /*.size=*/ sizeof(QObject *),
298 /*.flags=*/ QtPrivate::QMetaTypeTypeFlags<QObject *>::Flags,
299 /*.typeId=*/ 0,
300 /*.metaObjectFn=*/ &dynamicQmlMetaObject,
301 /*.name=*/ name.constData(),
302 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
303 *static_cast<QObject **>(addr) = nullptr;
304 },
305 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
306 *static_cast<QObject **>(addr) = *static_cast<QObject *const *>(other);
307 },
308 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
309 *static_cast<QObject **>(addr) = *static_cast<QObject **>(other);
310 },
311 /*.dtor=*/ [](const QMetaTypeInterface *, void *) {},
312 /*.equals*/ nullptr,
313 /*.lessThan*/ nullptr,
314 /*.debugStream=*/ nullptr,
315 /*.dataStreamOut=*/ nullptr,
316 /*.dataStreamIn=*/ nullptr,
317 /*.legacyRegisterOp=*/ nullptr
318 }
319 , name(name) { }
320};
321
322// metatype for qml list types
324{
326 // if this interface is for list<type>; valueType stores the interface for type
329 : QMetaTypeInterface {
330 /*.revision=*/ QMetaTypeInterface::CurrentRevision,
331 /*.alignment=*/ alignof(QQmlListProperty<QObject>),
332 /*.size=*/ sizeof(QQmlListProperty<QObject>),
333 /*.flags=*/ QtPrivate::QMetaTypeTypeFlags<QQmlListProperty<QObject>>::Flags,
334 /*.typeId=*/ 0,
335 /*.metaObjectFn=*/ &dynamicQmlListMarker,
336 /*.name=*/ name.constData(),
337 /*.defaultCtr=*/ [](const QMetaTypeInterface *, void *addr) {
339 },
340 /*.copyCtr=*/ [](const QMetaTypeInterface *, void *addr, const void *other) {
342 *static_cast<const QQmlListProperty<QObject> *>(other));
343 },
344 /*.moveCtr=*/ [](const QMetaTypeInterface *, void *addr, void *other) {
346 std::move(*static_cast<QQmlListProperty<QObject> *>(other)));
347 },
348 /*.dtor=*/ [](const QMetaTypeInterface *, void *addr) {
350 },
351 /*.equals*/ nullptr,
352 /*.lessThan*/ nullptr,
353 /*.debugStream=*/ nullptr,
354 /*.dataStreamOut=*/ nullptr,
355 /*.dataStreamIn=*/ nullptr,
356 /*.legacyRegisterOp=*/ nullptr
357 }
358 , name(name), valueType(valueType) { }
359};
360
362
363#endif // QQMLMETATYPE_P_H
364
\inmodule QtCore
Definition qbytearray.h:57
Definition qlist.h:74
\inmodule QtCore
Definition qmetaobject.h:18
\inmodule QtCore
\inmodule QtCore
Definition qmetatype.h:320
\inmodule QtCore
Definition qobject.h:90
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
const QMetaObject * metaObject() const
static bool equalBaseUrls(const QUrl &aUrl, const QUrl &bUrl)
static QQmlType findInlineComponentType(const QUrl &baseUrl, const QString &name, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit)
static QQmlMetaObject metaObjectForType(QMetaType metaType)
static const QMetaObject * metaObjectForValueType(const QQmlType &qmlType)
static QUrl inlineComponentUrl(const QUrl &baseUrl, const QString &name)
static void removeFromInlineComponents(InlineComponentContainer &container, const QQmlTypePrivate *reference)
static QQmlType inlineComponentTypeForUrl(const QUrl &baseUrl, const QString &name)
static void removeQQmlTypePrivate(QQmlTypeContainer &container, const QQmlTypePrivate *reference)
QUrl sourceUrl() const
Definition qqmltype.cpp:743
const QMetaObject * metaObject() const
Definition qqmltype.cpp:658
const QMetaObject * extensionMetaObject() const
Definition qqmltype.cpp:584
\inmodule QtCore
Definition qmutex.h:313
iterator begin()
Definition qset.h:136
iterator end()
Definition qset.h:140
iterator erase(const_iterator i)
Definition qset.h:145
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
\inmodule QtCore
Definition qurl.h:94
QString query(ComponentFormattingOptions=PrettyDecoded) const
Returns the query string of the URL if there's a query string, or an empty result if not.
Definition qurl.cpp:2606
void setFragment(const QString &fragment, ParsingMode mode=TolerantMode)
Sets the fragment of the URL to fragment.
Definition qurl.cpp:2645
QString userName(ComponentFormattingOptions options=FullyDecoded) const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
Definition qurl.cpp:2196
QString host(ComponentFormattingOptions=FullyDecoded) const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition qurl.cpp:2337
QString password(ComponentFormattingOptions=FullyDecoded) const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
Definition qurl.cpp:2259
QString scheme() const
Returns the scheme of the URL.
Definition qurl.cpp:1983
int port(int defaultPort=-1) const
Definition qurl.cpp:2380
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Definition qurl.cpp:2465
\inmodule QtCore
Definition qvariant.h:64
static constexpr ushort CurrentRevision
Definition qmetatype.h:254
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.
\qmltype Particle \inqmlmodule QtQuick.Particles
\macro QT_NAMESPACE
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:337
const QMetaObject * dynamicQmlListMarker(const QtPrivate::QMetaTypeInterface *)
const QMetaObject * dynamicQmlMetaObject(const QtPrivate::QMetaTypeInterface *iface)
QQmlPrivate::QQmlAttachedPropertiesFunc< QObject > QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:62
@ Success
Definition main.cpp:3197
@ NoError
Definition main.cpp:34
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
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)