1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL21$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
32 ****************************************************************************/
34 #ifndef QQMLVMEMETAOBJECT_P_H
35 #define QQMLVMEMETAOBJECT_P_H
41 // This file is not part of the Qt API. It exists purely as an
42 // implementation detail. This header file may change from version to
43 // version without notice, or even be removed.
50 #include <QtCore/QMetaObject>
51 #include <QtCore/QBitArray>
52 #include <QtCore/QPair>
53 #include <QtCore/QDate>
54 #include <QtCore/qlist.h>
55 #include <QtCore/qdebug.h>
57 #include <private/qobject_p.h>
59 #include "qqmlguard_p.h"
60 #include "qqmlcompiler_p.h"
61 #include "qqmlcontext_p.h"
63 #include <private/qv8engine_p.h>
64 #include <private/qflagpointer_p.h>
66 #include <private/qv4value_p.h>
70 #define QML_ALIAS_FLAG_PTR 0x00000001
72 struct QQmlVMEMetaData
74 short varPropertyCount;
79 short dummyForAlignment; // Add padding to ensure that the following
80 // AliasData/PropertyData/MethodData is int aligned.
89 bool isObjectAlias() const {
90 return propertyIdx == -1;
92 bool isPropertyAlias() const {
93 return !isObjectAlias() && valueTypeIndex() == -1;
95 bool isValueTypeAlias() const {
96 return !isObjectAlias() && valueTypeIndex() != -1;
98 int propertyIndex() const {
100 QQmlPropertyData::decodeValueTypePropertyIndex(propertyIdx, &index);
103 int valueTypeIndex() const {
104 return QQmlPropertyData::decodeValueTypePropertyIndex(propertyIdx);
106 int valueType() const {
107 return (valueTypeIndex() != -1) ? propType : 0;
111 struct PropertyData {
116 int runtimeFunctionIndex;
121 PropertyData *propertyData() const {
122 return (PropertyData *)(((char *)const_cast<QQmlVMEMetaData *>(this)) + sizeof(QQmlVMEMetaData));
125 AliasData *aliasData() const {
126 return (AliasData *)(propertyData() + propertyCount);
129 MethodData *methodData() const {
130 return (MethodData *)(aliasData() + aliasCount);
134 class QQmlVMEMetaObject;
135 class QQmlVMEVariantQObjectPtr : public QQmlGuard<QObject>
138 inline QQmlVMEVariantQObjectPtr(bool isVar);
139 inline ~QQmlVMEVariantQObjectPtr();
141 inline void objectDestroyed(QObject *);
142 inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index);
144 QQmlVMEMetaObject *m_target;
145 unsigned m_isVar : 1; // TODO: remove?
149 class QQmlVMEVariant;
151 class QQmlVMEMetaObjectEndpoint;
152 class Q_QML_PRIVATE_EXPORT QQmlVMEMetaObject : public QAbstractDynamicMetaObject
155 QQmlVMEMetaObject(QObject *obj, QQmlPropertyCache *cache, const QQmlVMEMetaData *data,
156 QV4::ExecutionContext *qmlBindingContext = 0, QQmlCompiledData *compiledData = 0);
157 ~QQmlVMEMetaObject();
159 bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const;
160 void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor);
161 QV4::ReturnedValue vmeMethod(int index);
162 quint16 vmeMethodLineNumber(int index);
163 void setVmeMethod(int index, const QV4::Value &function);
164 QV4::ReturnedValue vmeProperty(int index);
165 void setVMEProperty(int index, const QV4::Value &v);
167 void connectAliasSignal(int index, bool indexInSignalRange);
169 virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *o);
171 // Used by auto-tests for inspection
172 QQmlPropertyCache *propertyCache() const { return cache; }
174 static inline QQmlVMEMetaObject *get(QObject *o);
175 static QQmlVMEMetaObject *getForProperty(QObject *o, int coreIndex);
176 static QQmlVMEMetaObject *getForMethod(QObject *o, int coreIndex);
177 static QQmlVMEMetaObject *getForSignal(QObject *o, int coreIndex);
180 virtual int metaCall(QMetaObject::Call _c, int _id, void **_a);
183 friend class QQmlVMEMetaObjectEndpoint;
184 friend class QQmlVMEVariantQObjectPtr;
185 friend class QQmlPropertyCache;
188 QQmlGuardedContextData ctxt;
189 QQmlPropertyCache *cache;
191 const QQmlVMEMetaData *metaData;
192 inline int propOffset() const;
193 inline int methodOffset() const;
194 inline int signalOffset() const;
195 inline int signalCount() const;
197 bool hasAssignedMetaObjectData;
198 QQmlVMEMetaObjectEndpoint *aliasEndpoints;
200 QV4::WeakValue properties;
201 int firstVarPropertyIndex;
202 bool propertiesInitialized;
203 inline void allocateProperties();
204 inline bool ensurePropertiesAllocated();
206 int readPropertyAsInt(int id);
207 bool readPropertyAsBool(int id);
208 double readPropertyAsDouble(int id);
209 QString readPropertyAsString(int id);
210 QSizeF readPropertyAsSizeF(int id);
211 QPointF readPropertyAsPointF(int id);
212 QUrl readPropertyAsUrl(int id);
213 QDate readPropertyAsDate(int id);
214 QDateTime readPropertyAsDateTime(int id);
215 QRectF readPropertyAsRectF(int id);
216 QObject* readPropertyAsQObject(int id);
218 void writeProperty(int id, int v);
219 void writeProperty(int id, bool v);
220 void writeProperty(int id, double v);
221 void writeProperty(int id, const QString& v);
222 void writeProperty(int id, const QPointF& v);
223 void writeProperty(int id, const QSizeF& v);
224 void writeProperty(int id, const QUrl& v);
225 void writeProperty(int id, const QDate& v);
226 void writeProperty(int id, const QDateTime& v);
227 void writeProperty(int id, const QRectF& v);
228 void writeProperty(int id, QObject *v);
230 void ensureQObjectWrapper();
232 void mark(QV4::ExecutionEngine *e);
234 void connectAlias(int aliasId);
235 QBitArray aConnected;
237 QQmlPropertyValueInterceptor *interceptors;
239 QV4::PersistentValue *v8methods;
240 QV4::ReturnedValue method(int);
242 QV4::ReturnedValue readVarProperty(int);
243 void writeVarProperty(int, const QV4::Value &);
244 QVariant readPropertyAsVariant(int);
245 void writeProperty(int, const QVariant &);
247 QBiPointer<QDynamicMetaObjectData, const QMetaObject> parent;
249 inline QQmlVMEMetaObject *parentVMEMetaObject() const;
251 void listChanged(int);
252 class List : public QList<QObject*>
255 List(int lpi, QQmlVMEMetaObject *mo) : notifyIndex(lpi), mo(mo) {}
257 QQmlVMEMetaObject *mo;
259 QList<List> listProperties;
261 static void list_append(QQmlListProperty<QObject> *, QObject *);
262 static int list_count(QQmlListProperty<QObject> *);
263 static QObject *list_at(QQmlListProperty<QObject> *, int);
264 static void list_clear(QQmlListProperty<QObject> *);
266 void activate(QObject *, int, void **);
268 QList<QQmlVMEVariantQObjectPtr *> varObjectGuards;
270 QQmlVMEVariantQObjectPtr *getQObjectGuardForProperty(int) const;
272 friend class QV8GCCallback;
275 QQmlVMEMetaObject *QQmlVMEMetaObject::get(QObject *obj)
278 if (QQmlData *data = QQmlData::get(obj)) {
279 if (data->hasVMEMetaObject)
280 return static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(obj)->metaObject);
287 int QQmlVMEMetaObject::propOffset() const
289 return cache->propertyOffset();
292 int QQmlVMEMetaObject::methodOffset() const
294 return cache->methodOffset();
297 int QQmlVMEMetaObject::signalOffset() const
299 return cache->signalOffset();
302 int QQmlVMEMetaObject::signalCount() const
304 return cache->signalCount();
307 QQmlVMEMetaObject *QQmlVMEMetaObject::parentVMEMetaObject() const
309 if (parent.isT1() && parent.flag())
310 return static_cast<QQmlVMEMetaObject *>(parent.asT1());
317 #endif // QQMLVMEMETAOBJECT_P_H