|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QDECLARATIVEEXPRESSION_P_H |
|
43 #define QDECLARATIVEEXPRESSION_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 "qdeclarativeexpression.h" |
|
57 |
|
58 #include "private/qdeclarativeengine_p.h" |
|
59 #include "private/qdeclarativeguard_p.h" |
|
60 |
|
61 #include <QtScript/qscriptvalue.h> |
|
62 |
|
63 QT_BEGIN_NAMESPACE |
|
64 |
|
65 class QDeclarativeAbstractExpression |
|
66 { |
|
67 public: |
|
68 QDeclarativeAbstractExpression(); |
|
69 virtual ~QDeclarativeAbstractExpression(); |
|
70 |
|
71 bool isValid() const; |
|
72 |
|
73 QDeclarativeContextData *context() const; |
|
74 void setContext(QDeclarativeContextData *); |
|
75 |
|
76 virtual void refresh(); |
|
77 |
|
78 private: |
|
79 friend class QDeclarativeContext; |
|
80 friend class QDeclarativeContextData; |
|
81 friend class QDeclarativeContextPrivate; |
|
82 QDeclarativeContextData *m_context; |
|
83 QDeclarativeAbstractExpression **m_prevExpression; |
|
84 QDeclarativeAbstractExpression *m_nextExpression; |
|
85 }; |
|
86 |
|
87 class QDeclarativeDelayedError |
|
88 { |
|
89 public: |
|
90 inline QDeclarativeDelayedError() : nextError(0), prevError(0) {} |
|
91 inline ~QDeclarativeDelayedError() { removeError(); } |
|
92 |
|
93 QDeclarativeError error; |
|
94 |
|
95 bool addError(QDeclarativeEnginePrivate *); |
|
96 |
|
97 inline void removeError() { |
|
98 if (!prevError) return; |
|
99 if (nextError) nextError->prevError = prevError; |
|
100 *prevError = nextError; |
|
101 nextError = 0; |
|
102 prevError = 0; |
|
103 } |
|
104 |
|
105 private: |
|
106 QDeclarativeDelayedError *nextError; |
|
107 QDeclarativeDelayedError **prevError; |
|
108 }; |
|
109 |
|
110 class QDeclarativeExpressionData : public QDeclarativeAbstractExpression, public QDeclarativeDelayedError, public QDeclarativeRefCount |
|
111 { |
|
112 public: |
|
113 QDeclarativeExpressionData(); |
|
114 virtual ~QDeclarativeExpressionData(); |
|
115 |
|
116 QDeclarativeExpressionPrivate *q; |
|
117 |
|
118 QDeclarativeRefCount *dataRef; |
|
119 QString expression; |
|
120 bool expressionFunctionValid:1; |
|
121 bool expressionRewritten:1; |
|
122 QScriptValue expressionFunction; |
|
123 QScriptValue expressionContext; |
|
124 |
|
125 QObject *me; |
|
126 bool trackChange; |
|
127 |
|
128 bool isShared; |
|
129 |
|
130 QString url; // This is a QString for a reason. QUrls are slooooooow... |
|
131 int line; |
|
132 |
|
133 QDeclarativeNotifierEndpoint *guardList; |
|
134 int guardListLength; |
|
135 }; |
|
136 |
|
137 class QDeclarativeExpression; |
|
138 class QString; |
|
139 class QDeclarativeExpressionPrivate : public QObjectPrivate |
|
140 { |
|
141 Q_DECLARE_PUBLIC(QDeclarativeExpression) |
|
142 public: |
|
143 QDeclarativeExpressionPrivate(); |
|
144 QDeclarativeExpressionPrivate(QDeclarativeExpressionData *); |
|
145 ~QDeclarativeExpressionPrivate(); |
|
146 |
|
147 void init(QDeclarativeContextData *, const QString &, QObject *); |
|
148 void init(QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int); |
|
149 |
|
150 QDeclarativeExpressionData *data; |
|
151 |
|
152 QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0); |
|
153 QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0); |
|
154 |
|
155 QScriptValue eval(QObject *secondaryScope, bool *isUndefined = 0); |
|
156 |
|
157 void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties); |
|
158 void clearGuards(); |
|
159 |
|
160 static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) { |
|
161 return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr)); |
|
162 } |
|
163 static QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr) { |
|
164 return expr->q_func(); |
|
165 } |
|
166 |
|
167 void _q_notify(); |
|
168 virtual void emitValueChanged(); |
|
169 |
|
170 static void exceptionToError(QScriptEngine *, QDeclarativeError &); |
|
171 static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &, |
|
172 int, QScriptValue *); |
|
173 static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &, |
|
174 QScriptValue *); |
|
175 }; |
|
176 |
|
177 QT_END_NAMESPACE |
|
178 |
|
179 #endif // QDECLARATIVEEXPRESSION_P_H |