1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEEXPRESSION_P_H
43 #define QDECLARATIVEEXPRESSION_P_H
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.
56 #include "qdeclarativeexpression.h"
58 #include "private/qdeclarativeengine_p.h"
59 #include "private/qdeclarativeguard_p.h"
61 #include <QtScript/qscriptvalue.h>
65 class QDeclarativeAbstractExpression
68 QDeclarativeAbstractExpression();
69 virtual ~QDeclarativeAbstractExpression();
73 QDeclarativeContextData *context() const;
74 void setContext(QDeclarativeContextData *);
76 virtual void refresh();
79 friend class QDeclarativeContext;
80 friend class QDeclarativeContextData;
81 friend class QDeclarativeContextPrivate;
82 QDeclarativeContextData *m_context;
83 QDeclarativeAbstractExpression **m_prevExpression;
84 QDeclarativeAbstractExpression *m_nextExpression;
87 class QDeclarativeDelayedError
90 inline QDeclarativeDelayedError() : nextError(0), prevError(0) {}
91 inline ~QDeclarativeDelayedError() { removeError(); }
93 QDeclarativeError error;
95 bool addError(QDeclarativeEnginePrivate *);
97 inline void removeError() {
98 if (!prevError) return;
99 if (nextError) nextError->prevError = prevError;
100 *prevError = nextError;
106 QDeclarativeDelayedError *nextError;
107 QDeclarativeDelayedError **prevError;
110 class QDeclarativeQtScriptExpression : public QDeclarativeAbstractExpression,
111 public QDeclarativeDelayedError
114 enum Mode { SharedContext, ExplicitContext };
116 enum EvaluateFlag { RequiresThisObject = 0x01 };
117 Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
119 QDeclarativeQtScriptExpression();
120 virtual ~QDeclarativeQtScriptExpression();
122 QDeclarativeRefCount *dataRef;
126 Mode expressionFunctionMode;
127 QScriptValue expressionFunction;
129 QScriptValue expressionContext; // Only used in ExplicitContext
130 QObject *scopeObject; // Only used in SharedContext
132 bool notifyOnValueChange() const;
133 void setNotifyOnValueChange(bool);
134 void resetNotifyOnChange();
135 void setNotifyObject(QObject *, int );
137 void setEvaluateFlags(EvaluateFlags flags);
138 EvaluateFlags evaluateFlags() const;
140 QScriptValue scriptValue(QObject *secondaryScope, bool *isUndefined);
142 class DeleteWatcher {
144 inline DeleteWatcher(QDeclarativeQtScriptExpression *data);
145 inline ~DeleteWatcher();
146 inline bool wasDeleted() const;
149 bool m_wasDeletedStorage;
150 QDeclarativeQtScriptExpression *m_d;
155 QScriptValue eval(QObject *secondaryScope, bool *isUndefined);
156 void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties);
160 QDeclarativeNotifierEndpoint *guardList;
163 QObject *guardObject;
164 int guardObjectNotifyIndex;
167 EvaluateFlags evalFlags;
170 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeQtScriptExpression::EvaluateFlags)
173 class QDeclarativeExpression;
175 class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeQtScriptExpression
177 Q_DECLARE_PUBLIC(QDeclarativeExpression)
179 QDeclarativeExpressionPrivate();
180 ~QDeclarativeExpressionPrivate();
182 void init(QDeclarativeContextData *, const QString &, QObject *);
183 void init(QDeclarativeContextData *, const QScriptValue &, QObject *);
184 void init(QDeclarativeContextData *, void *, QDeclarativeRefCount *, QObject *, const QString &, int);
186 QVariant value(QObject *secondaryScope = 0, bool *isUndefined = 0);
187 QScriptValue scriptValue(QObject *secondaryScope = 0, bool *isUndefined = 0);
189 static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) {
190 return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr));
192 static QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr) {
193 return expr->q_func();
197 virtual void emitValueChanged();
199 static void exceptionToError(QScriptEngine *, QDeclarativeError &);
200 static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &,
201 int, QScriptValue *);
202 static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QScriptProgram &,
205 bool expressionFunctionValid:1;
207 QString url; // This is a QString for a reason. QUrls are slooooooow...
209 QByteArray name; //function name, hint for the debugger
212 QDeclarativeQtScriptExpression::DeleteWatcher::DeleteWatcher(QDeclarativeQtScriptExpression *data)
213 : m_wasDeletedStorage(false), m_d(data)
216 m_d->deleted = &m_wasDeletedStorage;
217 m_wasDeleted = m_d->deleted;
220 QDeclarativeQtScriptExpression::DeleteWatcher::~DeleteWatcher()
222 if (false == *m_wasDeleted && m_wasDeleted == m_d->deleted)
226 bool QDeclarativeQtScriptExpression::DeleteWatcher::wasDeleted() const
228 return *m_wasDeleted;
233 #endif // QDECLARATIVEEXPRESSION_P_H