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 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 QDeclarativeQtScriptExpression : public QDeclarativeAbstractExpression,
|
---|
111 | public QDeclarativeDelayedError
|
---|
112 | {
|
---|
113 | public:
|
---|
114 | enum Mode { SharedContext, ExplicitContext };
|
---|
115 |
|
---|
116 | QDeclarativeQtScriptExpression();
|
---|
117 | virtual ~QDeclarativeQtScriptExpression();
|
---|
118 |
|
---|
119 | QDeclarativeRefCount *dataRef;
|
---|
120 |
|
---|
121 | QString expression;
|
---|
122 |
|
---|
123 | Mode expressionFunctionMode;
|
---|
124 | QScriptValue expressionFunction;
|
---|
125 |
|
---|
126 | QScriptValue expressionContext; // Only used in ExplicitContext
|
---|
127 | QObject *scopeObject; // Only used in SharedContext
|
---|
128 |
|
---|
129 | bool notifyOnValueChange() const;
|
---|
130 | void setNotifyOnValueChange(bool);
|
---|
131 | void resetNotifyOnChange();
|
---|
132 | void setNotifyObject(QObject *, int );
|
---|
133 |
|
---|
134 | QScriptValue scriptValue(QObject *secondaryScope, bool *isUndefined);
|
---|
135 |
|
---|
136 | class DeleteWatcher {
|
---|
137 | public:
|
---|
138 | inline DeleteWatcher(QDeclarativeQtScriptExpression *data);
|
---|
139 | inline ~DeleteWatcher();
|
---|
140 | inline bool wasDeleted() const;
|
---|
141 | private:
|
---|
142 | bool *m_wasDeleted;
|
---|
143 | bool m_wasDeletedStorage;
|
---|
144 | QDeclarativeQtScriptExpression *m_d;
|
---|
145 | };
|
---|
146 |
|
---|
147 | private:
|
---|
148 | void clearGuards();
|
---|
149 | QScriptValue eval(QObject *secondaryScope, bool *isUndefined);
|
---|
150 | void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties);
|
---|
151 |
|
---|
152 | bool trackChange;
|
---|
153 |
|
---|
154 | QDeclarativeNotifierEndpoint *guardList;
|
---|
155 | int guardListLength;
|
---|
156 |
|
---|
157 | QObject *guardObject;
|
---|
158 | int guardObjectNotifyIndex;
|
---|
159 | bool *deleted;
|
---|
160 | };
|
---|
161 |
|
---|
162 | class QDeclarativeExpression;
|
---|
163 | class QString;
|
---|
164 | class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeQtScriptExpression
|
---|
165 | {
|
---|
166 | Q_DECLARE_PUBLIC(QDeclarativeExpression)
|
---|
167 | public:
|
---|
168 | QDeclarativeExpressionPrivate();
|
---|
169 | ~QDeclarativeExpressionPrivate();
|
---|
170 |
|
---|
171 | void init(QDeclarativeContextData *, const QString &, QObject *);
|
---|
172 | void init(QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int);
|
---|
173 |
|
---|
174 | QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0);
|
---|
175 | QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0);
|
---|
176 |
|
---|
177 | static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) {
|
---|
178 | return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr));
|
---|
179 | }
|
---|
180 | static QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr) {
|
---|
181 | return expr->q_func();
|
---|
182 | }
|
---|
183 |
|
---|
184 | void _q_notify();
|
---|
185 | virtual void emitValueChanged();
|
---|
186 |
|
---|
187 | static void exceptionToError(QScriptEngine *, QDeclarativeError &);
|
---|
188 | static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &,
|
---|
189 | int, QScriptValue *);
|
---|
190 | static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &,
|
---|
191 | QScriptValue *);
|
---|
192 |
|
---|
193 | bool expressionFunctionValid:1;
|
---|
194 |
|
---|
195 | QString url; // This is a QString for a reason. QUrls are slooooooow...
|
---|
196 | int line;
|
---|
197 | QByteArray name; //function name, hint for the debugger
|
---|
198 | };
|
---|
199 |
|
---|
200 | QDeclarativeQtScriptExpression::DeleteWatcher::DeleteWatcher(QDeclarativeQtScriptExpression *data)
|
---|
201 | : m_wasDeletedStorage(false), m_d(data)
|
---|
202 | {
|
---|
203 | if (!m_d->deleted)
|
---|
204 | m_d->deleted = &m_wasDeletedStorage;
|
---|
205 | m_wasDeleted = m_d->deleted;
|
---|
206 | }
|
---|
207 |
|
---|
208 | QDeclarativeQtScriptExpression::DeleteWatcher::~DeleteWatcher()
|
---|
209 | {
|
---|
210 | if (false == *m_wasDeleted && m_wasDeleted == m_d->deleted)
|
---|
211 | m_d->deleted = 0;
|
---|
212 | }
|
---|
213 |
|
---|
214 | bool QDeclarativeQtScriptExpression::DeleteWatcher::wasDeleted() const
|
---|
215 | {
|
---|
216 | return *m_wasDeleted;
|
---|
217 | }
|
---|
218 |
|
---|
219 | QT_END_NAMESPACE
|
---|
220 |
|
---|
221 | #endif // QDECLARATIVEEXPRESSION_P_H
|
---|