1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEDATA_P_H
43 #define QDECLARATIVEDATA_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.
56 #include <QtScript/qscriptvalue.h>
57 #include <private/qobject_p.h>
58 #include "private/qdeclarativeguard_p.h"
62 class QDeclarativeCompiledData;
63 class QDeclarativeAbstractBinding;
64 class QDeclarativeContext;
65 class QDeclarativePropertyCache;
66 class QDeclarativeContextData;
67 class QDeclarativeNotifier;
68 class QDeclarativeDataExtended;
69 // This class is structured in such a way, that simply zero'ing it is the
70 // default state for elemental object allocations. This is crucial in the
71 // workings of the QDeclarativeInstruction::CreateSimpleObject instruction.
72 // Don't change anything here without first considering that case!
73 class Q_AUTOTEST_EXPORT QDeclarativeData : public QAbstractDeclarativeData
77 : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false),
78 context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0),
79 bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0),
80 scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0), extendedData(0) {
84 static inline void init() {
85 QAbstractDeclarativeData::destroyed = destroyed;
86 QAbstractDeclarativeData::parentChanged = parentChanged;
87 QAbstractDeclarativeData::objectNameChanged = objectNameChanged;
90 static void destroyed(QAbstractDeclarativeData *, QObject *);
91 static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
92 static void objectNameChanged(QAbstractDeclarativeData *, QObject *);
94 void destroyed(QObject *);
95 void parentChanged(QObject *, QObject *);
96 void objectNameChanged(QObject *);
98 void setImplicitDestructible() {
99 if (!explicitIndestructibleSet) indestructible = false;
103 quint32 ownContext:1;
104 quint32 indestructible:1;
105 quint32 explicitIndestructibleSet:1;
108 // The context that created the C++ object
109 QDeclarativeContextData *context;
110 // The outermost context in which this object lives
111 QDeclarativeContextData *outerContext;
113 QDeclarativeAbstractBinding *bindings;
115 // Linked list for QDeclarativeContext::contextObjects
116 QDeclarativeData *nextContextObject;
117 QDeclarativeData**prevContextObject;
120 quint32 *bindingBits;
121 bool hasBindingBit(int) const;
122 void clearBindingBit(int);
123 void setBindingBit(QObject *obj, int);
128 QDeclarativeCompiledData *deferredComponent; // Can't this be found from the context?
129 unsigned int deferredIdx;
131 // ### Can we make this QScriptValuePrivate so we incur no additional allocation
133 QScriptValue *scriptValue;
134 quint32 objectDataRefCount;
135 QDeclarativePropertyCache *propertyCache;
137 QDeclarativeGuard<QObject> *guards;
139 static QDeclarativeData *get(const QObject *object, bool create = false) {
140 QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
141 if (priv->wasDeleted) {
144 } else if (priv->declarativeData) {
145 return static_cast<QDeclarativeData *>(priv->declarativeData);
147 priv->declarativeData = new QDeclarativeData;
148 return static_cast<QDeclarativeData *>(priv->declarativeData);
154 bool hasExtendedData() const { return extendedData != 0; }
155 QDeclarativeNotifier *objectNameNotifier() const;
156 QHash<int, QObject *> *attachedProperties() const;
159 // For objectNameNotifier and attachedProperties
160 mutable QDeclarativeDataExtended *extendedData;
164 void QDeclarativeGuard<T>::addGuard()
168 if (QObjectPrivate::get(o)->wasDeleted)
171 QDeclarativeData *data = QDeclarativeData::get(o, true);
173 if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = &next;
174 data->guards = reinterpret_cast<QDeclarativeGuard<QObject> *>(this);
175 prev = &data->guards;
179 void QDeclarativeGuard<T>::remGuard()
183 if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = prev;
191 #endif // QDECLARATIVEDATA_P_H