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
qqmltype_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 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 QQMLTYPE_P_P_H
5#define QQMLTYPE_P_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/qqmltype_p.h>
19#include <private/qstringhash_p.h>
20#include <private/qqmlproxymetaobject_p.h>
21#include <private/qqmlrefcount_p.h>
22#include <private/qqmlpropertycache_p.h>
23#include <private/qqmlmetatype_p.h>
24#include <private/qqmltypeloader_p.h>
25#include <private/qv4executablecompilationunit_p.h>
26#include <private/qv4engine_p.h>
27
28#include <QAtomicInteger>
29
31
32class QQmlTypePrivate final : public QQmlRefCounted<QQmlTypePrivate>
33{
34 Q_DISABLE_COPY_MOVE(QQmlTypePrivate)
35public:
37 {
39 {
41 free(metaObject.metaObject);
42 }
43
44 QList<QQmlProxyMetaObject::ProxyData> data;
46 };
47
48 struct Enums
49 {
51
52 QStringHash<int> enums;
53 QStringHash<int> scopedEnumIndex; // maps from enum name to index in scopedEnums
54 QList<QStringHash<int> *> scopedEnums;
55 };
56
58
59 const ProxyMetaObjects *init() const;
60
74
76 {
77 for (const QQmlTypePrivate *d = this; d; d = d->resolveCompositeBaseType(engine).d.data()) {
78 if (d->regType == QQmlType::CppType)
79 return d->extraData.cppTypeData->attachedPropertiesType ? d : nullptr;
80
81 if (d->regType != QQmlType::CompositeType)
82 return nullptr;
83 }
84 return nullptr;
85 }
86
91
92 bool isValueType() const
93 {
95 }
96
99
121
128
129 int index = -1;
130
142 static_assert(sizeof(extraData) == sizeof(void *));
143
144 QHashedString module;
152 const QMetaObject *baseMetaObject = nullptr;
153
154 void setName(const QString &uri, const QString &element);
155
156 template<typename String>
157 static int enumValue(
158 const QQmlRefPointer<const QQmlTypePrivate> &d, QQmlEnginePrivate *engine,
159 const String &name, bool *ok)
160 {
161 return doGetEnumValue(d, engine, [&](const QQmlTypePrivate::Enums *enums) {
162 return enums->enums.value(name);
163 }, ok);
164 }
165
166 template<typename String>
167 static int scopedEnumIndex(
168 const QQmlRefPointer<const QQmlTypePrivate> &d, QQmlEnginePrivate *engine,
169 const String &name, bool *ok)
170 {
171 return doGetEnumValue(d, engine, [&](const QQmlTypePrivate::Enums *enums) {
172 return enums->scopedEnumIndex.value(name);
173 }, ok);
174 }
175
176 template<typename String>
177 static int scopedEnumValue(
178 const QQmlRefPointer<const QQmlTypePrivate> &d, QQmlEnginePrivate *engine, int index,
179 const String &name, bool *ok)
180 {
181 return doGetEnumValue(d, engine, [&](const QQmlTypePrivate::Enums *enums) {
182 Q_ASSERT(index > -1 && index < enums->scopedEnums.size());
183 return enums->scopedEnums.at(index)->value(name);
184 }, ok);
185 }
186
187 template<typename String1, typename String2>
188 static int scopedEnumValue(
189 const QQmlRefPointer<const QQmlTypePrivate> &d, QQmlEnginePrivate *engine,
190 const String1 &scopedEnumName, const String2 &name, bool *ok)
191 {
192 return doGetEnumValue(d, engine, [&](const QQmlTypePrivate::Enums *enums) -> const int * {
193 const int *rv = enums->scopedEnumIndex.value(scopedEnumName);
194 if (!rv)
195 return nullptr;
196
197 const int index = *rv;
198 Q_ASSERT(index > -1 && index < enums->scopedEnums.size());
199 return enums->scopedEnums.at(index)->value(name);
200 }, ok);
201 }
202
203 const QMetaObject *metaObject() const
204 {
205 if (isValueType())
206 return metaObjectForValueType();
207
208 const QQmlTypePrivate::ProxyMetaObjects *proxies = init();
209 return proxies->data.isEmpty()
211 : proxies->data.constFirst().metaObject;
212 }
213
215 {
217
218 // Prefer the extension meta object, if any.
219 // Extensions allow registration of non-gadget value types.
220 if (const QMetaObject *extensionMetaObject = extraData.cppTypeData->extMetaObject) {
221 // This may be a namespace even if the original metaType isn't.
222 // You can do such things with QML_FOREIGN declarations.
223 if (extensionMetaObject->metaType().flags() & QMetaType::IsGadget)
224 return extensionMetaObject;
225 }
226
227 if (baseMetaObject) {
228 // This may be a namespace even if the original metaType isn't.
229 // You can do such things with QML_FOREIGN declarations.
231 return baseMetaObject;
232 }
233
234 return nullptr;
235 }
236
238 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit,
239 QQmlTypeLoader *typeLoader, const QString &type)
240 {
241 Q_ASSERT(typeLoader);
242
243 const QQmlType qmltype
244 = unit->typeNameCache->query<QQmlImport::AllowRecursion>(type, typeLoader).type;
245 if (!qmltype.isValid())
246 return qmltype;
247
248 if (qmltype.isInlineComponentType()
249 && !QQmlMetaType::obtainCompilationUnit(qmltype.typeId())) {
250 // If it seems to be an IC type, make sure there is an actual
251 // compilation unit for it. We create inline component types speculatively.
252 return QQmlType();
253 }
254
255 return qmltype;
256 }
257
258private:
259 mutable QAtomicPointer<const ProxyMetaObjects> proxyMetaObjects;
260 mutable QAtomicPointer<const Enums> enums;
261
263 friend class QQmlRefCounted<QQmlTypePrivate>;
264
265 struct EnumInfo {
267 QString metaObjectName;
268 QString enumName;
269 QString enumKey;
270 QString metaEnumScope;
271 bool scoped;
272 };
273
274 template<typename Op>
275 static int doGetEnumValue(
276 const QQmlRefPointer<const QQmlTypePrivate> &d, QQmlEnginePrivate *engine,
277 Op &&op, bool *ok)
278 {
279 Q_ASSERT(ok);
280 if (d) {
281 if (const QQmlTypePrivate::Enums *enums = d->initEnums(engine)) {
282 if (const int *rv = op(enums)) {
283 *ok = true;
284 return *rv;
285 }
286 }
287 }
288
289 *ok = false;
290 return -1;
291 }
292
293 const Enums *initEnums(QQmlEnginePrivate *engine) const;
294 void insertEnums(Enums *enums, const QMetaObject *metaObject) const;
295 void insertEnumsFromPropertyCache(Enums *enums, const QQmlPropertyCache::ConstPtr &cache) const;
296
297 void createListOfPossibleConflictingItems(const QMetaObject *metaObject, QList<EnumInfo> &enumInfoList, QStringList path) const;
298 void createEnumConflictReport(const QMetaObject *metaObject, const QString &conflictingKey) const;
299};
300
302
303#endif // QQMLTYPE_P_P_H
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
bool isEmpty() const noexcept
Definition qlist.h:401
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
const T & constFirst() const noexcept
Definition qlist.h:647
\inmodule QtCore
\inmodule QtCore
Definition qmetatype.h:341
constexpr TypeFlags flags() const
Definition qmetatype.h:2658
@ PointerToQObject
Definition qmetatype.h:406
\inmodule QtCore
Definition qobject.h:103
The QQmlCustomParser class allows you to add new arbitrary types to QML.
static QQmlRefPointer< QV4::CompiledData::CompilationUnit > obtainCompilationUnit(QMetaType type)
The QQmlTypeLoader class abstracts loading files and their dependencies over the network.
void setName(const QString &uri, const QString &element)
Definition qqmltype.cpp:444
static int scopedEnumIndex(const QQmlRefPointer< const QQmlTypePrivate > &d, QQmlEnginePrivate *engine, const String &name, bool *ok)
const ProxyMetaObjects * init() const
Definition qqmltype.cpp:173
QTypeRevision revision
QQmlPropertyCache::ConstPtr compositePropertyCache(QQmlEnginePrivate *engine) const
Definition qqmltype.cpp:154
static int enumValue(const QQmlRefPointer< const QQmlTypePrivate > &d, QQmlEnginePrivate *engine, const String &name, bool *ok)
union QQmlTypePrivate::extraData extraData
static int scopedEnumValue(const QQmlRefPointer< const QQmlTypePrivate > &d, QQmlEnginePrivate *engine, int index, const String &name, bool *ok)
const QQmlTypePrivate * attachedPropertiesBase(QQmlEnginePrivate *engine) const
static int scopedEnumValue(const QQmlRefPointer< const QQmlTypePrivate > &d, QQmlEnginePrivate *engine, const String1 &scopedEnumName, const String2 &name, bool *ok)
static QQmlType compositeQmlType(const QQmlRefPointer< QV4::CompiledData::CompilationUnit > &unit, QQmlTypeLoader *typeLoader, const QString &type)
QHashedString QString name
bool isComposite() const
const QMetaObject * metaObject() const
QTypeRevision version
QUrl sourceUrl() const
QQmlTypePrivate(QQmlType::RegistrationType type)
Definition qqmltype.cpp:19
QQmlType::RegistrationType regType
bool isValueType() const
const QMetaObject * baseMetaObject
QQmlType resolveCompositeBaseType(QQmlEnginePrivate *engine) const
Definition qqmltype.cpp:141
const QMetaObject * metaObjectForValueType() const
@ InlineComponentType
Definition qqmltype_p.h:165
@ CompositeType
Definition qqmltype_p.h:163
@ CompositeSingletonType
Definition qqmltype_p.h:164
T * value(const K &) const
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
static constexpr QTypeRevision zero()
Produces a QTypeRevision with major and minor version {0}.
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
qDeleteAll(list.begin(), list.end())
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
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
GLuint index
[2]
GLenum type
GLuint name
GLsizei const GLchar *const * path
QQmlPrivate::QQmlAttachedPropertiesFunc< QObject > QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:63
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QJSEngine engine
[0]
\inmodule QtCore
QMetaType metaType() const
QStringHash< int > enums
QList< QStringHash< int > * > scopedEnums
QStringHash< int > scopedEnumIndex
QList< QQmlProxyMetaObject::ProxyData > data
const QMetaObject * attachedPropertiesType
QQmlAttachedPropertiesFunc attachedPropertiesFunc
const QMetaObject * extMetaObject
void(* newFunc)(void *, void *)
QVariant(* createValueTypeFunc)(const QJSValue &)
QQmlType::SingletonInstanceInfo::ConstPtr singletonInstanceInfo
QQmlSingletonTypeData * singletonTypeData
QMetaSequence sequentialContainerTypeData
QQmlCppTypeData * cppTypeData