source: trunk/src/declarative/qml/qdeclarativecontext_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: 9.0 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 QDECLARATIVECONTEXT_P_H
43#define QDECLARATIVECONTEXT_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 "qdeclarativecontext.h"
57
58#include "private/qdeclarativedata_p.h"
59#include "private/qdeclarativeintegercache_p.h"
60#include "private/qdeclarativetypenamecache_p.h"
61#include "private/qdeclarativenotifier_p.h"
62#include "qdeclarativelist.h"
63#include "private/qdeclarativeparser_p.h"
64
65#include <QtCore/qhash.h>
66#include <QtScript/qscriptvalue.h>
67#include <QtCore/qset.h>
68
69#include <private/qobject_p.h>
70#include "private/qdeclarativeguard_p.h"
71
72QT_BEGIN_NAMESPACE
73
74class QDeclarativeContext;
75class QDeclarativeExpression;
76class QDeclarativeEngine;
77class QDeclarativeExpression;
78class QDeclarativeExpressionPrivate;
79class QDeclarativeAbstractExpression;
80class QDeclarativeBinding_Id;
81class QDeclarativeCompiledBindings;
82class QDeclarativeContextData;
83
84class QDeclarativeContextPrivate : public QObjectPrivate
85{
86 Q_DECLARE_PUBLIC(QDeclarativeContext)
87public:
88 QDeclarativeContextPrivate();
89
90 QDeclarativeContextData *data;
91
92 QList<QVariant> propertyValues;
93 int notifyIndex;
94
95 static QDeclarativeContextPrivate *get(QDeclarativeContext *context) {
96 return static_cast<QDeclarativeContextPrivate *>(QObjectPrivate::get(context));
97 }
98 static QDeclarativeContext *get(QDeclarativeContextPrivate *context) {
99 return static_cast<QDeclarativeContext *>(context->q_func());
100 }
101
102 // Only used for debugging
103 QList<QPointer<QObject> > instances;
104
105 static int context_count(QDeclarativeListProperty<QObject> *);
106 static QObject *context_at(QDeclarativeListProperty<QObject> *, int);
107};
108
109class QDeclarativeComponentAttached;
110class QDeclarativeGuardedContextData;
111class Q_AUTOTEST_EXPORT QDeclarativeContextData
112{
113public:
114 QDeclarativeContextData();
115 QDeclarativeContextData(QDeclarativeContext *);
116 void clearContext();
117 void destroy();
118 void invalidate();
119
120 inline bool isValid() const {
121 return engine && (!isInternal || !contextObject || !QObjectPrivate::get(contextObject)->wasDeleted);
122 }
123
124 // My parent context and engine
125 QDeclarativeContextData *parent;
126 QDeclarativeEngine *engine;
127
128 void setParent(QDeclarativeContextData *);
129 void refreshExpressions();
130
131 void addObject(QObject *);
132
133 QUrl resolvedUrl(const QUrl &);
134
135 // My containing QDeclarativeContext. If isInternal is true this owns publicContext.
136 // If internal is false publicContext owns this.
137 QDeclarativeContext *asQDeclarativeContext();
138 QDeclarativeContextPrivate *asQDeclarativeContextPrivate();
139 bool isInternal;
140 QDeclarativeContext *publicContext;
141
142 // Property name cache
143 QDeclarativeIntegerCache *propertyNames;
144
145 // Context object
146 QObject *contextObject;
147
148 // Any script blocks that exist on this context
149 QList<QScriptValue> importedScripts;
150 void addImportedScript(const QDeclarativeParser::Object::ScriptBlock &script);
151
152 // Context base url
153 QUrl url;
154
155 // List of imports that apply to this context
156 QDeclarativeTypeNameCache *imports;
157
158 // My children
159 QDeclarativeContextData *childContexts;
160
161 // My peers in parent's childContexts list
162 QDeclarativeContextData *nextChild;
163 QDeclarativeContextData **prevChild;
164
165 // Expressions that use this context
166 QDeclarativeAbstractExpression *expressions;
167
168 // Doubly-linked list of objects that are owned by this context
169 QDeclarativeData *contextObjects;
170
171 // Doubly-linked list of context guards (XXX merge with contextObjects)
172 QDeclarativeGuardedContextData *contextGuards;
173
174 // id guards
175 struct ContextGuard : public QDeclarativeGuard<QObject>
176 {
177 ContextGuard() : context(0) {}
178 inline ContextGuard &operator=(QObject *obj)
179 { QDeclarativeGuard<QObject>::operator=(obj); return *this; }
180 virtual void objectDestroyed(QObject *) {
181 if (context->contextObject && !QObjectPrivate::get(context->contextObject)->wasDeleted) bindings.notify();
182 }
183 QDeclarativeContextData *context;
184 QDeclarativeNotifier bindings;
185 };
186 ContextGuard *idValues;
187 int idValueCount;
188 void setIdProperty(int, QObject *);
189 void setIdPropertyData(QDeclarativeIntegerCache *);
190
191 // Optimized binding pointer
192 QDeclarativeCompiledBindings *optimizedBindings;
193
194 // Linked contexts. this owns linkedContext.
195 QDeclarativeContextData *linkedContext;
196
197 // Linked list of uses of the Component attached property in this
198 // context
199 QDeclarativeComponentAttached *componentAttached;
200
201 // Return the outermost id for obj, if any.
202 QString findObjectId(const QObject *obj) const;
203
204 static QDeclarativeContextData *get(QDeclarativeContext *context) {
205 return QDeclarativeContextPrivate::get(context)->data;
206 }
207
208private:
209 ~QDeclarativeContextData() {}
210};
211
212class QDeclarativeGuardedContextData
213{
214public:
215 inline QDeclarativeGuardedContextData();
216 inline QDeclarativeGuardedContextData(QDeclarativeContextData *);
217 inline ~QDeclarativeGuardedContextData();
218
219 inline void setContextData(QDeclarativeContextData *);
220
221 inline QDeclarativeContextData *contextData();
222
223 inline operator QDeclarativeContextData*() const { return m_contextData; }
224 inline QDeclarativeContextData* operator->() const { return m_contextData; }
225 inline QDeclarativeGuardedContextData &operator=(QDeclarativeContextData *d);
226
227private:
228 QDeclarativeGuardedContextData &operator=(const QDeclarativeGuardedContextData &);
229 QDeclarativeGuardedContextData(const QDeclarativeGuardedContextData &);
230 friend class QDeclarativeContextData;
231
232 inline void clear();
233
234 QDeclarativeContextData *m_contextData;
235 QDeclarativeGuardedContextData *m_next;
236 QDeclarativeGuardedContextData **m_prev;
237};
238
239QDeclarativeGuardedContextData::QDeclarativeGuardedContextData()
240: m_contextData(0), m_next(0), m_prev(0)
241{
242}
243
244QDeclarativeGuardedContextData::QDeclarativeGuardedContextData(QDeclarativeContextData *data)
245: m_contextData(0), m_next(0), m_prev(0)
246{
247 setContextData(data);
248}
249
250QDeclarativeGuardedContextData::~QDeclarativeGuardedContextData()
251{
252 clear();
253}
254
255void QDeclarativeGuardedContextData::setContextData(QDeclarativeContextData *contextData)
256{
257 clear();
258
259 if (contextData) {
260 m_contextData = contextData;
261 m_next = contextData->contextGuards;
262 if (m_next) m_next->m_prev = &m_next;
263 m_prev = &contextData->contextGuards;
264 contextData->contextGuards = this;
265 }
266}
267
268QDeclarativeContextData *QDeclarativeGuardedContextData::contextData()
269{
270 return m_contextData;
271}
272
273void QDeclarativeGuardedContextData::clear()
274{
275 if (m_prev) {
276 *m_prev = m_next;
277 if (m_next) m_next->m_prev = m_prev;
278 m_contextData = 0;
279 m_next = 0;
280 m_prev = 0;
281 }
282}
283
284QDeclarativeGuardedContextData &
285QDeclarativeGuardedContextData::operator=(QDeclarativeContextData *d)
286{
287 setContextData(d);
288 return *this;
289}
290
291QT_END_NAMESPACE
292
293#endif // QDECLARATIVECONTEXT_P_H
Note: See TracBrowser for help on using the repository browser.