1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKSTATE_P_H
43 #define QQUICKSTATE_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 "qquickstate_p.h"
58 #include "qquicktransitionmanager_p_p.h"
60 #include <private/qqmlproperty_p.h>
61 #include <private/qqmlguard_p.h>
63 #include <private/qqmlbinding_p.h>
65 #include <private/qobject_p.h>
69 class QQuickSimpleAction
72 enum State { StartState, EndState };
73 QQuickSimpleAction(const QQuickAction &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 (QQmlPropertyPrivate::binding(m_property)) {
82 m_binding = QQmlAbstractBinding::getPointer(QQmlPropertyPrivate::binding(m_property));
84 m_reverseEvent = true;
87 m_binding = a.toBinding;
88 m_reverseEvent = false;
96 QQuickSimpleAction(const QQuickSimpleAction &other)
97 : m_property(other.m_property),
98 m_value(other.m_value),
99 m_binding(QQmlAbstractBinding::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 QQuickSimpleAction &operator =(const QQuickSimpleAction &other)
109 m_property = other.m_property;
110 m_value = other.m_value;
111 m_binding = QQmlAbstractBinding::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 QQmlProperty &property)
122 m_property = property;
125 const QQmlProperty &property() const
130 void setValue(const QVariant &value)
135 const QVariant &value() const
140 void setBinding(QQmlAbstractBinding *binding)
142 m_binding = QQmlAbstractBinding::getPointer(binding);
145 QQmlAbstractBinding *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 QQuickActionEvent *event() const
165 bool reverseEvent() const
167 return m_reverseEvent;
171 QQmlProperty m_property;
173 QQmlAbstractBinding::Pointer m_binding;
174 QObject *m_specifiedObject;
175 QString m_specifiedProperty;
176 QQuickActionEvent *m_event;
180 class QQuickRevertAction
183 QQuickRevertAction() : event(0) {}
184 QQuickRevertAction(const QQmlProperty &prop) : property(prop), event(0) {}
185 QQuickRevertAction(QQuickActionEvent *e) : event(e) {}
186 QQmlProperty property;
187 QQuickActionEvent *event;
190 class QQuickStateOperationPrivate : public QObjectPrivate
192 Q_DECLARE_PUBLIC(QQuickStateOperation)
196 QQuickStateOperationPrivate()
199 QQuickState *m_state;
202 class QQuickStatePrivate : public QObjectPrivate
204 Q_DECLARE_PUBLIC(QQuickState)
208 : when(0), named(false), inState(false), group(0) {}
210 typedef QList<QQuickSimpleAction> SimpleActionList;
216 struct OperationGuard : public QQmlGuard<QQuickStateOperation>
218 OperationGuard(QObject *obj, QList<OperationGuard> *l) : list(l) {
219 setObject(static_cast<QQuickStateOperation *>(obj));
221 QList<OperationGuard> *list;
222 void objectDestroyed(QQuickStateOperation *) {
223 // we assume priv will always be destroyed after objectDestroyed calls
224 list->removeOne(*this);
227 QList<OperationGuard> operations;
229 static void operations_append(QQmlListProperty<QQuickStateOperation> *prop, QQuickStateOperation *op) {
230 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
231 op->setState(qobject_cast<QQuickState*>(prop->object));
232 list->append(OperationGuard(op, list));
234 static void operations_clear(QQmlListProperty<QQuickStateOperation> *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(QQmlListProperty<QQuickStateOperation> *prop) {
242 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
243 return list->count();
245 static QQuickStateOperation *operations_at(QQmlListProperty<QQuickStateOperation> *prop, int index) {
246 QList<OperationGuard> *list = static_cast<QList<OperationGuard> *>(prop->data);
247 return list->at(index);
250 QQuickTransitionManager transitionManager;
252 SimpleActionList revertList;
253 QList<QQuickRevertAction> reverting;
255 mutable bool inState;
256 QQuickStateGroup *group;
258 QQuickStateOperation::ActionList generateActionList() const;
264 #endif // QQUICKSTATE_P_H