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
qqmltype_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// Qt-Security score:significant
4
5#ifndef QQMLTYPE_P_H
6#define QQMLTYPE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <functional>
20
21#include <private/qtqmlglobal_p.h>
22#include <private/qqmlrefcount_p.h>
23
24#include <QtQml/qqmlprivate.h>
25#include <QtQml/qjsvalue.h>
26
27#include <QtCore/qobject.h>
28#include <QtCore/qversionnumber.h>
29
30QT_BEGIN_NAMESPACE
31
32class QHashedCStringRef;
33class QHashedString;
34class QHashedStringRef;
35class QQmlCustomParser;
37class QQmlPropertyCache;
38class QQmlTypeLoader;
39class QQmlTypePrivate;
40
41namespace QV4 {
42struct String;
43}
44
45class Q_QML_EXPORT QQmlType
46{
47public:
48 QQmlType();
49 QQmlType(const QQmlType &other);
50 QQmlType(QQmlType &&other);
51 QQmlType &operator =(const QQmlType &other);
52 QQmlType &operator =(QQmlType &&other);
53 explicit QQmlType(const QQmlTypePrivate *priv);
54 ~QQmlType();
55
56 bool isValid() const { return !d.isNull(); }
57
58 QByteArray typeName() const;
59 QString qmlTypeName() const;
60 QString elementName() const;
61
62 QHashedString module() const;
63 QTypeRevision version() const;
64
65 bool availableInVersion(QTypeRevision version) const;
66 bool availableInVersion(const QHashedStringRef &module, QTypeRevision version) const;
67
68 typedef QVariant (*CreateValueTypeFunc)(const QJSValue &);
69 CreateValueTypeFunc createValueTypeFunction() const;
70
71 bool canConstructValueType() const;
72 bool canPopulateValueType() const;
73
74 QObject *create() const;
75 QObject *create(void **, size_t) const;
76 QObject *createWithQQmlData() const;
77
78 typedef void (*CreateFunc)(void *, void *);
79 CreateFunc createFunction() const;
80
81 QQmlCustomParser *customParser() const;
82
83 bool isCreatable() const;
84 typedef QObject *(*ExtensionFunc)(QObject *);
85 ExtensionFunc extensionFunction() const;
86 const QMetaObject *extensionMetaObject() const;
87 bool isExtendedType() const;
88 QString noCreationReason() const;
89
90 bool isSingleton() const;
91 bool isInterface() const;
92 bool isComposite() const;
93 bool isCompositeSingleton() const;
94 bool isQObjectSingleton() const;
95 bool isQJSValueSingleton() const;
96 bool isSequentialContainer() const;
97 bool isValueType() const;
98
99 QMetaType typeId() const;
100 QMetaType qListTypeId() const;
101 QMetaSequence listMetaSequence() const;
102
103 const QMetaObject *metaObject() const;
104
105 // Precondition: The type is actually a value type!
106 const QMetaObject *metaObjectForValueType() const;
107
108 const QMetaObject *baseMetaObject() const;
109 QTypeRevision metaObjectRevision() const;
110 bool containsRevisionedAttributes() const;
111
112 QQmlAttachedPropertiesFunc attachedPropertiesFunction(QQmlTypeLoader *typeLoader) const;
113 const QMetaObject *attachedPropertiesType(QQmlTypeLoader *typeLoader) const;
114
115 int parserStatusCast() const;
116 const char *interfaceIId() const;
117 int propertyValueSourceCast() const;
118 int propertyValueInterceptorCast() const;
119 int finalizerCast() const;
120
121 int index() const;
122
123 bool isInlineComponentType() const;
124
125 struct Q_QML_EXPORT SingletonInstanceInfo final
126 : public QQmlRefCounted<SingletonInstanceInfo>
127 {
128 using Ptr = QQmlRefPointer<SingletonInstanceInfo>;
129 using ConstPtr = QQmlRefPointer<const SingletonInstanceInfo>;
130
131 static Ptr create() { return Ptr(new SingletonInstanceInfo, Ptr::Adopt); }
132
133 std::function<QJSValue(QQmlEngine *, QJSEngine *)> scriptCallback = {};
134 std::function<QObject *(QQmlEngine *, QJSEngine *)> qobjectCallback = {};
135 QByteArray typeName;
136 QUrl url; // used by composite singletons
137
138 private:
139 Q_DISABLE_COPY_MOVE(SingletonInstanceInfo)
140 SingletonInstanceInfo() = default;
141 };
142 SingletonInstanceInfo::ConstPtr singletonInstanceInfo() const;
143
144 QUrl sourceUrl() const;
145
146 int enumValue(QQmlTypeLoader *typeLoader, const QHashedStringRef &, bool *ok) const;
147 int enumValue(QQmlTypeLoader *typeLoader, const QHashedCStringRef &, bool *ok) const;
148 int enumValue(QQmlTypeLoader *typeLoader, const QV4::String *, bool *ok) const;
149
150 int scopedEnumIndex(QQmlTypeLoader *typeLoader, const QV4::String *, bool *ok) const;
151 int scopedEnumIndex(QQmlTypeLoader *typeLoader, const QString &, bool *ok) const;
152 int unscopedEnumIndex(QQmlTypeLoader *typeLoader, const QV4::String *, bool *ok) const;
153 int unscopedEnumIndex(QQmlTypeLoader *typeLoader, const QString &, bool *ok) const;
154
155 int scopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QV4::String *, bool *ok) const;
156 int scopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QString &, bool *ok) const;
157 int scopedEnumValue(QQmlTypeLoader *typeLoader, const QHashedStringRef &, const QHashedStringRef &, bool *ok) const;
158
159 int unscopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QV4::String *, bool *ok) const;
160 int unscopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QString &, bool *ok) const;
161 int unscopedEnumValue(QQmlTypeLoader *typeLoader, const QHashedStringRef &, const QHashedStringRef &, bool *ok) const;
162
163 QString scopedEnumKey(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
164 QStringList scopedEnumKeys(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
165
166 QString unscopedEnumKey(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
167 QStringList unscopedEnumKeys(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
168
169 const QQmlTypePrivate *priv() const { return d.data(); }
170 static void refHandle(const QQmlTypePrivate *priv);
171 static void derefHandle(const QQmlTypePrivate *priv);
172 static int refCount(const QQmlTypePrivate *priv);
173
174 enum RegistrationType {
175 CppType = 0,
176 SingletonType = 1,
177 InterfaceType = 2,
178 CompositeType = 3,
179 CompositeSingletonType = 4,
180 InlineComponentType = 5,
181 SequentialContainerType = 6,
182 JavaScriptType = 7,
183 AnyRegistrationType = 255
184 };
185
186 void createProxy(QObject *instance) const;
187
188private:
189 friend class QQmlTypePrivate;
190 friend size_t qHash(const QQmlType &t, size_t seed);
191 friend bool operator==(const QQmlType &a, const QQmlType &b) noexcept
192 {
193 return a.d.data() == b.d.data();
194 }
195 friend bool operator!=(const QQmlType &a, const QQmlType &b) noexcept
196 {
197 return !(a == b);
198 }
199
200 QQmlRefPointer<const QQmlTypePrivate> d;
201};
202
203inline size_t qHash(const QQmlType &t, size_t seed = 0)
204{
205 return qHash(reinterpret_cast<quintptr>(t.d.data()), seed);
206}
207
208QT_END_NAMESPACE
209
210#endif // QQMLTYPE_P_H
friend class QQmlEnginePrivate
Definition qjsvalue.h:24
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192