Add missing QT_{BEGIN,END}_NAMESPACE
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlboundsignal_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQMLBOUNDSIGNAL_P_H
43 #define QQMLBOUNDSIGNAL_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 <QtCore/qmetaobject.h>
57
58 #include <private/qqmlabstractexpression_p.h>
59 #include <private/qqmljavascriptexpression_p.h>
60 #include <private/qqmlboundsignalexpressionpointer_p.h>
61 #include <private/qqmlnotifier_p.h>
62 #include <private/qflagpointer_p.h>
63 #include <private/qqmlrefcount_p.h>
64 #include <private/qqmlglobal_p.h>
65 #include <private/qobject_p.h>
66
67 QT_BEGIN_NAMESPACE
68
69 class Q_QML_PRIVATE_EXPORT QQmlBoundSignalExpression : public QQmlAbstractExpression, public QQmlJavaScriptExpression, public QQmlRefCount
70 {
71 public:
72     QQmlBoundSignalExpression(QQmlContextData *ctxt, QObject *scope, const QByteArray &expression,
73                               bool isRewritten, const QString &fileName, quint16 line, quint16 column);
74     QQmlBoundSignalExpression(QQmlContextData *ctxt, QObject *scope, const QString &expression,
75                               bool isRewritten, const QString &fileName, quint16 line, quint16 column);
76
77     // "inherited" from QQmlJavaScriptExpression.
78     static QString expressionIdentifier(QQmlJavaScriptExpression *);
79     static void expressionChanged(QQmlJavaScriptExpression *);
80
81     // evaluation of a bound signal expression doesn't return any value
82     void evaluate(QObject *secondaryScope = 0);
83
84     QString sourceFile() const { return m_fileName; }
85     quint16 lineNumber() const { return m_line; }
86     quint16 columnNumber() const { return m_column; }
87     QString expression() const;
88
89     QQmlEngine *engine() const { return context() ? context()->engine : 0; }
90
91 private:
92     ~QQmlBoundSignalExpression();
93
94     v8::Persistent<v8::Object> m_v8qmlscope;
95     v8::Persistent<v8::Function> m_v8function;
96
97     //either expressionUtf8 or expression will be used (but not both).
98     //once m_v8function is valid, we clear both expressions, and
99     //extract it from m_v8function if needed.
100     QByteArray m_expressionUtf8;
101     QString m_expression;   //only used when expression needs to be rewritten
102
103     QString m_fileName;
104     quint16 m_line;
105     quint16 m_column;
106
107     bool m_expressionFunctionValid:1;
108     bool m_expressionFunctionRewritten:1;
109 };
110
111 class Q_QML_PRIVATE_EXPORT QQmlAbstractBoundSignal
112 {
113 public:
114     QQmlAbstractBoundSignal();
115     virtual ~QQmlAbstractBoundSignal();
116
117     virtual int index() const = 0;
118     virtual QQmlBoundSignalExpression *expression() const = 0;
119     virtual QQmlBoundSignalExpressionPointer setExpression(QQmlBoundSignalExpression *) = 0;
120     virtual QQmlBoundSignalExpressionPointer takeExpression(QQmlBoundSignalExpression *) = 0;
121     virtual QObject *scope() = 0;
122     virtual bool isEvaluating() const = 0;
123
124     void removeFromObject();
125 protected:
126     void addToObject(QObject *owner);
127
128 private:
129     friend class QQmlData;
130     friend class QQmlPropertyPrivate;
131     friend class QQmlEngineDebugService;
132     QQmlAbstractBoundSignal **m_prevSignal;
133     QQmlAbstractBoundSignal  *m_nextSignal;
134 };
135
136 class QQmlBoundSignalParameters;
137 class Q_QML_PRIVATE_EXPORT QQmlBoundSignal : public QQmlAbstractBoundSignal,
138                                              public QQmlNotifierEndpoint
139 {
140 public:
141     QQmlBoundSignal(QObject *scope, int signal, QObject *owner, QQmlEngine *engine);
142     virtual ~QQmlBoundSignal();
143
144     int index() const;
145
146     QQmlBoundSignalExpression *expression() const;
147     QQmlBoundSignalExpressionPointer setExpression(QQmlBoundSignalExpression *);
148     QQmlBoundSignalExpressionPointer takeExpression(QQmlBoundSignalExpression *);
149     QObject *scope() { return *m_scope; }
150
151     bool isEvaluating() const { return m_scope.flag(); }
152
153 private:
154     friend void QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void **);
155
156     QQmlBoundSignalExpressionPointer m_expression;
157     QQmlBoundSignalParameters *m_params;
158     // We store some flag bits in the following flag pointer.
159     //    m_scope:flag1 - m_isEvaluating
160     //    m_scope:flag2 - m_paramsValid
161     QFlagPointer<QObject> m_scope;
162     int m_index;
163
164     void setIsEvaluating(bool v) { m_scope.setFlagValue(v); }
165     void setParamsValid(bool v) { m_scope.setFlag2Value(v); }
166     bool paramsValid() const { return m_scope.flag2(); }
167 };
168
169
170 QT_END_NAMESPACE
171
172 #endif // QQMLBOUNDSIGNAL_P_H