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 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 *);
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);
114 // To save memory, we store flags inside the instruction pointer.
115 // target.flag1: destroyed
116 // instruction.flag1: enabled
117 // instruction.flag2: updating
118 QPointerValuePair<QObject, Retarget> target;
119 QFlagPointer<const QQmlInstruction::instr_assignBinding> instruction;
121 inline bool destroyedFlag() const { return target.flag(); }
122 inline void setDestroyedFlag(bool v) { return target.setFlagValue(v); }
123 inline bool enabledFlag() const { return instruction.flag(); }
124 inline void setEnabledFlag(bool v) { instruction.setFlagValue(v); }
125 inline bool updatingFlag() const { return instruction.flag2(); }
126 inline void setUpdatingFlag(bool v) { instruction.setFlag2Value(v); }
129 inline void addref();
130 inline void release();
132 QQmlAbstractBinding *binding(int index) const { return bindings + index; }
135 Q_DISABLE_COPY(QV8Bindings)
137 const QUrl &url() const;
138 const QString &urlString() const;
139 v8::Persistent<v8::Array> &functions() const;
141 QQmlCompiledData::V8Program *program;
146 void QV8Bindings::addref()
151 void QV8Bindings::release()
161 #endif // QV8BINDINGS_P_H