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/qtyperevision.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 isInlineComponent() const;
95 bool isQObjectSingleton() const;
96 bool isQJSValueSingleton() const;
97 bool isSequentialContainer() const;
98 bool isValueType() const;
99
100 QMetaType typeId() const;
101 QMetaType qListTypeId() const;
102 QMetaSequence listMetaSequence() const;
103
104 const QMetaObject *metaObject() const;
105
106 // Precondition: The type is actually a value type!
107 const QMetaObject *metaObjectForValueType() const;
108
109 const QMetaObject *baseMetaObject() const;
110 QTypeRevision metaObjectRevision() const;
111 bool containsRevisionedAttributes() const;
112
113 QQmlAttachedPropertiesFunc attachedPropertiesFunction(QQmlTypeLoader *typeLoader) const;
114 const QMetaObject *attachedPropertiesType(QQmlTypeLoader *typeLoader) const;
115
116 int parserStatusCast() const;
117 const char *interfaceIId() const;
118 int propertyValueSourceCast() const;
119 int propertyValueInterceptorCast() const;
120 int finalizerCast() const;
121
122 int index() const;
123
124 struct Q_QML_EXPORT SingletonInstanceInfo final
125 : public QQmlRefCounted<SingletonInstanceInfo>
126 {
127 using Ptr = QQmlRefPointer<SingletonInstanceInfo>;
128 using ConstPtr = QQmlRefPointer<const SingletonInstanceInfo>;
129
130 static Ptr create() { return Ptr(new SingletonInstanceInfo, Ptr::Adopt); }
131
132 std::function<QJSValue(QQmlEngine *, QJSEngine *)> scriptCallback = {};
133 std::function<QObject *(QQmlEngine *, QJSEngine *)> qobjectCallback = {};
134 QByteArray typeName;
135 QUrl url; // used by composite singletons
136
137 private:
138 Q_DISABLE_COPY_MOVE(SingletonInstanceInfo)
139 SingletonInstanceInfo() = default;
140 };
141 SingletonInstanceInfo::ConstPtr singletonInstanceInfo() const;
142
143 QUrl sourceUrl() const;
144
145 int enumValue(QQmlTypeLoader *typeLoader, const QHashedStringRef &, bool *ok) const;
146 int enumValue(QQmlTypeLoader *typeLoader, const QHashedCStringRef &, bool *ok) const;
147 int enumValue(QQmlTypeLoader *typeLoader, const QV4::String *, bool *ok) const;
148
149 int scopedEnumIndex(QQmlTypeLoader *typeLoader, const QV4::String *, bool *ok) const;
150 int scopedEnumIndex(QQmlTypeLoader *typeLoader, const QString &, bool *ok) const;
151 int unscopedEnumIndex(QQmlTypeLoader *typeLoader, const QV4::String *, bool *ok) const;
152 int unscopedEnumIndex(QQmlTypeLoader *typeLoader, const QString &, bool *ok) const;
153
154 int scopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QV4::String *, bool *ok) const;
155 int scopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QString &, bool *ok) const;
156 int scopedEnumValue(QQmlTypeLoader *typeLoader, const QHashedStringRef &, const QHashedStringRef &, bool *ok) const;
157
158 int unscopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QV4::String *, bool *ok) const;
159 int unscopedEnumValue(QQmlTypeLoader *typeLoader, int index, const QString &, bool *ok) const;
160 int unscopedEnumValue(QQmlTypeLoader *typeLoader, const QHashedStringRef &, const QHashedStringRef &, bool *ok) const;
161
162 QString scopedEnumKey(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
163 QStringList scopedEnumKeys(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
164
165 QString unscopedEnumKey(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
166 QStringList unscopedEnumKeys(QQmlTypeLoader *typeLoader, int index, int value, bool *ok) const;
167
168 const QQmlTypePrivate *priv() const { return d.data(); }
169 static void refHandle(const QQmlTypePrivate *priv);
170 static void derefHandle(const QQmlTypePrivate *priv);
171 static int refCount(const QQmlTypePrivate *priv);
172
173 enum RegistrationType {
174 CppType = 0,
175 SingletonType = 1,
176 InterfaceType = 2,
177 CompositeType = 3,
178 CompositeSingletonType = 4,
179 InlineComponentType = 5,
180 SequentialContainerType = 6,
181 JavaScriptType = 7,
182 AnyRegistrationType = 255
183 };
184
185 void createProxy(QObject *instance) const;
186
187private:
188 friend class QQmlTypePrivate;
189 friend size_t qHash(const QQmlType &t, size_t seed);
190 friend bool operator==(const QQmlType &a, const QQmlType &b) noexcept
191 {
192 return a.d.data() == b.d.data();
193 }
194 friend bool operator!=(const QQmlType &a, const QQmlType &b) noexcept
195 {
196 return !(a == b);
197 }
198
199 QQmlRefPointer<const QQmlTypePrivate> d;
200};
201
202inline size_t qHash(const QQmlType &t, size_t seed = 0)
203{
204 return qHash(reinterpret_cast<quintptr>(t.d.data()), seed);
205}
206
207QT_END_NAMESPACE
208
209#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