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 QtDeclarative 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 QDECLARATIVESTATE_H
43 #define QDECLARATIVESTATE_H
45 #include <qdeclarative.h>
46 #include <qdeclarativeproperty.h>
47 #include <QtCore/qobject.h>
48 #include <QtCore/qsharedpointer.h>
49 #include <private/qtquickglobal_p.h>
55 class QDeclarativeActionEvent;
56 class QDeclarativeAbstractBinding;
57 class QDeclarativeBinding;
58 class QDeclarativeExpression;
59 class Q_QUICK_PRIVATE_EXPORT QDeclarativeAction
63 QDeclarativeAction(QObject *, const QString &, const QVariant &);
64 QDeclarativeAction(QObject *, const QString &,
65 QDeclarativeContext *, const QVariant &);
70 bool deletableToBinding:1;
72 QDeclarativeProperty property;
76 QDeclarativeAbstractBinding *fromBinding;
77 QWeakPointer<QDeclarativeAbstractBinding> toBinding;
78 QDeclarativeActionEvent *event;
80 //strictly for matching
81 QObject *specifiedObject;
82 QString specifiedProperty;
84 void deleteFromBinding();
87 class Q_AUTOTEST_EXPORT QDeclarativeActionEvent
90 virtual ~QDeclarativeActionEvent();
91 virtual QString typeName() const;
93 enum Reason { ActualChange, FastForward };
95 virtual void execute(Reason reason = ActualChange);
96 virtual bool isReversable();
97 virtual void reverse(Reason reason = ActualChange);
98 virtual void saveOriginals() {}
99 virtual bool needsCopy() { return false; }
100 virtual void copyOriginals(QDeclarativeActionEvent *) {}
102 virtual bool isRewindable() { return isReversable(); }
103 virtual void rewind() {}
104 virtual void saveCurrentValues() {}
105 virtual void saveTargetValues() {}
107 virtual bool changesBindings();
108 virtual void clearBindings();
109 virtual bool override(QDeclarativeActionEvent*other);
112 //### rename to QDeclarativeStateChange?
113 class QDeclarativeStateGroup;
114 class QDeclarativeState;
115 class QDeclarativeStateOperationPrivate;
116 class Q_QUICK_EXPORT QDeclarativeStateOperation : public QObject
120 QDeclarativeStateOperation(QObject *parent = 0)
122 typedef QList<QDeclarativeAction> ActionList;
124 virtual ActionList actions();
126 QDeclarativeState *state() const;
127 void setState(QDeclarativeState *state);
130 QDeclarativeStateOperation(QObjectPrivate &dd, QObject *parent = 0);
133 Q_DECLARE_PRIVATE(QDeclarativeStateOperation)
134 Q_DISABLE_COPY(QDeclarativeStateOperation)
137 typedef QDeclarativeStateOperation::ActionList QDeclarativeStateActions;
139 class QDeclarativeTransition;
140 class QDeclarativeStatePrivate;
141 class Q_QUICK_EXPORT QDeclarativeState : public QObject
145 Q_PROPERTY(QString name READ name WRITE setName)
146 Q_PROPERTY(QDeclarativeBinding *when READ when WRITE setWhen)
147 Q_PROPERTY(QString extend READ extends WRITE setExtends)
148 Q_PROPERTY(QDeclarativeListProperty<QDeclarativeStateOperation> changes READ changes)
149 Q_CLASSINFO("DefaultProperty", "changes")
150 Q_CLASSINFO("DeferredPropertyNames", "changes")
153 QDeclarativeState(QObject *parent=0);
154 virtual ~QDeclarativeState();
156 QString name() const;
157 void setName(const QString &);
158 bool isNamed() const;
160 /*'when' is a QDeclarativeBinding to limit state changes oscillation
161 due to the unpredictable order of evaluation of bound expressions*/
162 bool isWhenKnown() const;
163 QDeclarativeBinding *when() const;
164 void setWhen(QDeclarativeBinding *);
166 QString extends() const;
167 void setExtends(const QString &);
169 QDeclarativeListProperty<QDeclarativeStateOperation> changes();
170 int operationCount() const;
171 QDeclarativeStateOperation *operationAt(int) const;
173 QDeclarativeState &operator<<(QDeclarativeStateOperation *);
175 void apply(QDeclarativeTransition *, QDeclarativeState *revert);
178 QDeclarativeStateGroup *stateGroup() const;
179 void setStateGroup(QDeclarativeStateGroup *);
181 bool containsPropertyInRevertList(QObject *target, const QString &name) const;
182 bool changeValueInRevertList(QObject *target, const QString &name, const QVariant &revertValue);
183 bool changeBindingInRevertList(QObject *target, const QString &name, QDeclarativeAbstractBinding *binding);
184 bool removeEntryFromRevertList(QObject *target, const QString &name);
185 void addEntryToRevertList(const QDeclarativeAction &action);
186 void removeAllEntriesFromRevertList(QObject *target);
187 void addEntriesToRevertList(const QList<QDeclarativeAction> &actions);
188 QVariant valueInRevertList(QObject *target, const QString &name) const;
189 QDeclarativeAbstractBinding *bindingInRevertList(QObject *target, const QString &name) const;
191 bool isStateActive() const;
197 Q_DECLARE_PRIVATE(QDeclarativeState)
198 Q_DISABLE_COPY(QDeclarativeState)
203 QML_DECLARE_TYPE(QDeclarativeStateOperation)
204 QML_DECLARE_TYPE(QDeclarativeState)
208 #endif // QDECLARATIVESTATE_H