Add missing QT_{BEGIN,END}_NAMESPACE
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlvaluetypeproxybinding.cpp
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 #include "qqmlvaluetypeproxybinding_p.h"
43
44 QT_BEGIN_NAMESPACE
45
46 // Used in qqmlabstractbinding.cpp
47 QQmlAbstractBinding::VTable QQmlValueTypeProxyBinding_vtable = {
48     QQmlAbstractBinding::default_destroy<QQmlValueTypeProxyBinding>,
49     QQmlAbstractBinding::default_expression,
50     QQmlValueTypeProxyBinding::propertyIndex,
51     QQmlValueTypeProxyBinding::object,
52     QQmlValueTypeProxyBinding::setEnabled,
53     QQmlValueTypeProxyBinding::update,
54     QQmlAbstractBinding::default_retargetBinding
55 };
56
57 QQmlValueTypeProxyBinding::QQmlValueTypeProxyBinding(QObject *o, int index)
58 : QQmlAbstractBinding(ValueTypeProxy), m_object(o), m_index(index), m_bindings(0)
59 {
60 }
61
62 QQmlValueTypeProxyBinding::~QQmlValueTypeProxyBinding()
63 {
64     QQmlAbstractBinding *binding = m_bindings;
65     // This must be identical to the logic in QQmlData::destroyed()
66     while (binding) {
67         QQmlAbstractBinding *next = binding->nextBinding();
68         binding->setAddedToObject(false);
69         binding->setNextBinding(0);
70         binding->destroy();
71         binding = next;
72     }
73 }
74
75 void QQmlValueTypeProxyBinding::setEnabled(QQmlAbstractBinding *_This,
76                                            bool e, QQmlPropertyPrivate::WriteFlags flags)
77 {
78     QQmlValueTypeProxyBinding *This = static_cast<QQmlValueTypeProxyBinding *>(_This);
79
80     if (e) {
81         QQmlAbstractBinding *bindings = This->m_bindings;
82         This->recursiveEnable(bindings, flags);
83     } else {
84         QQmlAbstractBinding *bindings = This->m_bindings;
85         This->recursiveDisable(bindings);
86     }
87 }
88
89 void QQmlValueTypeProxyBinding::recursiveEnable(QQmlAbstractBinding *b, QQmlPropertyPrivate::WriteFlags flags)
90 {
91     if (!b)
92         return;
93
94     recursiveEnable(b->nextBinding(), flags);
95
96     if (b)
97         b->setEnabled(true, flags);
98 }
99
100 void QQmlValueTypeProxyBinding::recursiveDisable(QQmlAbstractBinding *b)
101 {
102     if (!b)
103         return;
104
105     recursiveDisable(b->nextBinding());
106
107     if (b)
108         b->setEnabled(false, 0);
109 }
110
111 void QQmlValueTypeProxyBinding::update(QQmlAbstractBinding *, QQmlPropertyPrivate::WriteFlags)
112 {
113 }
114
115 QQmlAbstractBinding *QQmlValueTypeProxyBinding::binding(int propertyIndex)
116 {
117     QQmlAbstractBinding *binding = m_bindings;
118
119     while (binding && binding->propertyIndex() != propertyIndex)
120         binding = binding->nextBinding();
121
122     return binding;
123 }
124
125 /*!
126 Removes a collection of bindings, corresponding to the set bits in \a mask.
127 */
128 void QQmlValueTypeProxyBinding::removeBindings(quint32 mask)
129 {
130     QQmlAbstractBinding *binding = m_bindings;
131     QQmlAbstractBinding *lastBinding = 0;
132
133     while (binding) {
134         if (mask & (1 << (binding->propertyIndex() >> 16))) {
135             QQmlAbstractBinding *remove = binding;
136             binding = remove->nextBinding();
137
138             if (lastBinding == 0)
139                 m_bindings = remove->nextBinding();
140             else
141                 lastBinding->setNextBinding(remove->nextBinding());
142
143             remove->setAddedToObject(false);
144             remove->setNextBinding(0);
145             remove->destroy();
146         } else {
147             lastBinding = binding;
148             binding = binding->nextBinding();
149         }
150     }
151 }
152
153 int QQmlValueTypeProxyBinding::propertyIndex(const QQmlAbstractBinding *This)
154 {
155     return static_cast<const QQmlValueTypeProxyBinding *>(This)->m_index;
156 }
157
158 QObject *QQmlValueTypeProxyBinding::object(const QQmlAbstractBinding *This)
159 {
160     return static_cast<const QQmlValueTypeProxyBinding *>(This)->m_object;
161 }
162
163 int QQmlValueTypeProxyBinding::propertyIndex() const
164 {
165     return m_index;
166 }
167
168 QObject *QQmlValueTypeProxyBinding::object() const
169 {
170     return m_object;
171 }
172
173 QT_END_NAMESPACE