1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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.
96 bool isObjectAlias() const {
97 return propertyIdx == -1;
99 bool isPropertyAlias() const {
100 return !isObjectAlias() && !(propertyIdx & 0xFF000000);
102 bool isValueTypeAlias() const {
103 return !isObjectAlias() && (propertyIdx & 0xFF000000);
105 int propertyIndex() const {
106 return propertyIdx & 0x0000FFFF;
108 int valueTypeIndex() const {
109 return (propertyIdx & 0x00FF0000) >> 16;
111 int valueType() const {
112 return ((unsigned int)propertyIdx) >> 24;
116 struct PropertyData {
127 PropertyData *propertyData() const {
128 return (PropertyData *)(((const char *)this) + sizeof(QQmlVMEMetaData));
131 AliasData *aliasData() const {
132 return (AliasData *)(propertyData() + propertyCount);
135 MethodData *methodData() const {
136 return (MethodData *)(aliasData() + aliasCount);
140 class QQmlVMEMetaObject;
141 class QQmlVMEVariantQObjectPtr : public QQmlGuard<QObject>
144 inline QQmlVMEVariantQObjectPtr(bool isVar);
145 inline ~QQmlVMEVariantQObjectPtr();
147 inline void objectDestroyed(QObject *);
148 inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index);
150 QQmlVMEMetaObject *m_target;
151 unsigned m_isVar : 1;
155 class QV8QObjectWrapper;
156 class QQmlVMEVariant;
158 class QQmlVMEMetaObjectEndpoint;
159 class Q_AUTOTEST_EXPORT QQmlVMEMetaObject : public QAbstractDynamicMetaObject,
160 public QV8GCCallback::Node
163 QQmlVMEMetaObject(QObject *obj, QQmlPropertyCache *cache, const QQmlVMEMetaData *data);
164 ~QQmlVMEMetaObject();
166 bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const;
167 void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor);
168 v8::Handle<v8::Function> vmeMethod(int index);
169 int vmeMethodLineNumber(int index);
170 void setVmeMethod(int index, v8::Persistent<v8::Function>);
171 v8::Handle<v8::Value> vmeProperty(int index);
172 void setVMEProperty(int index, v8::Handle<v8::Value> v);
174 void connectAliasSignal(int index, bool indexInSignalRange);
176 virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *o);
178 static inline QQmlVMEMetaObject *get(QObject *o);
179 static QQmlVMEMetaObject *getForProperty(QObject *o, int coreIndex);
180 static QQmlVMEMetaObject *getForMethod(QObject *o, int coreIndex);
181 static QQmlVMEMetaObject *getForSignal(QObject *o, int coreIndex);
184 virtual int metaCall(QMetaObject::Call _c, int _id, void **_a);
187 friend class QQmlVMEMetaObjectEndpoint;
188 friend class QQmlVMEVariantQObjectPtr;
191 QQmlGuardedContextData ctxt;
192 QQmlPropertyCache *cache;
194 const QQmlVMEMetaData *metaData;
195 inline int propOffset() const;
196 inline int methodOffset() const;
197 inline int signalOffset() const;
199 bool hasAssignedMetaObjectData;
200 QQmlVMEVariant *data;
201 QQmlVMEMetaObjectEndpoint *aliasEndpoints;
203 v8::Persistent<v8::Array> varProperties;
204 int firstVarPropertyIndex;
205 bool varPropertiesInitialized;
206 static void VarPropertiesWeakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter);
207 static void GcPrologueCallback(QV8GCCallback::Node *node);
208 inline void allocateVarPropertiesArray();
209 inline bool ensureVarPropertiesAllocated();
211 void connectAlias(int aliasId);
212 QBitArray aConnected;
214 QQmlPropertyValueInterceptor *interceptors;
216 v8::Persistent<v8::Function> *v8methods;
217 v8::Handle<v8::Function> method(int);
219 v8::Handle<v8::Value> readVarProperty(int);
220 void writeVarProperty(int, v8::Handle<v8::Value>);
221 QVariant readPropertyAsVariant(int);
222 void writeProperty(int, const QVariant &);
224 QBiPointer<QDynamicMetaObjectData, const QMetaObject> parent;
226 void listChanged(int);
227 class List : public QList<QObject*>
230 List(int lpi, QQmlVMEMetaObject *mo) : notifyIndex(lpi), mo(mo) {}
232 QQmlVMEMetaObject *mo;
234 QList<List> listProperties;
236 static void list_append(QQmlListProperty<QObject> *, QObject *);
237 static int list_count(QQmlListProperty<QObject> *);
238 static QObject *list_at(QQmlListProperty<QObject> *, int);
239 static void list_clear(QQmlListProperty<QObject> *);
241 void activate(QObject *, int, void **);
243 QList<QQmlVMEVariantQObjectPtr *> varObjectGuards;
245 QQmlVMEVariantQObjectPtr *getQObjectGuardForProperty(int) const;
247 friend class QV8GCCallback;
248 friend class QV8QObjectWrapper;
251 QQmlVMEMetaObject *QQmlVMEMetaObject::get(QObject *obj)
254 if (QQmlData *data = QQmlData::get(obj)) {
255 if (data->hasVMEMetaObject)
256 return static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(obj)->metaObject);
263 int QQmlVMEMetaObject::propOffset() const
265 return cache->propertyOffset();
268 int QQmlVMEMetaObject::methodOffset() const
270 return cache->methodOffset();
273 int QQmlVMEMetaObject::signalOffset() const
275 return cache->signalOffset();
280 #endif // QQMLVMEMETAOBJECT_P_H