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
qqmlvmemetaobject_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 BasysKom GmbH.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QQMLVMEMETAOBJECT_P_H
6#define QQMLVMEMETAOBJECT_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 <private/qbipointer_p.h>
20#include <private/qqmlguard_p.h>
21#include <private/qqmlguardedcontextdata_p.h>
22#include <private/qqmlpropertyvalueinterceptor_p.h>
23#include <private/qv4object_p.h>
24#include <private/qv4value_p.h>
25
26#include <QtCore/private/qobject_p.h>
27
28#if QT_CONFIG(regularexpression)
29#include <QtCore/qregularexpression.h>
30#endif
31
32#include <QtCore/qbitarray.h>
33#include <QtCore/qdatetime.h>
34#include <QtCore/qdebug.h>
35#include <QtCore/qlist.h>
36#include <QtCore/qmetaobject.h>
37#include <QtCore/qpair.h>
38
40
43{
44 Q_DISABLE_COPY_MOVE(QQmlVMEResolvedList)
45
46public:
47 QQmlVMEResolvedList(QQmlListProperty<QObject> *prop);
49
50 QQmlVMEMetaObject *metaObject() const { return m_metaObject; }
51 QV4::Heap::Object *list() const { return m_list; }
52 quintptr id() const { return m_id; }
53
54 void append(QObject *o) const;
55 void replace(qsizetype i, QObject *o) const;
56 QObject *at(qsizetype i) const;
57
58 qsizetype size() const { return m_list->arrayData->length(); }
59
60 void clear() const
61 {
62 QV4::Scope scope(m_list->internalClass->engine);
63 QV4::ScopedObject object(scope, m_list);
64 m_list->arrayData->vtable()->truncate(object, 0);
65 }
66
67 void removeLast() const
68 {
69 const uint length = m_list->arrayData->length();
70 if (length == 0)
71 return;
72
73 QV4::Scope scope(m_list->internalClass->engine);
74 QV4::ScopedObject object(scope, m_list);
75 m_list->arrayData->vtable()->truncate(object, length - 1);
76 }
77
78 void activateSignal() const;
79
80private:
81 QQmlVMEMetaObject *m_metaObject = nullptr;
82 QV4::Heap::Object *m_list = nullptr;
83 quintptr m_id = 0;
84};
85
86class QQmlVMEVariantQObjectPtr : public QQmlGuard<QObject>
87{
88public:
90
92
95
96private:
97 static void objectDestroyedImpl(QQmlGuardImpl *guard);
98};
99
100
102{
103public:
106
107 void registerInterceptor(QQmlPropertyIndex index, QQmlPropertyValueInterceptor *interceptor);
108
110
111 QMetaObject *toDynamicMetaObject(QObject *o) override;
112
113 // Used by auto-tests for inspection
115
116 bool intercepts(QQmlPropertyIndex propertyIndex) const
117 {
118 for (auto it = interceptors; it; it = it->m_next) {
119 if (it->m_propertyIndex == propertyIndex)
120 return true;
121 }
122 if (auto parentInterceptor = ((parent.isT1() && parent.flag()) ? static_cast<QQmlInterceptorMetaObject *>(parent.asT1()) : nullptr))
123 return parentInterceptor->intercepts(propertyIndex);
124 return false;
125 }
126
127 void invalidate() { metaObject.setTag(MetaObjectInvalid); }
128
129 QObject *object = nullptr;
131
132protected:
133 int metaCall(QObject *o, QMetaObject::Call c, int id, void **a) override;
134 bool intercept(QMetaObject::Call c, int id, void **a)
135 {
136 if (!interceptors)
137 return false;
138
139 switch (c) {
141 if (*reinterpret_cast<int*>(a[3]) & QQmlPropertyData::BypassInterceptor)
142 return false;
143 break;
145 break;
146 default:
147 return false;
148 }
149
150 return doIntercept(c, id, a);
151 }
152
153 QBiPointer<QDynamicMetaObjectData, const QMetaObject> parent;
154
155 enum MetaObjectValidity { MetaObjectValid, MetaObjectInvalid };
156 QTaggedPointer<const QMetaObject, MetaObjectValidity> metaObject;
157
158private:
159 bool doIntercept(QMetaObject::Call c, int id, void **a);
160 QQmlPropertyValueInterceptor *interceptors = nullptr;
161};
162
164{
165 if (obj) {
166 if (QQmlData *data = QQmlData::get(obj)) {
167 if (data->hasInterceptorMetaObject)
168 return static_cast<QQmlInterceptorMetaObject *>(QObjectPrivate::get(obj)->metaObject);
169 }
170 }
171
172 return nullptr;
173}
174
177{
178public:
181 const QQmlRefPointer<QV4::ExecutableCompilationUnit> &qmlCompilationUnit,
182 int qmlObjectId);
183 ~QQmlVMEMetaObject() override;
184
185 bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const;
186 QV4::ReturnedValue vmeMethod(int index) const;
187 void setVmeMethod(int index, const QV4::Value &function);
188 QV4::ReturnedValue vmeProperty(int index) const;
189 void setVMEProperty(int index, const QV4::Value &v);
190
191 void connectAliasSignal(int index, bool indexInSignalRange);
192
193 static inline QQmlVMEMetaObject *get(QObject *o);
194 static QQmlVMEMetaObject *getForProperty(QObject *o, int coreIndex);
195 static QQmlVMEMetaObject *getForMethod(QObject *o, int coreIndex);
196 static QQmlVMEMetaObject *getForSignal(QObject *o, int coreIndex);
197
198 static void list_append(QQmlListProperty<QObject> *prop, QObject *o);
199 static void list_clear(QQmlListProperty<QObject> *prop);
200 static void list_append_nosignal(QQmlListProperty<QObject> *prop, QObject *o);
201 static void list_clear_nosignal(QQmlListProperty<QObject> *prop);
202
203protected:
204 int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a) override;
205
206public:
209
210 inline int propOffset() const;
211 inline int methodOffset() const;
212 inline int signalOffset() const;
213 inline int signalCount() const;
214
216
218 QV4::MemberData *propertyAndMethodStorageAsMemberData() const;
219
220 int readPropertyAsInt(int id) const;
221 bool readPropertyAsBool(int id) const;
222 double readPropertyAsDouble(int id) const;
223 QString readPropertyAsString(int id) const;
224 QSizeF readPropertyAsSizeF(int id) const;
225 QPointF readPropertyAsPointF(int id) const;
226 QUrl readPropertyAsUrl(int id) const;
227 QDate readPropertyAsDate(int id) const;
228 QTime readPropertyAsTime(int id) const;
229 QDateTime readPropertyAsDateTime(int id) const;
230
231#if QT_CONFIG(regularexpression)
232 QRegularExpression readPropertyAsRegularExpression(int id) const;
233#endif
234
235 QRectF readPropertyAsRectF(int id) const;
236 QObject *readPropertyAsQObject(int id) const;
237 void initPropertyAsList(int id) const;
238
239 void writeProperty(int id, int v);
240 void writeProperty(int id, bool v);
241 void writeProperty(int id, double v);
242 void writeProperty(int id, const QString& v);
243
244 template<typename VariantCompatible>
245 void writeProperty(int id, const VariantCompatible &v)
246 {
247 QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
248 if (md) {
249 QV4::Scope scope(engine);
250 QV4::Scoped<QV4::MemberData>(scope, md)->set(
251 engine, id, engine->newVariantObject(
252 QMetaType::fromType<VariantCompatible>(), &v));
253 }
254 }
255
256 void writeProperty(int id, QObject *v);
257
258 void ensureQObjectWrapper();
259
260 void mark(QV4::MarkStack *markStack);
261
262 void connectAlias(int aliasId);
263
264 QV4::ReturnedValue method(int) const;
265
266 QV4::ReturnedValue readVarProperty(int) const;
267 void writeVarProperty(int, const QV4::Value &);
268 QVariant readPropertyAsVariant(int) const;
269 void writeProperty(int, const QVariant &);
270
271 inline QQmlVMEMetaObject *parentVMEMetaObject() const;
272
273 void activate(QObject *, int, void **);
274
275 QList<QQmlVMEVariantQObjectPtr *> varObjectGuards;
276
277 QQmlVMEVariantQObjectPtr *getQObjectGuardForProperty(int) const;
278
279
280 // keep a reference to the compilation unit in order to still
281 // do property access when the context has been invalidated.
282 QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit;
284};
285
287{
288 if (obj) {
289 if (QQmlData *data = QQmlData::get(obj)) {
290 if (data->hasVMEMetaObject)
291 return static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(obj)->metaObject);
292 }
293 }
294
295 return nullptr;
296}
297
299{
300 return cache->propertyOffset();
301}
302
304{
305 return cache->methodOffset();
306}
307
309{
310 return cache->signalOffset();
311}
312
314{
315 return cache->signalCount();
316}
317
319{
320 if (parent.isT1() && parent.flag())
321 return static_cast<QQmlVMEMetaObject *>(parent.asT1());
322
323 return nullptr;
324}
325
327
328#endif // QQMLVMEMETAOBJECT_P_H
T * asT1() const
bool flag() const
bool isT1() const
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore \reentrant
Definition qdatetime.h:29
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:217
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
QQmlPropertyCache::ConstPtr cache
QQmlPropertyCache::ConstPtr propertyCache() const
static QQmlInterceptorMetaObject * get(QObject *obj)
QBiPointer< QDynamicMetaObjectData, const QMetaObject > parent
bool intercepts(QQmlPropertyIndex propertyIndex) const
bool intercept(QMetaObject::Call c, int id, void **a)
QTaggedPointer< const QMetaObject, MetaObjectValidity > metaObject
The QQmlPropertyValueInterceptor class is inherited by property interceptors such as Behavior.
const QV4::CompiledData::Object * compiledObject
void writeProperty(int id, const VariantCompatible &v)
QV4::WeakValue propertyAndMethodStorage
static QQmlVMEMetaObject * get(QObject *o)
QQmlRefPointer< QV4::ExecutableCompilationUnit > compilationUnit
QV4::ExecutionEngine * engine
QQmlGuardedContextData ctxt
QList< QQmlVMEVariantQObjectPtr * > varObjectGuards
QQmlVMEMetaObject * parentVMEMetaObject() const
QQmlVMEMetaObjectEndpoint * aliasEndpoints
QQmlVMEMetaObject * metaObject() const
void replace(qsizetype i, QObject *o) const
qsizetype size() const
QV4::Heap::Object * list() const
void append(QObject *o) const
QQmlVMEResolvedList(QQmlListProperty< QObject > *prop)
QQmlVMEMetaObject * m_target
void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index)
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore \reentrant
\inmodule QtCore
Definition qsize.h:208
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore \reentrant
Definition qdatetime.h:215
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
QCache< int, Employee > cache
[0]
QSet< QString >::iterator it
Combined button and popup list for selecting options.
quint64 ReturnedValue
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 * method
static QDBusError::ErrorType get(const char *name)
static int writeProperty(QObject *obj, const QByteArray &property_name, QVariant value, int propFlags=QDBusConnection::ExportAllProperties)
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLenum GLuint GLenum GLsizei length
GLuint object
[3]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum target
GLhandleARB obj
[2]
const GLubyte * c
size_t quintptr
Definition qtypes.h:167
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
obj metaObject() -> className()
QAction * at
QJSEngine engine
[0]
\inmodule QtCore