1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVESTATE_P_H
43 #define QDECLARATIVESTATE_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 "qdeclarativestate_p.h"
58 #include "qdeclarativetransitionmanager_p_p.h"
60 #include <private/qdeclarativeproperty_p.h>
61 #include <private/qdeclarativeguard_p.h>
63 #include <private/qdeclarativebinding_p.h>
65 #include <private/qobject_p.h>
69 class QDeclarativeSimpleAction
72 enum State { StartState, EndState };
73 QDeclarativeSimpleAction(const QDeclarativeAction &a, State state = StartState)
75 m_property = a.property;
76 m_specifiedObject = a.specifiedObject;
77 m_specifiedProperty = a.specifiedProperty;
79 if (state == StartState) {
80 m_value = a.fromValue;
81 if (QDeclarativePropertyPrivate::binding(m_property)) {
82 m_binding = QDeclarativeAbstractBinding::getPointer(QDeclarativePropertyPrivate::binding(m_property));
84 m_reverseEvent = true;
87 m_binding = a.toBinding;
88 m_reverseEvent = false;
92 ~QDeclarativeSimpleAction()
96 QDeclarativeSimpleAction(const QDeclarativeSimpleAction &other)
97 : m_property(other.m_property),
98 m_value(other.m_value),
99 m_binding(QDeclarativeAbstractBinding::getPointer(other.binding())),
100 m_specifiedObject(other.m_specifiedObject),
101 m_specifiedProperty(other.m_specifiedProperty),
102 m_event(other.m_event),
103 m_reverseEvent(other.m_reverseEvent)
107 QDeclarativeSimpleAction &operator =(const QDeclarativeSimpleAction &other)
109 m_property = other.m_property;
110 m_value = other.m_value;
111 m_binding = QDeclarativeAbstractBinding::getPointer(other.binding());
112 m_specifiedObject = other.m_specifiedObject;
113 m_specifiedProperty = other.m_specifiedProperty;
114 m_event = other.m_event;
115 m_reverseEvent = other.m_reverseEvent;
120 void setProperty(const QDeclarativeProperty &property)
122 m_property = property;
125 const QDeclarativeProperty &property() const
130 void setValue(const QVariant &value)
135 const QVariant &value() const
140 void setBinding(QDeclarativeAbstractBinding *binding)
142 m_binding = QDeclarativeAbstractBinding::getPointer(binding);
145 QDeclarativeAbstractBinding *binding() const
147 return m_binding.data();
150 QObject *specifiedObject() const
152 return m_specifiedObject;
155 const QString &specifiedProperty() const
157 return m_specifiedProperty;
160 QDeclarativeActionEvent *event() const
165 bool reverseEvent() const
167 return m_reverseEvent;
171 QDeclarativeProperty m_property;
173 QDeclarativeAbstractBinding::Pointer m_binding;
174 QObject *m_specifiedObject;
175 QString m_specifiedProperty;
176 QDeclarativeActionEvent *m_event;
180 class QDeclarativeRevertAction
183 QDeclarativeRevertAction() : event(0) {}
184 QDeclarativeRevertAction(const QDeclarativeProperty &prop) : property(prop), event(0) {}
185 QDeclarativeRevertAction(QDeclarativeActionEvent *e) : event(e) {}
186 QDeclarativeProperty property;
187 QDeclarativeActionEvent *event;
190 class QDeclarativeStateOperationPrivate : public QObjectPrivate
192 Q_DECLARE_PUBLIC(QDeclarativeStateOperation)
196 QDeclarativeStateOperationPrivate()
199 QDeclarativeState *m_state;
202 class QDeclarativeStatePrivate : public QObjectPrivate
204 Q_DECLARE_PUBLIC(QDeclarativeState)
207 QDeclarativeStatePrivate()
208 : when(0), named(false), inState(false), group(0) {}
210 typedef QList<QDeclarativeSimpleAction> SimpleActionList;
213 QDeclarativeBinding *when;
216 struct OperationGuard : public QDeclarativeGuard<QDeclarativeStateOperation>
218 OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) {
219 setObject(static_cast<QDeclarativeStateOperation *>(obj));
221 QList<OperationGuard> *list;
222 void objectDestroyed(QDeclarativeStateOperation *) {
223 // we assume priv will always be destroyed after objectDestroyed calls
224 list->removeOne(*this);
227 QList<OperationGuard> operations;
229 static void operations_append(QDeclarativeListProperty<QDeclarativeStateOperation> *prop, QDeclarativeStateOperation *op) {
230 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
231 op->setState(qobject_cast<QDeclarativeState*>(prop->object));
232 list->append(OperationGuard(op, list));
234 static void operations_clear(QDeclarativeListProperty<QDeclarativeStateOperation> *prop) {
235 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
236 QMutableListIterator<OperationGuard> listIterator(*list);
237 while(listIterator.hasNext())
238 listIterator.next()->setState(0);
241 static int operations_count(QDeclarativeListProperty<QDeclarativeStateOperation> *prop) {
242 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
243 return list->count();
245 static QDeclarativeStateOperation *operations_at(QDeclarativeListProperty<QDeclarativeStateOperation> *prop, int index) {
246 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
247 return list->at(index);
250 QDeclarativeTransitionManager transitionManager;
252 SimpleActionList revertList;
253 QList<QDeclarativeRevertAction> reverting;
255 mutable bool inState;
256 QDeclarativeStateGroup *group;
258 QDeclarativeStateOperation::ActionList generateActionList() const;
264 #endif // QDECLARATIVESTATE_P_H