Add missing QT_{BEGIN,END}_NAMESPACE
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlbinding_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 QQMLBINDING_P_H
43 #define QQMLBINDING_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 "qqml.h"
57 #include "qqmlpropertyvaluesource.h"
58 #include "qqmlexpression.h"
59 #include "qqmlproperty.h"
60 #include "qqmlscriptstring.h"
61 #include "qqmlproperty_p.h"
62
63 #include <QtCore/QObject>
64 #include <QtCore/QMetaProperty>
65
66 #include <private/qpointervaluepair_p.h>
67 #include <private/qqmlabstractbinding_p.h>
68 #include <private/qqmlabstractexpression_p.h>
69 #include <private/qqmljavascriptexpression_p.h>
70
71 QT_BEGIN_NAMESPACE
72
73 class QQmlContext;
74 class Q_QML_PRIVATE_EXPORT QQmlBinding : public QQmlJavaScriptExpression,
75                                          public QQmlAbstractExpression,
76                                          public QQmlAbstractBinding
77 {
78 public:
79     enum EvaluateFlag { None = 0x00, RequiresThisObject = 0x01 };
80     Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
81
82     QQmlBinding(const QString &, QObject *, QQmlContext *);
83     QQmlBinding(const QQmlScriptString &, QObject *, QQmlContext *);
84     QQmlBinding(const QString &, QObject *, QQmlContextData *);
85     QQmlBinding(const QString &, bool isRewritten, QObject *, QQmlContextData *, 
86                 const QString &url, quint16 lineNumber, quint16 columnNumber);
87     QQmlBinding(void *, QObject *, QQmlContextData *,
88                 const QString &url, quint16 lineNumber, quint16 columnNumber);
89
90     void setTarget(const QQmlProperty &);
91     void setTarget(QObject *, const QQmlPropertyData &, QQmlContextData *);
92     QQmlProperty property() const;
93
94     void setEvaluateFlags(EvaluateFlags flags);
95     EvaluateFlags evaluateFlags() const;
96
97     void setNotifyOnValueChanged(bool);
98
99     // Inherited from  QQmlAbstractExpression
100     virtual void refresh();
101
102     // "Inherited" from  QQmlAbstractBinding
103     static QString expression(const QQmlAbstractBinding *);
104     static int propertyIndex(const QQmlAbstractBinding *);
105     static QObject *object(const QQmlAbstractBinding *);
106     static void setEnabled(QQmlAbstractBinding *, bool, QQmlPropertyPrivate::WriteFlags);
107     static void update(QQmlAbstractBinding *, QQmlPropertyPrivate::WriteFlags);
108     static void retargetBinding(QQmlAbstractBinding *, QObject *, int);
109
110     void setEnabled(bool, QQmlPropertyPrivate::WriteFlags flags);
111     void update(QQmlPropertyPrivate::WriteFlags flags);
112     void update() { update(QQmlPropertyPrivate::DontRemoveBinding); }
113
114     QString expression() const;
115     QObject *object() const;
116     int propertyIndex() const;
117     void retargetBinding(QObject *, int);
118
119     typedef int Identifier;
120     static Identifier Invalid;
121
122     static QQmlBinding *createBinding(Identifier, QObject *, QQmlContext *, const QString &, quint16);
123
124     QVariant evaluate();
125
126     static QString expressionIdentifier(QQmlJavaScriptExpression *);
127     static void expressionChanged(QQmlJavaScriptExpression *);
128
129 protected:
130     friend class QQmlAbstractBinding;
131     ~QQmlBinding();
132
133 private:
134     v8::Persistent<v8::Function> v8function;
135
136     inline bool updatingFlag() const;
137     inline void setUpdatingFlag(bool);
138     inline bool enabledFlag() const;
139     inline void setEnabledFlag(bool);
140
141     struct Retarget {
142         QObject *target;
143         int targetProperty;
144     };
145
146     QPointerValuePair<QObject, Retarget> m_coreObject;
147     QQmlPropertyData m_core;
148     // We store some flag bits in the following flag pointers.
149     //    m_ctxt:flag1 - updatingFlag
150     //    m_ctxt:flag2 - enabledFlag
151     QFlagPointer<QQmlContextData> m_ctxt;
152
153     // XXX It would be good if we could get rid of these in most circumstances
154     QString m_url;
155     quint16 m_lineNumber;
156     quint16 m_columnNumber;
157     QByteArray m_expression;
158 };
159
160 bool QQmlBinding::updatingFlag() const
161 {
162     return m_ctxt.flag();
163 }
164
165 void QQmlBinding::setUpdatingFlag(bool v)
166 {
167     m_ctxt.setFlagValue(v);
168 }
169
170 bool QQmlBinding::enabledFlag() const
171 {
172     return m_ctxt.flag2();
173 }
174
175 void QQmlBinding::setEnabledFlag(bool v)
176 {
177     m_ctxt.setFlag2Value(v);
178 }
179
180 Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlBinding::EvaluateFlags)
181
182 QT_END_NAMESPACE
183
184 Q_DECLARE_METATYPE(QQmlBinding*)
185
186 #endif // QQMLBINDING_P_H