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