Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativedata_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 QtDeclarative 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 QDECLARATIVEDATA_P_H
43 #define QDECLARATIVEDATA_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/qobject_p.h>
57
58 #include <private/qv8_p.h>
59
60 QT_BEGIN_NAMESPACE
61
62 template <class Key, class T> class QHash;
63 class QDeclarativeGuardImpl;
64 class QDeclarativeCompiledData;
65 class QDeclarativeAbstractBinding;
66 class QDeclarativeContext;
67 class QDeclarativePropertyCache;
68 class QDeclarativeContextData;
69 class QDeclarativeNotifier;
70 class QDeclarativeDataExtended;
71 class QDeclarativeNotifierEndpoint;
72 // This class is structured in such a way, that simply zero'ing it is the
73 // default state for elemental object allocations.  This is crucial in the
74 // workings of the QDeclarativeInstruction::CreateSimpleObject instruction.
75 // Don't change anything here without first considering that case!
76 class Q_DECLARATIVE_EXPORT QDeclarativeData : public QAbstractDeclarativeData
77 {
78 public:
79     QDeclarativeData()
80         : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), 
81           hasTaintedV8Object(false), notifyList(0), context(0), outerContext(0), bindings(0), 
82           nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0), 
83           lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), v8objectid(0), 
84           propertyCache(0), guards(0), extendedData(0) {
85           init(); 
86     }
87
88     static inline void init() {
89         QAbstractDeclarativeData::destroyed = destroyed;
90         QAbstractDeclarativeData::parentChanged = parentChanged;
91         QAbstractDeclarativeData::objectNameChanged = objectNameChanged;
92         QAbstractDeclarativeData::signalEmitted = signalEmitted;
93     }
94
95     static void destroyed(QAbstractDeclarativeData *, QObject *);
96     static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
97     static void objectNameChanged(QAbstractDeclarativeData *, QObject *);
98     static void signalEmitted(QAbstractDeclarativeData *, QObject *, int, void **);
99
100     void destroyed(QObject *);
101     void parentChanged(QObject *, QObject *);
102     void objectNameChanged(QObject *);
103
104     void setImplicitDestructible() {
105         if (!explicitIndestructibleSet) indestructible = false;
106     }
107
108     quint32 ownMemory:1;
109     quint32 ownContext:1;
110     quint32 indestructible:1;
111     quint32 explicitIndestructibleSet:1;
112     quint32 hasTaintedV8Object:1;
113     quint32 dummy:27;
114
115     struct NotifyList {
116         quint64 connectionMask;
117
118         quint16 maximumTodoIndex;
119         quint16 notifiesSize;
120
121         QDeclarativeNotifierEndpoint *todo;
122         QDeclarativeNotifierEndpoint**notifies;
123         void layout();
124     private:
125         void layout(QDeclarativeNotifierEndpoint*);
126     };
127     NotifyList *notifyList;
128     
129     inline QDeclarativeNotifierEndpoint *notify(int index);
130     void addNotify(int index, QDeclarativeNotifierEndpoint *);
131
132     // The context that created the C++ object
133     QDeclarativeContextData *context; 
134     // The outermost context in which this object lives
135     QDeclarativeContextData *outerContext;
136
137     QDeclarativeAbstractBinding *bindings;
138
139     // Linked list for QDeclarativeContext::contextObjects
140     QDeclarativeData *nextContextObject;
141     QDeclarativeData**prevContextObject;
142
143     int bindingBitsSize;
144     quint32 *bindingBits; 
145     bool hasBindingBit(int) const;
146     void clearBindingBit(int);
147     void setBindingBit(QObject *obj, int);
148
149     ushort lineNumber;
150     ushort columnNumber;
151
152     QDeclarativeCompiledData *deferredComponent; // Can't this be found from the context?
153     unsigned int deferredIdx;
154
155     quint32 v8objectid;
156     v8::Persistent<v8::Object> v8object;
157
158     QDeclarativePropertyCache *propertyCache;
159
160     QDeclarativeGuardImpl *guards;
161
162     static QDeclarativeData *get(const QObject *object, bool create = false) {
163         QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
164         if (priv->wasDeleted) {
165             Q_ASSERT(!create);
166             return 0;
167         } else if (priv->declarativeData) {
168             return static_cast<QDeclarativeData *>(priv->declarativeData);
169         } else if (create) {
170             priv->declarativeData = new QDeclarativeData;
171             return static_cast<QDeclarativeData *>(priv->declarativeData);
172         } else {
173             return 0;
174         }
175     }
176
177     bool hasExtendedData() const { return extendedData != 0; }
178     QDeclarativeNotifier *objectNameNotifier() const;
179     QHash<int, QObject *> *attachedProperties() const;
180
181 private:
182     // For objectNameNotifier and attachedProperties
183     mutable QDeclarativeDataExtended *extendedData;
184 };
185
186 QDeclarativeNotifierEndpoint *QDeclarativeData::notify(int index)
187 {
188     Q_ASSERT(index <= 0xFFFF);
189
190     if (!notifyList || !(notifyList->connectionMask & (1ULL << quint64(index % 64)))) {
191         return 0;
192     } else if (index < notifyList->notifiesSize) {
193         return notifyList->notifies[index];
194     } else if (index <= notifyList->maximumTodoIndex) {
195         notifyList->layout();
196     }
197
198     if (index < notifyList->notifiesSize) {
199         return notifyList->notifies[index];
200     } else {
201         return 0;
202     }
203 }
204
205 QT_END_NAMESPACE
206
207 #endif // QDECLARATIVEDATA_P_H