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 ****************************************************************************/
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.
56 #include <private/qtqmlglobal_p.h>
57 #include <private/qobject_p.h>
58 #include <private/qv8_p.h>
62 template <class Key, class T> class QHash;
64 class QQmlCompiledData;
65 class QQmlAbstractBinding;
66 class QQmlAbstractBoundSignal;
68 class QQmlPropertyCache;
69 class QQmlContextData;
71 class QQmlDataExtended;
72 class QQmlNotifierEndpoint;
73 // This class is structured in such a way, that simply zero'ing it is the
74 // default state for elemental object allocations. This is crucial in the
75 // workings of the QQmlInstruction::CreateSimpleObject instruction.
76 // Don't change anything here without first considering that case!
77 class Q_QML_PRIVATE_EXPORT QQmlData : public QAbstractDeclarativeData
81 : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false),
82 hasTaintedV8Object(false), isQueuedForDeletion(false), rootObjectInCreation(false),
83 hasVMEMetaObject(false), parentFrozen(false), notifyList(0), context(0), outerContext(0),
84 bindings(0), signalHandlers(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0),
85 lineNumber(0), columnNumber(0), compiledData(0), deferredIdx(0), v8objectid(0),
86 propertyCache(0), guards(0), extendedData(0) {
90 static inline void init() {
91 static bool initialized = false;
94 QAbstractDeclarativeData::destroyed = destroyed;
95 QAbstractDeclarativeData::parentChanged = parentChanged;
96 QAbstractDeclarativeData::signalEmitted = signalEmitted;
97 QAbstractDeclarativeData::receivers = receivers;
98 QAbstractDeclarativeData::isSignalConnected = isSignalConnected;
102 static void destroyed(QAbstractDeclarativeData *, QObject *);
103 static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
104 static void signalEmitted(QAbstractDeclarativeData *, QObject *, int, void **);
105 static int receivers(QAbstractDeclarativeData *, const QObject *, int);
106 static bool isSignalConnected(QAbstractDeclarativeData *, const QObject *, int);
108 void destroyed(QObject *);
109 void parentChanged(QObject *, QObject *);
111 void setImplicitDestructible() {
112 if (!explicitIndestructibleSet) indestructible = false;
116 quint32 ownContext:1;
117 quint32 indestructible:1;
118 quint32 explicitIndestructibleSet:1;
119 quint32 hasTaintedV8Object:1;
120 quint32 isQueuedForDeletion:1;
122 * rootObjectInCreation should be true only when creating top level CPP and QML objects,
123 * v8 GC will check this flag, only deletes the objects when rootObjectInCreation is false.
125 quint32 rootObjectInCreation:1;
126 quint32 hasVMEMetaObject:1;
127 quint32 parentFrozen:1;
131 quint64 connectionMask;
133 quint16 maximumTodoIndex;
134 quint16 notifiesSize;
136 QQmlNotifierEndpoint *todo;
137 QQmlNotifierEndpoint**notifies;
140 void layout(QQmlNotifierEndpoint*);
142 NotifyList *notifyList;
144 inline QQmlNotifierEndpoint *notify(int index);
145 void addNotify(int index, QQmlNotifierEndpoint *);
146 int endpointCount(int index);
147 bool signalHasEndpoint(int index);
149 // The context that created the C++ object
150 QQmlContextData *context;
151 // The outermost context in which this object lives
152 QQmlContextData *outerContext;
154 QQmlAbstractBinding *bindings;
155 QQmlAbstractBoundSignal *signalHandlers;
157 // Linked list for QQmlContext::contextObjects
158 QQmlData *nextContextObject;
159 QQmlData**prevContextObject;
162 quint32 *bindingBits;
163 bool hasBindingBit(int) const;
164 void clearBindingBit(int);
165 void setBindingBit(QObject *obj, int);
170 QQmlCompiledData *compiledData;
171 unsigned int deferredIdx;
174 v8::Persistent<v8::Object> v8object;
176 QQmlPropertyCache *propertyCache;
178 QQmlGuardImpl *guards;
180 static QQmlData *get(const QObject *object, bool create = false) {
181 QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
182 if (priv->wasDeleted) {
185 } else if (priv->declarativeData) {
186 return static_cast<QQmlData *>(priv->declarativeData);
188 priv->declarativeData = new QQmlData;
189 return static_cast<QQmlData *>(priv->declarativeData);
195 bool hasExtendedData() const { return extendedData != 0; }
196 QHash<int, QObject *> *attachedProperties() const;
198 static inline bool wasDeleted(QObject *);
200 static void markAsDeleted(QObject *);
201 static void setQueuedForDeletion(QObject *);
204 // For attachedProperties
205 mutable QQmlDataExtended *extendedData;
208 bool QQmlData::wasDeleted(QObject *object)
213 QObjectPrivate *priv = QObjectPrivate::get(object);
214 if (priv->wasDeleted)
217 return priv->declarativeData &&
218 static_cast<QQmlData *>(priv->declarativeData)->isQueuedForDeletion;
221 QQmlNotifierEndpoint *QQmlData::notify(int index)
223 Q_ASSERT(index <= 0xFFFF);
225 if (!notifyList || !(notifyList->connectionMask & (1ULL << quint64(index % 64)))) {
227 } else if (index < notifyList->notifiesSize) {
228 return notifyList->notifies[index];
229 } else if (index <= notifyList->maximumTodoIndex) {
230 notifyList->layout();
233 if (index < notifyList->notifiesSize) {
234 return notifyList->notifies[index];
242 #endif // QQMLDATA_P_H