8ceccbb731c9315a2ffdbfa5d50c8df539d3f5c5
[profile/ivi/qtdeclarative.git] / src / qml / qml / v4 / qv4bindings_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QV4BINDINGS_P_H
43 #define QV4BINDINGS_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include "private/qqmlexpression_p.h"
57 #include "private/qqmlbinding_p.h"
58 #include "private/qv4instruction_p.h"
59 #include "private/qpointervaluepair_p.h"
60
61 QT_BEGIN_HEADER
62
63 QT_BEGIN_NAMESPACE
64
65 struct QV4Program;
66 class QV4Bindings : public QQmlAbstractExpression, 
67                                public QQmlRefCount
68 {
69     Q_DECLARE_TR_FUNCTIONS(QV4Bindings)
70 public:
71     QV4Bindings(const char *program, QQmlContextData *context,
72                            QQmlRefCount *);
73     virtual ~QV4Bindings();
74
75     QQmlAbstractBinding *configBinding(int index, QObject *target, 
76                                                QObject *scope, int property,
77                                                int line, int column);
78
79 #ifdef QML_THREADED_INTERPRETER
80     static void **getDecodeInstrTable();
81 #endif
82
83 private:
84     Q_DISABLE_COPY(QV4Bindings)
85
86     struct Binding : public QQmlAbstractBinding, public QQmlDelayedError {
87         Binding() : enabled(false), updating(0), property(0),
88                     scope(0), target(0), executedBlocks(0), parent(0) {}
89
90         // Inherited from QQmlAbstractBinding
91         virtual void setEnabled(bool, QQmlPropertyPrivate::WriteFlags flags);
92         virtual void update(QQmlPropertyPrivate::WriteFlags flags);
93         virtual void destroy();
94         virtual int propertyIndex() const;
95         virtual void retargetBinding(QObject *, int);
96         virtual QObject *object() const;
97
98         struct Retarget {
99             QObject *target;
100             int targetProperty;
101         };
102
103         int index:30;
104         bool enabled:1;
105         bool updating:1;
106         // Encoding of property is coreIndex | (propType << 16) | (valueTypeIndex << 24)
107         // propType and valueTypeIndex are only set if the property is a value type property
108         int property;
109         QObject *scope;
110         int line;
111         int column;
112         QPointerValuePair<QObject, Retarget> target;
113         quint32 executedBlocks;
114
115         QV4Bindings *parent;
116     };
117
118     class Subscription : public QQmlNotifierEndpoint
119     {
120     public:
121         Subscription() : bindings(0), method(-1) { callback = &subscriptionCallback; }
122         static void subscriptionCallback(QQmlNotifierEndpoint *e, void**);
123         QV4Bindings *bindings;
124         int method;
125     };
126     friend class Subscription;
127
128     Subscription *subscriptions;
129
130     void subscriptionNotify(int);
131     void run(Binding *, QQmlPropertyPrivate::WriteFlags flags);
132
133     QV4Program *program;
134     QQmlRefCount *dataRef;
135     Binding *bindings;
136
137     void init();
138     void run(int instr, quint32 &executedBlocks, QQmlContextData *context,
139              QQmlDelayedError *error, QObject *scope, QObject *output, 
140              QQmlPropertyPrivate::WriteFlags storeFlags
141 #ifdef QML_THREADED_INTERPRETER
142              , void ***decode_instr = 0
143 #endif
144              );
145
146
147     inline void unsubscribe(int subIndex);
148     inline void subscribeId(QQmlContextData *p, int idIndex, int subIndex);
149     inline void subscribe(QObject *o, int notifyIndex, int subIndex);
150
151     inline static qint32 toInt32(double n);
152     static const double D32;
153     static quint32 toUint32(double n);
154
155 };
156
157 QT_END_NAMESPACE
158
159 QT_END_HEADER
160
161 #endif // QV4BINDINGS_P_H
162