Improve documentation.
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlboundsignal_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQml 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 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/qbitfield_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(QObject *target, int index,
73                               QQmlContextData *ctxt, QObject *scope, const QByteArray &expression,
74                               bool isRewritten, const QString &fileName, quint16 line, quint16 column);
75     QQmlBoundSignalExpression(QObject *target, int index,
76                               QQmlContextData *ctxt, QObject *scope, const QString &expression,
77                               bool isRewritten, const QString &fileName, quint16 line, quint16 column);
78
79     // "inherited" from QQmlJavaScriptExpression.
80     static QString expressionIdentifier(QQmlJavaScriptExpression *);
81     static void expressionChanged(QQmlJavaScriptExpression *);
82
83     void setParameterCountForJS(int count) { m_parameterCountForJS = count; }
84
85     // evaluation of a bound signal expression doesn't return any value
86     void evaluate(void **a);
87
88     QString sourceFile() const { return m_fileName; }
89     quint16 lineNumber() const { return m_line; }
90     quint16 columnNumber() const { return m_column; }
91     QString expression() const;
92     QObject *target() const { return m_target; }
93
94     QQmlEngine *engine() const { return context() ? context()->engine : 0; }
95
96 private:
97     ~QQmlBoundSignalExpression();
98
99     void init(QQmlContextData *ctxt, QObject *scope);
100     bool hasParameterInfo() const { return m_parameterCountForJS > 0; }
101
102     v8::Persistent<v8::Object> m_v8qmlscope;
103     v8::Persistent<v8::Function> m_v8function;
104
105     //either expressionUtf8 or expression will be used (but not both).
106     //once m_v8function is valid, we clear both expressions, and
107     //extract it from m_v8function if needed.
108     QByteArray m_expressionUtf8;
109     QString m_expression;   //only used when expression needs to be rewritten
110     QString m_fileName;
111     quint16 m_line;
112     quint16 m_column;
113
114     int m_parameterCountForJS;
115
116     QObject *m_target;
117     int m_index;
118
119     bool m_expressionFunctionValid:1;
120     bool m_expressionFunctionRewritten:1;
121     bool m_invalidParameterName:1;
122 };
123
124 class Q_QML_PRIVATE_EXPORT QQmlAbstractBoundSignal
125 {
126 public:
127     QQmlAbstractBoundSignal();
128     virtual ~QQmlAbstractBoundSignal();
129
130     virtual int index() const = 0;
131     virtual QQmlBoundSignalExpression *expression() const = 0;
132     virtual QQmlBoundSignalExpressionPointer setExpression(QQmlBoundSignalExpression *) = 0;
133     virtual QQmlBoundSignalExpressionPointer takeExpression(QQmlBoundSignalExpression *) = 0;
134     virtual bool isEvaluating() const = 0;
135
136     void removeFromObject();
137 protected:
138     void addToObject(QObject *owner);
139
140 private:
141     friend class QQmlData;
142     friend class QQmlPropertyPrivate;
143     friend class QQmlEngineDebugService;
144     QQmlAbstractBoundSignal **m_prevSignal;
145     QQmlAbstractBoundSignal  *m_nextSignal;
146 };
147
148 class Q_QML_PRIVATE_EXPORT QQmlBoundSignal : public QQmlAbstractBoundSignal,
149                                              public QQmlNotifierEndpoint
150 {
151 public:
152     QQmlBoundSignal(QObject *target, int signal, QObject *owner, QQmlEngine *engine);
153     virtual ~QQmlBoundSignal();
154
155     int index() const;
156
157     QQmlBoundSignalExpression *expression() const;
158     QQmlBoundSignalExpressionPointer setExpression(QQmlBoundSignalExpression *);
159     QQmlBoundSignalExpressionPointer takeExpression(QQmlBoundSignalExpression *);
160
161     bool isEvaluating() const { return m_isEvaluating; }
162
163 private:
164     friend void QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void **);
165
166     QQmlBoundSignalExpressionPointer m_expression;
167     int m_index;
168     bool m_isEvaluating;
169 };
170
171 QT_END_NAMESPACE
172
173 #endif // QQMLBOUNDSIGNAL_P_H