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 "qqmlproperty_p.h"
62 #include <QtCore/QObject>
63 #include <QtCore/QMetaProperty>
65 #include <private/qpointervaluepair_p.h>
66 #include <private/qqmlabstractbinding_p.h>
67 #include <private/qqmlabstractexpression_p.h>
68 #include <private/qqmljavascriptexpression_p.h>
73 class Q_QML_PRIVATE_EXPORT QQmlBinding : public QQmlJavaScriptExpression,
74 public QQmlAbstractExpression,
75 public QQmlAbstractBinding
78 enum EvaluateFlag { None = 0x00, RequiresThisObject = 0x01 };
79 Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag)
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);
88 void setTarget(const QQmlProperty &);
89 void setTarget(QObject *, const QQmlPropertyData &, QQmlContextData *);
90 QQmlProperty property() const;
92 void setEvaluateFlags(EvaluateFlags flags);
93 EvaluateFlags evaluateFlags() const;
95 void setNotifyOnValueChanged(bool);
97 // Inherited from QQmlAbstractExpression
98 virtual void refresh();
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);
108 void setEnabled(bool, QQmlPropertyPrivate::WriteFlags flags);
109 void update(QQmlPropertyPrivate::WriteFlags flags);
110 void update() { update(QQmlPropertyPrivate::DontRemoveBinding); }
112 QString expression() const;
113 QObject *object() const;
114 int propertyIndex() const;
115 void retargetBinding(QObject *, int);
117 typedef int Identifier;
118 static Identifier Invalid;
120 static QQmlBinding *createBinding(Identifier, QObject *, QQmlContext *, const QString &, int);
124 static QString expressionIdentifier(QQmlJavaScriptExpression *);
125 static void expressionChanged(QQmlJavaScriptExpression *);
128 friend class QQmlAbstractBinding;
132 v8::Persistent<v8::Function> v8function;
134 inline bool updatingFlag() const;
135 inline void setUpdatingFlag(bool);
136 inline bool enabledFlag() const;
137 inline void setEnabledFlag(bool);
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;
151 // XXX It would be good if we could get rid of these in most circumstances
155 QByteArray m_expression;
158 bool QQmlBinding::updatingFlag() const
160 return m_ctxt.flag();
163 void QQmlBinding::setUpdatingFlag(bool v)
165 m_ctxt.setFlagValue(v);
168 bool QQmlBinding::enabledFlag() const
170 return m_ctxt.flag2();
173 void QQmlBinding::setEnabledFlag(bool v)
175 m_ctxt.setFlag2Value(v);
178 Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlBinding::EvaluateFlags)
182 Q_DECLARE_METATYPE(QQmlBinding*)
184 #endif // QQMLBINDING_P_H