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
4#ifndef QQMLTYPE_P_H
5#define QQMLTYPE_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 <functional>
19
20#include <private/qtqmlglobal_p.h>
21#include <private/qqmlrefcount_p.h>
22
23#include <QtQml/qqmlprivate.h>
24#include <QtQml/qjsvalue.h>
25
26#include <QtCore/qobject.h>
27#include <QtCore/qversionnumber.h>
28
29QT_BEGIN_NAMESPACE
30
31class QHashedCStringRef;
32class QHashedString;
33class QHashedStringRef;
34class QQmlCustomParser;
36class QQmlPropertyCache;
37class QQmlTypeLoader;
38class QQmlTypePrivate;
39
40namespace QV4 {
41struct String;
42}
43
44class Q_QML_EXPORT QQmlType
45{
46public:
47 QQmlType();
48 QQmlType(const QQmlType &other);
49 QQmlType(QQmlType &&other);
50 QQmlType &operator =(const QQmlType &other);
51 QQmlType &operator =(QQmlType &&other);
52 explicit QQmlType(const QQmlTypePrivate *priv);
53 ~QQmlType();
54
55 bool isValid() const { return !d.isNull(); }
56
57 QByteArray typeName() const;
58 QString qmlTypeName() const;
59 QString elementName() const;
60
61 QHashedString module() const;
62 QTypeRevision version() const;
63
64 bool availableInVersion(QTypeRevision version) const;
65 bool availableInVersion(const QHashedStringRef &module, QTypeRevision version) const;
66
67 typedef QVariant (*CreateValueTypeFunc)(const QJSValue &);
68 CreateValueTypeFunc createValueTypeFunction() const;
69
70 bool canConstructValueType() const;
71 bool canPopulateValueType() const;
72
73 QObject *create() const;
74 QObject *create(void **, size_t) const;
75 QObject *createWithQQmlData() const;
76
77 typedef void (*CreateFunc)(void *, void *);
78 CreateFunc createFunction() const;
79
80 QQmlCustomParser *customParser() const;
81
82 bool isCreatable() const;
83 typedef QObject *(*ExtensionFunc)(QObject *);
84 ExtensionFunc extensionFunction() const;
85 const QMetaObject *extensionMetaObject() const;
86 bool isExtendedType() const;
87 QString noCreationReason() const;
88
89 bool isSingleton() const;
90 bool isInterface() const;
91 bool isComposite() const;
92 bool isCompositeSingleton() const;
93 bool isQObjectSingleton() const;
94 bool isQJSValueSingleton() const;
95 bool isSequentialContainer() const;
96 bool isValueType() const;
97
98 QMetaType typeId() const;
99 QMetaType qListTypeId() const;
100 QMetaSequence listMetaSequence() const;
101
102 const QMetaObject *metaObject() const;
103
104 // Precondition: The type is actually a value type!
105 const QMetaObject *metaObjectForValueType() const;
106
107 const QMetaObject *baseMetaObject() const;
108 QTypeRevision metaObjectRevision() const;
109 bool containsRevisionedAttributes() const;
110
111 QQmlAttachedPropertiesFunc attachedPropertiesFunction(QQmlTypeLoader *typeLoader) const;
112 const QMetaObject *attachedPropertiesType(QQmlTypeLoader *typeLoader) const;
113
114 int parserStatusCast() const;
115 const char *interfaceIId() const;
116 int propertyValueSourceCast() const;
117 int propertyValueInterceptorCast() const;
118 int finalizerCast() const;
119
120 int index() const;
121
122 bool isInlineComponentType() 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:23
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:191