1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQMLBINDING_P_H
43 #define QQMLBINDING_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.
57 #include "qqmlpropertyvaluesource.h"
58 #include "qqmlexpression.h"
59 #include "qqmlproperty.h"
60 #include "qqmlscriptstring.h"
61 #include "qqmlproperty_p.h"
63 #include <QtCore/QObject>
64 #include <QtCore/QMetaProperty>
66 #include <private/qpointervaluepair_p.h>
67 #include <private/qqmlabstractbinding_p.h>
68 #include <private/qqmlabstractexpression_p.h>
69 #include <private/qqmljavascriptexpression_p.h>
74 class Q_QML_PRIVATE_EXPORT QQmlBinding : public QQmlJavaScriptExpression,
75 public QQmlAbstractExpression,
76 public QQmlAbstractBinding
79 enum EvaluateFlag { None = 0x00, RequiresThisObject = 0x01 };
80 Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
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);
90 void setTarget(const QQmlProperty &);
91 void setTarget(QObject *, const QQmlPropertyData &, QQmlContextData *);
92 QQmlProperty property() const;
94 void setEvaluateFlags(EvaluateFlags flags);
95 EvaluateFlags evaluateFlags() const;
97 void setNotifyOnValueChanged(bool);
99 // Inherited from QQmlAbstractExpression
100 virtual void refresh();
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);
110 void setEnabled(bool, QQmlPropertyPrivate::WriteFlags flags);
111 void update(QQmlPropertyPrivate::WriteFlags flags);
112 void update() { update(QQmlPropertyPrivate::DontRemoveBinding); }
114 QString expression() const;
115 QObject *object() const;
116 int propertyIndex() const;
117 void retargetBinding(QObject *, int);
119 typedef int Identifier;
120 static Identifier Invalid;
122 static QQmlBinding *createBinding(Identifier, QObject *, QQmlContext *, const QString &, quint16);
126 static QString expressionIdentifier(QQmlJavaScriptExpression *);
127 static void expressionChanged(QQmlJavaScriptExpression *);
130 friend class QQmlAbstractBinding;
134 v8::Persistent<v8::Function> v8function;
136 inline bool updatingFlag() const;
137 inline void setUpdatingFlag(bool);
138 inline bool enabledFlag() const;
139 inline void setEnabledFlag(bool);
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;
153 // XXX It would be good if we could get rid of these in most circumstances
155 quint16 m_lineNumber;
156 quint16 m_columnNumber;
157 QByteArray m_expression;
160 bool QQmlBinding::updatingFlag() const
162 return m_ctxt.flag();
165 void QQmlBinding::setUpdatingFlag(bool v)
167 m_ctxt.setFlagValue(v);
170 bool QQmlBinding::enabledFlag() const
172 return m_ctxt.flag2();
175 void QQmlBinding::setEnabledFlag(bool v)
177 m_ctxt.setFlag2Value(v);
180 Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlBinding::EvaluateFlags)
184 Q_DECLARE_METATYPE(QQmlBinding*)
186 #endif // QQMLBINDING_P_H