1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
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