source: trunk/src/declarative/qml/qdeclarativedata_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the QtDeclarative module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QDECLARATIVEDATA_P_H
43#define QDECLARATIVEDATA_P_H
44
45//
46// W A R N I N G
47// -------------
48//
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.
52//
53// We mean it.
54//
55
56#include <QtScript/qscriptvalue.h>
57#include <private/qobject_p.h>
58#include "private/qdeclarativeguard_p.h"
59
60QT_BEGIN_NAMESPACE
61
62class QDeclarativeCompiledData;
63class QDeclarativeAbstractBinding;
64class QDeclarativeContext;
65class QDeclarativePropertyCache;
66class QDeclarativeContextData;
67class QDeclarativeNotifier;
68class 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!
73class Q_AUTOTEST_EXPORT QDeclarativeData : public QAbstractDeclarativeData
74{
75public:
76 QDeclarativeData()
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) {
81 init();
82 }
83
84 static inline void init() {
85 QAbstractDeclarativeData::destroyed = destroyed;
86 QAbstractDeclarativeData::parentChanged = parentChanged;
87 QAbstractDeclarativeData::objectNameChanged = objectNameChanged;
88 }
89
90 static void destroyed(QAbstractDeclarativeData *, QObject *);
91 static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
92 static void objectNameChanged(QAbstractDeclarativeData *, QObject *);
93
94 void destroyed(QObject *);
95 void parentChanged(QObject *, QObject *);
96 void objectNameChanged(QObject *);
97
98 void setImplicitDestructible() {
99 if (!explicitIndestructibleSet) indestructible = false;
100 }
101
102 quint32 ownMemory:1;
103 quint32 ownContext:1;
104 quint32 indestructible:1;
105 quint32 explicitIndestructibleSet:1;
106 quint32 dummy:28;
107
108 // The context that created the C++ object
109 QDeclarativeContextData *context;
110 // The outermost context in which this object lives
111 QDeclarativeContextData *outerContext;
112
113 QDeclarativeAbstractBinding *bindings;
114
115 // Linked list for QDeclarativeContext::contextObjects
116 QDeclarativeData *nextContextObject;
117 QDeclarativeData**prevContextObject;
118
119 int bindingBitsSize;
120 quint32 *bindingBits;
121 bool hasBindingBit(int) const;
122 void clearBindingBit(int);
123 void setBindingBit(QObject *obj, int);
124
125 ushort lineNumber;
126 ushort columnNumber;
127
128 QDeclarativeCompiledData *deferredComponent; // Can't this be found from the context?
129 unsigned int deferredIdx;
130
131 // ### Can we make this QScriptValuePrivate so we incur no additional allocation
132 // cost?
133 QScriptValue *scriptValue;
134 quint32 objectDataRefCount;
135 QDeclarativePropertyCache *propertyCache;
136
137 QDeclarativeGuard<QObject> *guards;
138
139 static QDeclarativeData *get(const QObject *object, bool create = false) {
140 QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
141 if (priv->wasDeleted) {
142 Q_ASSERT(!create);
143 return 0;
144 } else if (priv->declarativeData) {
145 return static_cast<QDeclarativeData *>(priv->declarativeData);
146 } else if (create) {
147 priv->declarativeData = new QDeclarativeData;
148 return static_cast<QDeclarativeData *>(priv->declarativeData);
149 } else {
150 return 0;
151 }
152 }
153
154 bool hasExtendedData() const { return extendedData != 0; }
155 QDeclarativeNotifier *objectNameNotifier() const;
156 QHash<int, QObject *> *attachedProperties() const;
157
158private:
159 // For objectNameNotifier and attachedProperties
160 mutable QDeclarativeDataExtended *extendedData;
161};
162
163template<class T>
164void QDeclarativeGuard<T>::addGuard()
165{
166 Q_ASSERT(!prev);
167
168 if (QObjectPrivate::get(o)->wasDeleted)
169 return;
170
171 QDeclarativeData *data = QDeclarativeData::get(o, true);
172 next = data->guards;
173 if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = &next;
174 data->guards = reinterpret_cast<QDeclarativeGuard<QObject> *>(this);
175 prev = &data->guards;
176}
177
178template<class T>
179void QDeclarativeGuard<T>::remGuard()
180{
181 Q_ASSERT(prev);
182
183 if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = prev;
184 *prev = next;
185 next = 0;
186 prev = 0;
187}
188
189QT_END_NAMESPACE
190
191#endif // QDECLARATIVEDATA_P_H
Note: See TracBrowser for help on using the repository browser.