1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 "QtQuick1/private/qdeclarativestate_p.h"
58 #include "QtQuick1/private/qdeclarativeanimation_p_p.h"
59 #include "QtQuick1/private/qdeclarativetransitionmanager_p_p.h"
61 #include <QtDeclarative/private/qdeclarativeproperty_p.h>
62 #include <QtDeclarative/private/qdeclarativeguard_p.h>
64 #include <QtDeclarative/private/qdeclarativebinding_p.h>
66 #include <QtCore/private/qobject_p.h>
70 class QDeclarative1SimpleAction
73 enum State { StartState, EndState };
74 QDeclarative1SimpleAction(const QDeclarative1Action &a, State state = StartState)
76 m_property = a.property;
77 m_specifiedObject = a.specifiedObject;
78 m_specifiedProperty = a.specifiedProperty;
80 if (state == StartState) {
81 m_value = a.fromValue;
82 if (QDeclarativePropertyPrivate::binding(m_property)) {
83 m_binding = QDeclarativeAbstractBinding::getPointer(QDeclarativePropertyPrivate::binding(m_property));
85 m_reverseEvent = true;
88 m_binding = a.toBinding;
89 m_reverseEvent = false;
93 ~QDeclarative1SimpleAction()
97 QDeclarative1SimpleAction(const QDeclarative1SimpleAction &other)
98 : m_property(other.m_property),
99 m_value(other.m_value),
100 m_binding(QDeclarativeAbstractBinding::getPointer(other.binding())),
101 m_specifiedObject(other.m_specifiedObject),
102 m_specifiedProperty(other.m_specifiedProperty),
103 m_event(other.m_event),
104 m_reverseEvent(other.m_reverseEvent)
108 QDeclarative1SimpleAction &operator =(const QDeclarative1SimpleAction &other)
110 m_property = other.m_property;
111 m_value = other.m_value;
112 m_binding = QDeclarativeAbstractBinding::getPointer(other.binding());
113 m_specifiedObject = other.m_specifiedObject;
114 m_specifiedProperty = other.m_specifiedProperty;
115 m_event = other.m_event;
116 m_reverseEvent = other.m_reverseEvent;
121 void setProperty(const QDeclarativeProperty &property)
123 m_property = property;
126 const QDeclarativeProperty &property() const
131 void setValue(const QVariant &value)
136 const QVariant &value() const
141 void setBinding(QDeclarativeAbstractBinding *binding)
143 m_binding = QDeclarativeAbstractBinding::getPointer(binding);
146 QDeclarativeAbstractBinding *binding() const
148 return m_binding.data();
151 QObject *specifiedObject() const
153 return m_specifiedObject;
156 const QString &specifiedProperty() const
158 return m_specifiedProperty;
161 QDeclarative1ActionEvent *event() const
166 bool reverseEvent() const
168 return m_reverseEvent;
172 QDeclarativeProperty m_property;
174 QDeclarativeAbstractBinding::Pointer m_binding;
175 QObject *m_specifiedObject;
176 QString m_specifiedProperty;
177 QDeclarative1ActionEvent *m_event;
181 class QDeclarative1StateOperationPrivate : public QObjectPrivate
183 Q_DECLARE_PUBLIC(QDeclarative1StateOperation)
187 QDeclarative1StateOperationPrivate()
190 QDeclarative1State *m_state;
193 class QDeclarative1StatePrivate : public QObjectPrivate
195 Q_DECLARE_PUBLIC(QDeclarative1State)
198 QDeclarative1StatePrivate()
199 : when(0), named(false), inState(false), group(0) {}
201 typedef QList<QDeclarative1SimpleAction> SimpleActionList;
204 QDeclarativeBinding *when;
207 struct OperationGuard : public QDeclarativeGuard<QDeclarative1StateOperation>
209 OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) { (QDeclarativeGuard<QObject>&)*this = obj; }
210 QList<OperationGuard> *list;
211 void objectDestroyed(QDeclarative1StateOperation *) {
212 // we assume priv will always be destroyed after objectDestroyed calls
213 list->removeOne(*this);
216 QList<OperationGuard> operations;
218 static void operations_append(QDeclarativeListProperty<QDeclarative1StateOperation> *prop, QDeclarative1StateOperation *op) {
219 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
220 op->setState(qobject_cast<QDeclarative1State*>(prop->object));
221 list->append(OperationGuard(op, list));
223 static void operations_clear(QDeclarativeListProperty<QDeclarative1StateOperation> *prop) {
224 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
225 QMutableListIterator<OperationGuard> listIterator(*list);
226 while(listIterator.hasNext())
227 listIterator.next()->setState(0);
230 static int operations_count(QDeclarativeListProperty<QDeclarative1StateOperation> *prop) {
231 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
232 return list->count();
234 static QDeclarative1StateOperation *operations_at(QDeclarativeListProperty<QDeclarative1StateOperation> *prop, int index) {
235 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
236 return list->at(index);
239 QDeclarative1TransitionManager transitionManager;
241 SimpleActionList revertList;
242 QList<QDeclarativeProperty> reverting;
244 mutable bool inState;
245 QDeclarative1StateGroup *group;
247 QDeclarative1StateOperation::ActionList generateActionList(QDeclarative1StateGroup *) const;
253 #endif // QDECLARATIVESTATE_P_H