Qt 4.8
qdeclarativecontext_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
73 
76 class QDeclarativeEngine;
82 
84 {
86 public:
88 
90 
93 
95  return static_cast<QDeclarativeContextPrivate *>(QObjectPrivate::get(context));
96  }
98  return static_cast<QDeclarativeContext *>(context->q_func());
99  }
100 
101  // Only used for debugging
103 
106 };
107 
111 {
112 public:
115  void clearContext();
116  void destroy();
117  void invalidate();
118 
119  inline bool isValid() const {
120  return engine && (!isInternal || !contextObject || !QObjectPrivate::get(contextObject)->wasDeleted);
121  }
122 
123  // My parent context and engine
126 
127  void setParent(QDeclarativeContextData *);
128  void refreshExpressions();
129 
130  void addObject(QObject *);
131 
132  QUrl resolvedUrl(const QUrl &);
133 
134  // My containing QDeclarativeContext. If isInternal is true this owns publicContext.
135  // If internal is false publicContext owns this.
136  QDeclarativeContext *asQDeclarativeContext();
137  QDeclarativeContextPrivate *asQDeclarativeContextPrivate();
140 
141  // Property name cache
143 
144  // Context object
146 
147  // Any script blocks that exist on this context
149  void addImportedScript(const QDeclarativeParser::Object::ScriptBlock &script);
150 
151  // Context base url
153 
154  // List of imports that apply to this context
156 
157  // My children
159 
160  // My peers in parent's childContexts list
163 
164  // Expressions that use this context
166 
167  // Doubly-linked list of objects that are owned by this context
169 
170  // Doubly-linked list of context guards (XXX merge with contextObjects)
172 
173  // id guards
174  struct ContextGuard : public QDeclarativeGuard<QObject>
175  {
176  ContextGuard() : context(0) {}
178  { QDeclarativeGuard<QObject>::operator=(obj); return *this; }
179  virtual void objectDestroyed(QObject *) {
180  if (context->contextObject && !QObjectPrivate::get(context->contextObject)->wasDeleted) bindings.notify();
181  }
184  };
187  void setIdProperty(int, QObject *);
188  void setIdPropertyData(QDeclarativeIntegerCache *);
189 
190  // Optimized binding pointer
192 
193  // Linked contexts. this owns linkedContext.
195 
196  // Linked list of uses of the Component attached property in this
197  // context
199 
200  // Return the outermost id for obj, if any.
201  QString findObjectId(const QObject *obj) const;
202 
204  return QDeclarativeContextPrivate::get(context)->data;
205  }
206 
207 private:
209 };
210 
212 {
213 public:
217 
218  inline void setContextData(QDeclarativeContextData *);
219 
220  inline QDeclarativeContextData *contextData();
221 
222  inline operator QDeclarativeContextData*() const { return m_contextData; }
223  inline QDeclarativeContextData* operator->() const { return m_contextData; }
225 
226 private:
230 
231  inline void clear();
232 
236 };
237 
239 : m_contextData(0), m_next(0), m_prev(0)
240 {
241 }
242 
244 : m_contextData(0), m_next(0), m_prev(0)
245 {
246  setContextData(data);
247 }
248 
250 {
251  clear();
252 }
253 
255 {
256  clear();
257 
258  if (contextData) {
260  m_next = contextData->contextGuards;
261  if (m_next) m_next->m_prev = &m_next;
262  m_prev = &contextData->contextGuards;
263  contextData->contextGuards = this;
264  }
265 }
266 
268 {
269  return m_contextData;
270 }
271 
273 {
274  if (m_prev) {
275  *m_prev = m_next;
276  if (m_next) m_next->m_prev = m_prev;
277  m_contextData = 0;
278  m_next = 0;
279  m_prev = 0;
280  }
281 }
282 
285 {
286  setContextData(d);
287  return *this;
288 }
289 
291 
292 #endif // QDECLARATIVECONTEXT_P_H
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QDeclarativeEngine * engine
QDeclarativeContext * publicContext
QDeclarativeComponentAttached * componentAttached
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
uint wasDeleted
Definition: qobject.h:98
static int context_count(QDeclarativeListProperty< QObject > *)
QDeclarativeAbstractExpression * expressions
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setContextData(QDeclarativeContextData *)
QDeclarativeContextData * linkedContext
QDeclarativeContextData * parent
QDeclarativeContextData * m_contextData
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
QDeclarativeGuardedContextData * m_next
QDeclarativeTypeNameCache * imports
QDeclarativeGuard< T > & operator=(const QDeclarativeGuard< T > &o)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QDeclarativeContextData * data
QDeclarativeGuardedContextData & operator=(QDeclarativeContextData *d)
ContextGuard & operator=(QObject *obj)
QDeclarativeContextData * nextChild
static const char * data(const QByteArray &arr)
QDeclarativeData * contextObjects
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QDeclarativeIntegerCache * propertyNames
QList< QPointer< QObject > > instances
static QDeclarativeContextPrivate * get(QDeclarativeContext *context)
QDeclarativeContextData * operator->() const
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativeContextData ** prevChild
QDeclarativeGuardedContextData ** m_prev
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
The QDeclarativeContext class defines a context within a QML engine.
static QObject * context_at(QDeclarativeListProperty< QObject > *, int)
QDeclarativeContextData * contextData()
QDeclarativeCompiledBindings * optimizedBindings
The QDeclarativeExpression class evaluates JavaScript in a QML context.
QList< QScriptValue > importedScripts
QDeclarativeGuardedContextData * contextGuards
QDeclarativeContextData * childContexts