1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #ifndef QQMLVMEMETAOBJECT_P_H
43 #define QQMLVMEMETAOBJECT_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
58 #include <QtCore/QMetaObject>
59 #include <QtCore/QBitArray>
60 #include <QtCore/QPair>
61 #include <QtCore/QDate>
62 #include <QtCore/qlist.h>
63 #include <QtCore/qdebug.h>
65 #include <private/qobject_p.h>
67 #include "qqmlguard_p.h"
68 #include "qqmlcompiler_p.h"
69 #include "qqmlcontext_p.h"
71 #include <private/qv8engine_p.h>
72 #include <private/qflagpointer_p.h>
74 #include <private/qv8_p.h>
78 #define QML_ALIAS_FLAG_PTR 0x00000001
80 struct QQmlVMEMetaData
82 short varPropertyCount;
87 short dummyForAlignment; // Add padding to ensure that the following
88 // AliasData/PropertyData/MethodData is int aligned.
97 bool isObjectAlias() const {
98 return propertyIdx == -1;
100 bool isPropertyAlias() const {
101 return !isObjectAlias() && !(propertyIdx & 0xFFFF0000);
103 bool isValueTypeAlias() const {
104 return !isObjectAlias() && (propertyIdx & 0xFFFF0000);
106 int propertyIndex() const {
107 return propertyIdx & 0x0000FFFF;
109 int valueTypeIndex() const {
110 return (propertyIdx & 0xFFFF0000) >> 16;
112 int valueType() const {
113 return (propertyIdx & 0xFFFF0000) ? propType : 0;
117 struct PropertyData {
128 PropertyData *propertyData() const {
129 return (PropertyData *)(((const char *)this) + sizeof(QQmlVMEMetaData));
132 AliasData *aliasData() const {
133 return (AliasData *)(propertyData() + propertyCount);
136 MethodData *methodData() const {
137 return (MethodData *)(aliasData() + aliasCount);
141 class QQmlVMEMetaObject;
142 class QQmlVMEVariantQObjectPtr : public QQmlGuard<QObject>
145 inline QQmlVMEVariantQObjectPtr(bool isVar);
146 inline ~QQmlVMEVariantQObjectPtr();
148 inline void objectDestroyed(QObject *);
149 inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index);
151 QQmlVMEMetaObject *m_target;
152 unsigned m_isVar : 1;
156 class QV8QObjectWrapper;
157 class QQmlVMEVariant;
159 class QQmlVMEMetaObjectEndpoint;
160 class Q_QML_PRIVATE_EXPORT QQmlVMEMetaObject : public QAbstractDynamicMetaObject,
161 public QV8GCCallback::Node
164 QQmlVMEMetaObject(QObject *obj, QQmlPropertyCache *cache, const QQmlVMEMetaData *data);
165 ~QQmlVMEMetaObject();
167 bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const;
168 void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor);
169 v8::Handle<v8::Function> vmeMethod(int index);
170 quint16 vmeMethodLineNumber(int index);
171 void setVmeMethod(int index, v8::Persistent<v8::Function>);
172 v8::Handle<v8::Value> vmeProperty(int index);
173 void setVMEProperty(int index, v8::Handle<v8::Value> v);
175 void connectAliasSignal(int index, bool indexInSignalRange);
177 virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *o);
179 static inline QQmlVMEMetaObject *get(QObject *o);
180 static QQmlVMEMetaObject *getForProperty(QObject *o, int coreIndex);
181 static QQmlVMEMetaObject *getForMethod(QObject *o, int coreIndex);
182 static QQmlVMEMetaObject *getForSignal(QObject *o, int coreIndex);
185 virtual int metaCall(QMetaObject::Call _c, int _id, void **_a);
188 friend class QQmlVMEMetaObjectEndpoint;
189 friend class QQmlVMEVariantQObjectPtr;
190 friend class QQmlPropertyCache;
193 QQmlGuardedContextData ctxt;
194 QQmlPropertyCache *cache;
196 const QQmlVMEMetaData *metaData;
197 inline int propOffset() const;
198 inline int methodOffset() const;
199 inline int signalOffset() const;
200 inline int signalCount() const;
202 bool hasAssignedMetaObjectData;
203 QQmlVMEVariant *data;
204 QQmlVMEMetaObjectEndpoint *aliasEndpoints;
206 v8::Persistent<v8::Array> varProperties;
207 int firstVarPropertyIndex;
208 bool varPropertiesInitialized;
209 static void VarPropertiesWeakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter);
210 static void GcPrologueCallback(QV8GCCallback::Node *node);
211 inline void allocateVarPropertiesArray();
212 inline bool ensureVarPropertiesAllocated();
214 void connectAlias(int aliasId);
215 QBitArray aConnected;
217 QQmlPropertyValueInterceptor *interceptors;
219 v8::Persistent<v8::Function> *v8methods;
220 v8::Handle<v8::Function> method(int);
222 v8::Handle<v8::Value> readVarProperty(int);
223 void writeVarProperty(int, v8::Handle<v8::Value>);
224 QVariant readPropertyAsVariant(int);
225 void writeProperty(int, const QVariant &);
227 QBiPointer<QDynamicMetaObjectData, const QMetaObject> parent;
229 inline QQmlVMEMetaObject *parentVMEMetaObject() const;
231 void listChanged(int);
232 class List : public QList<QObject*>
235 List(int lpi, QQmlVMEMetaObject *mo) : notifyIndex(lpi), mo(mo) {}
237 QQmlVMEMetaObject *mo;
239 QList<List> listProperties;
241 static void list_append(QQmlListProperty<QObject> *, QObject *);
242 static int list_count(QQmlListProperty<QObject> *);
243 static QObject *list_at(QQmlListProperty<QObject> *, int);
244 static void list_clear(QQmlListProperty<QObject> *);
246 void activate(QObject *, int, void **);
248 QList<QQmlVMEVariantQObjectPtr *> varObjectGuards;
250 QQmlVMEVariantQObjectPtr *getQObjectGuardForProperty(int) const;
252 friend class QV8GCCallback;
253 friend class QV8QObjectWrapper;
256 QQmlVMEMetaObject *QQmlVMEMetaObject::get(QObject *obj)
259 if (QQmlData *data = QQmlData::get(obj)) {
260 if (data->hasVMEMetaObject)
261 return static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(obj)->metaObject);
268 int QQmlVMEMetaObject::propOffset() const
270 return cache->propertyOffset();
273 int QQmlVMEMetaObject::methodOffset() const
275 return cache->methodOffset();
278 int QQmlVMEMetaObject::signalOffset() const
280 return cache->signalOffset();
283 int QQmlVMEMetaObject::signalCount() const
285 return cache->signalCount();
288 QQmlVMEMetaObject *QQmlVMEMetaObject::parentVMEMetaObject() const
290 if (parent.isT1() && parent.flag())
291 return static_cast<QQmlVMEMetaObject *>(parent.asT1());
298 #endif // QQMLVMEMETAOBJECT_P_H