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 QV8BINDINGS_P_H
43 #define QV8BINDINGS_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.
56 #include <private/qpointervaluepair_p.h>
57 #include <private/qqmlpropertycache_p.h>
58 #include <private/qqmlinstruction_p.h>
59 #include <private/qqmlexpression_p.h>
60 #include <private/qqmlcompiler_p.h>
61 #include <private/qflagpointer_p.h>
62 #include <private/qqmlbinding_p.h>
68 class QQmlCompiledData;
70 class QV8BindingsPrivate;
71 class QV8Bindings : public QQmlAbstractExpression
74 QV8Bindings(QQmlCompiledData::V8Program *,
76 QQmlContextData *context);
77 virtual ~QV8Bindings();
79 QQmlAbstractBinding *configBinding(QObject *target, QObject *scope,
80 const QQmlInstruction::instr_assignBinding *);
82 // Inherited from QQmlAbstractExpression
83 virtual void refresh();
85 struct Binding : public QQmlJavaScriptExpression,
86 public QQmlAbstractBinding {
89 void update() { QQmlAbstractBinding::update(); }
92 // "Inherited" from QQmlJavaScriptExpression
93 static QString expressionIdentifier(QQmlJavaScriptExpression *);
94 static void expressionChanged(QQmlJavaScriptExpression *);
96 // "Inherited" from QQmlAbstractBinding
97 static void destroy(QQmlAbstractBinding *, QQmlAbstractBinding::DestroyMode mode);
98 static int propertyIndex(const QQmlAbstractBinding *);
99 static QObject *object(const QQmlAbstractBinding *);
100 static void setEnabled(QQmlAbstractBinding *, bool, QQmlPropertyPrivate::WriteFlags);
101 static void update(QQmlAbstractBinding *, QQmlPropertyPrivate::WriteFlags);
102 static void retargetBinding(QQmlAbstractBinding *, QObject *, int);
104 QObject *object() const;
105 void update(QQmlPropertyPrivate::WriteFlags flags);
116 // To save memory, we store flags inside the instruction pointer.
117 // target.flag1: destroyed
118 // instruction.flag1: enabled
119 // instruction.flag2: updating
120 QPointerValuePair<QObject, Retarget> target;
121 QFlagPointer<const QQmlInstruction::instr_assignBinding> instruction;
123 inline bool destroyedFlag() const { return target.flag(); }
124 inline void setDestroyedFlag(bool v) { return target.setFlagValue(v); }
125 inline bool enabledFlag() const { return instruction.flag(); }
126 inline void setEnabledFlag(bool v) { instruction.setFlagValue(v); }
127 inline bool updatingFlag() const { return instruction.flag2(); }
128 inline void setUpdatingFlag(bool v) { instruction.setFlag2Value(v); }
131 inline void addref();
132 inline void release();
134 QQmlAbstractBinding *binding(int index) const { return bindings + index; }
137 Q_DISABLE_COPY(QV8Bindings)
139 const QUrl &url() const;
140 const QString &urlString() const;
141 v8::Persistent<v8::Array> &functions() const;
143 QQmlCompiledData::V8Program *program;
148 void QV8Bindings::addref()
153 void QV8Bindings::release()
163 #endif // QV8BINDINGS_P_H