1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Copyright (C) 2015 BasysKom GmbH.
5 ** Contact: http://www.qt.io/licensing/
7 ** This file is part of the QtQml module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL21$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see http://www.qt.io/terms-conditions. For further
16 ** information use the contact form at http://www.qt.io/contact-us.
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 2.1 or version 3 as published by the Free
21 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
22 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
23 ** following information to ensure the GNU Lesser General Public License
24 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
25 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
27 ** As a special exception, The Qt Company gives you certain additional
28 ** rights. These rights are described in The Qt Company LGPL Exception
29 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
33 ****************************************************************************/
35 #ifndef QQMLVMEMETAOBJECT_P_H
36 #define QQMLVMEMETAOBJECT_P_H
42 // This file is not part of the Qt API. It exists purely as an
43 // implementation detail. This header file may change from version to
44 // version without notice, or even be removed.
51 #include <QtCore/QMetaObject>
52 #include <QtCore/QBitArray>
53 #include <QtCore/QPair>
54 #include <QtCore/QDate>
55 #include <QtCore/qlist.h>
56 #include <QtCore/qdebug.h>
58 #include <private/qobject_p.h>
60 #include "qqmlguard_p.h"
61 #include "qqmlcompiler_p.h"
62 #include "qqmlcontext_p.h"
64 #include <private/qv8engine_p.h>
65 #include <private/qflagpointer_p.h>
67 #include <private/qv4value_p.h>
71 #define QML_ALIAS_FLAG_PTR 0x00000001
73 struct QQmlVMEMetaData
75 short varPropertyCount;
80 short dummyForAlignment; // Add padding to ensure that the following
81 // AliasData/PropertyData/MethodData is int aligned.
90 bool isObjectAlias() const {
91 return propertyIdx == -1;
93 bool isPropertyAlias() const {
94 return !isObjectAlias() && valueTypeIndex() == -1;
96 bool isValueTypeAlias() const {
97 return !isObjectAlias() && valueTypeIndex() != -1;
99 int propertyIndex() const {
101 QQmlPropertyData::decodeValueTypePropertyIndex(propertyIdx, &index);
104 int valueTypeIndex() const {
105 return QQmlPropertyData::decodeValueTypePropertyIndex(propertyIdx);
107 int valueType() const {
108 return (valueTypeIndex() != -1) ? propType : 0;
112 struct PropertyData {
117 int runtimeFunctionIndex;
122 PropertyData *propertyData() const {
123 return (PropertyData *)(((char *)const_cast<QQmlVMEMetaData *>(this)) + sizeof(QQmlVMEMetaData));
126 AliasData *aliasData() const {
127 return (AliasData *)(propertyData() + propertyCount);
130 MethodData *methodData() const {
131 return (MethodData *)(aliasData() + aliasCount);
135 class QQmlVMEMetaObject;
136 class QQmlVMEVariantQObjectPtr : public QQmlGuard<QObject>
139 inline QQmlVMEVariantQObjectPtr(bool isVar);
140 inline ~QQmlVMEVariantQObjectPtr();
142 inline void objectDestroyed(QObject *);
143 inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index);
145 QQmlVMEMetaObject *m_target;
146 unsigned m_isVar : 1; // TODO: remove?
150 class QQmlVMEVariant;
152 class QQmlVMEMetaObjectEndpoint;
153 class Q_QML_PRIVATE_EXPORT QQmlVMEMetaObject : public QAbstractDynamicMetaObject
156 QQmlVMEMetaObject(QObject *obj, QQmlPropertyCache *cache, const QQmlVMEMetaData *data,
157 QV4::ExecutionContext *qmlBindingContext = 0, QQmlCompiledData *compiledData = 0);
158 ~QQmlVMEMetaObject();
160 bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const;
161 void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor);
162 QV4::ReturnedValue vmeMethod(int index);
163 quint16 vmeMethodLineNumber(int index);
164 void setVmeMethod(int index, const QV4::Value &function);
165 QV4::ReturnedValue vmeProperty(int index);
166 void setVMEProperty(int index, const QV4::Value &v);
168 void connectAliasSignal(int index, bool indexInSignalRange);
170 virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *o);
172 // Used by auto-tests for inspection
173 QQmlPropertyCache *propertyCache() const { return cache; }
175 static inline QQmlVMEMetaObject *get(QObject *o);
176 static QQmlVMEMetaObject *getForProperty(QObject *o, int coreIndex);
177 static QQmlVMEMetaObject *getForMethod(QObject *o, int coreIndex);
178 static QQmlVMEMetaObject *getForSignal(QObject *o, int coreIndex);
181 virtual int metaCall(QMetaObject::Call _c, int _id, void **_a);
184 friend class QQmlVMEMetaObjectEndpoint;
185 friend class QQmlVMEVariantQObjectPtr;
186 friend class QQmlPropertyCache;
189 QQmlGuardedContextData ctxt;
190 QQmlPropertyCache *cache;
192 const QQmlVMEMetaData *metaData;
193 inline int propOffset() const;
194 inline int methodOffset() const;
195 inline int signalOffset() const;
196 inline int signalCount() const;
198 bool hasAssignedMetaObjectData;
199 QQmlVMEMetaObjectEndpoint *aliasEndpoints;
201 QV4::WeakValue properties;
202 int firstVarPropertyIndex;
203 bool propertiesInitialized;
204 inline void allocateProperties();
205 inline bool ensurePropertiesAllocated();
207 int readPropertyAsInt(int id);
208 bool readPropertyAsBool(int id);
209 double readPropertyAsDouble(int id);
210 QString readPropertyAsString(int id);
211 QSizeF readPropertyAsSizeF(int id);
212 QPointF readPropertyAsPointF(int id);
213 QUrl readPropertyAsUrl(int id);
214 QDate readPropertyAsDate(int id);
215 QDateTime readPropertyAsDateTime(int id);
216 QRectF readPropertyAsRectF(int id);
217 QObject* readPropertyAsQObject(int id);
219 void writeProperty(int id, int v);
220 void writeProperty(int id, bool v);
221 void writeProperty(int id, double v);
222 void writeProperty(int id, const QString& v);
223 void writeProperty(int id, const QPointF& v);
224 void writeProperty(int id, const QSizeF& v);
225 void writeProperty(int id, const QUrl& v);
226 void writeProperty(int id, const QDate& v);
227 void writeProperty(int id, const QDateTime& v);
228 void writeProperty(int id, const QRectF& v);
229 void writeProperty(int id, QObject *v);
231 void ensureQObjectWrapper();
233 void mark(QV4::ExecutionEngine *e);
235 void connectAlias(int aliasId);
236 QBitArray aConnected;
238 QQmlPropertyValueInterceptor *interceptors;
240 QV4::PersistentValue *v8methods;
241 QV4::ReturnedValue method(int);
243 QV4::ReturnedValue readVarProperty(int);
244 void writeVarProperty(int, const QV4::Value &);
245 QVariant readPropertyAsVariant(int);
246 void writeProperty(int, const QVariant &);
248 QBiPointer<QDynamicMetaObjectData, const QMetaObject> parent;
250 inline QQmlVMEMetaObject *parentVMEMetaObject() const;
252 void listChanged(int);
253 class List : public QList<QObject*>
256 List(int lpi, QQmlVMEMetaObject *mo) : notifyIndex(lpi), mo(mo) {}
258 QQmlVMEMetaObject *mo;
260 QList<List> listProperties;
262 static void list_append(QQmlListProperty<QObject> *, QObject *);
263 static int list_count(QQmlListProperty<QObject> *);
264 static QObject *list_at(QQmlListProperty<QObject> *, int);
265 static void list_clear(QQmlListProperty<QObject> *);
267 void activate(QObject *, int, void **);
269 QList<QQmlVMEVariantQObjectPtr *> varObjectGuards;
271 QQmlVMEVariantQObjectPtr *getQObjectGuardForProperty(int) const;
273 friend class QV8GCCallback;
276 QQmlVMEMetaObject *QQmlVMEMetaObject::get(QObject *obj)
279 if (QQmlData *data = QQmlData::get(obj)) {
280 if (data->hasVMEMetaObject)
281 return static_cast<QQmlVMEMetaObject *>(QObjectPrivate::get(obj)->metaObject);
288 int QQmlVMEMetaObject::propOffset() const
290 return cache->propertyOffset();
293 int QQmlVMEMetaObject::methodOffset() const
295 return cache->methodOffset();
298 int QQmlVMEMetaObject::signalOffset() const
300 return cache->signalOffset();
303 int QQmlVMEMetaObject::signalCount() const
305 return cache->signalCount();
308 QQmlVMEMetaObject *QQmlVMEMetaObject::parentVMEMetaObject() const
310 if (parent.isT1() && parent.flag())
311 return static_cast<QQmlVMEMetaObject *>(parent.asT1());
318 #endif // QQMLVMEMETAOBJECT_P_H