| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qhistorystate.h" | - |
| 43 | | - |
| 44 | #ifndef QT_NO_STATEMACHINE | - |
| 45 | | - |
| 46 | #include "qhistorystate_p.h" | - |
| 47 | | - |
| 48 | QT_BEGIN_NAMESPACE | - |
| 49 | | - |
| 50 | /*! | - |
| 51 | \class QHistoryState | - |
| 52 | \inmodule QtCore | - |
| 53 | | - |
| 54 | \brief The QHistoryState class provides a means of returning to a previously active substate. | - |
| 55 | | - |
| 56 | \since 4.6 | - |
| 57 | \ingroup statemachine | - |
| 58 | | - |
| 59 | A history state is a pseudo-state that represents the child state that the | - |
| 60 | parent state was in the last time the parent state was exited. A transition | - |
| 61 | with a history state as its target is in fact a transition to one of the | - |
| 62 | other child states of the parent state. QHistoryState is part of \l{The | - |
| 63 | State Machine Framework}. | - |
| 64 | | - |
| 65 | Use the setDefaultState() function to set the state that should be entered | - |
| 66 | if the parent state has never been entered. Example: | - |
| 67 | | - |
| 68 | \code | - |
| 69 | QStateMachine machine; | - |
| 70 | | - |
| 71 | QState *s1 = new QState(); | - |
| 72 | QState *s11 = new QState(s1); | - |
| 73 | QState *s12 = new QState(s1); | - |
| 74 | | - |
| 75 | QHistoryState *s1h = new QHistoryState(s1); | - |
| 76 | s1h->setDefaultState(s11); | - |
| 77 | | - |
| 78 | machine.addState(s1); | - |
| 79 | | - |
| 80 | QState *s2 = new QState(); | - |
| 81 | machine.addState(s2); | - |
| 82 | | - |
| 83 | QPushButton *button = new QPushButton(); | - |
| 84 | // Clicking the button will cause the state machine to enter the child state | - |
| 85 | // that s1 was in the last time s1 was exited, or the history state's default | - |
| 86 | // state if s1 has never been entered. | - |
| 87 | s1->addTransition(button, SIGNAL(clicked()), s1h); | - |
| 88 | \endcode | - |
| 89 | | - |
| 90 | By default a history state is shallow, meaning that it won't remember nested | - |
| 91 | states. This can be configured through the historyType property. | - |
| 92 | */ | - |
| 93 | | - |
| 94 | /*! | - |
| 95 | \property QHistoryState::defaultState | - |
| 96 | | - |
| 97 | \brief the default state of this history state | - |
| 98 | */ | - |
| 99 | | - |
| 100 | /*! | - |
| 101 | \property QHistoryState::historyType | - |
| 102 | | - |
| 103 | \brief the type of history that this history state records | - |
| 104 | | - |
| 105 | The default value of this property is QHistoryState::ShallowHistory. | - |
| 106 | */ | - |
| 107 | | - |
| 108 | /*! | - |
| 109 | \enum QHistoryState::HistoryType | - |
| 110 | | - |
| 111 | This enum specifies the type of history that a QHistoryState records. | - |
| 112 | | - |
| 113 | \value ShallowHistory Only the immediate child states of the parent state | - |
| 114 | are recorded. In this case a transition with the history state as its | - |
| 115 | target will end up in the immediate child state that the parent was in the | - |
| 116 | last time it was exited. This is the default. | - |
| 117 | | - |
| 118 | \value DeepHistory Nested states are recorded. In this case a transition | - |
| 119 | with the history state as its target will end up in the most deeply nested | - |
| 120 | descendant state the parent was in the last time it was exited. | - |
| 121 | */ | - |
| 122 | | - |
| 123 | QHistoryStatePrivate::QHistoryStatePrivate() | - |
| 124 | : QAbstractStatePrivate(HistoryState), | - |
| 125 | defaultState(0), historyType(QHistoryState::ShallowHistory) | - |
| 126 | { | - |
| 127 | } executed: }Execution Count:7 | 7 |
| 128 | | - |
| 129 | QHistoryStatePrivate *QHistoryStatePrivate::get(QHistoryState *q) | - |
| 130 | { | - |
| 131 | return q->d_func(); executed: return q->d_func();Execution Count:63 | 63 |
| 132 | } | - |
| 133 | | - |
| 134 | /*! | - |
| 135 | Constructs a new shallow history state with the given \a parent state. | - |
| 136 | */ | - |
| 137 | QHistoryState::QHistoryState(QState *parent) | - |
| 138 | : QAbstractState(*new QHistoryStatePrivate, parent) | - |
| 139 | { | - |
| 140 | } executed: }Execution Count:6 | 6 |
| 141 | /*! | - |
| 142 | Constructs a new history state of the given \a type, with the given \a | - |
| 143 | parent state. | - |
| 144 | */ | - |
| 145 | QHistoryState::QHistoryState(HistoryType type, QState *parent) | - |
| 146 | : QAbstractState(*new QHistoryStatePrivate, parent) | - |
| 147 | { | - |
| 148 | Q_D(QHistoryState); executed (the execution status of this line is deduced): QHistoryStatePrivate * const d = d_func(); | - |
| 149 | d->historyType = type; executed (the execution status of this line is deduced): d->historyType = type; | - |
| 150 | } executed: }Execution Count:1 | 1 |
| 151 | | - |
| 152 | /*! | - |
| 153 | Destroys this history state. | - |
| 154 | */ | - |
| 155 | QHistoryState::~QHistoryState() | - |
| 156 | { | - |
| 157 | } | - |
| 158 | | - |
| 159 | /*! | - |
| 160 | Returns this history state's default state. The default state indicates the | - |
| 161 | state to transition to if the parent state has never been entered before. | - |
| 162 | */ | - |
| 163 | QAbstractState *QHistoryState::defaultState() const | - |
| 164 | { | - |
| 165 | Q_D(const QHistoryState); executed (the execution status of this line is deduced): const QHistoryStatePrivate * const d = d_func(); | - |
| 166 | return d->defaultState; executed: return d->defaultState;Execution Count:4 | 4 |
| 167 | } | - |
| 168 | | - |
| 169 | /*! | - |
| 170 | Sets this history state's default state to be the given \a state. | - |
| 171 | \a state must be a sibling of this history state. | - |
| 172 | | - |
| 173 | Note that this function does not set \a state as the initial state | - |
| 174 | of its parent. | - |
| 175 | */ | - |
| 176 | void QHistoryState::setDefaultState(QAbstractState *state) | - |
| 177 | { | - |
| 178 | Q_D(QHistoryState); executed (the execution status of this line is deduced): QHistoryStatePrivate * const d = d_func(); | - |
| 179 | if (state && state->parentState() != parentState()) { partially evaluated: state| yes Evaluation Count:8 | no Evaluation Count:0 |
evaluated: state->parentState() != parentState()| yes Evaluation Count:2 | yes Evaluation Count:6 |
| 0-8 |
| 180 | qWarning("QHistoryState::setDefaultState: state %p does not belong " executed (the execution status of this line is deduced): QMessageLogger("statemachine/qhistorystate.cpp", 180, __PRETTY_FUNCTION__).warning("QHistoryState::setDefaultState: state %p does not belong " | - |
| 181 | "to this history state's group (%p)", state, parentState()); executed (the execution status of this line is deduced): "to this history state's group (%p)", state, parentState()); | - |
| 182 | return; executed: return;Execution Count:2 | 2 |
| 183 | } | - |
| 184 | d->defaultState = state; executed (the execution status of this line is deduced): d->defaultState = state; | - |
| 185 | } executed: }Execution Count:6 | 6 |
| 186 | | - |
| 187 | /*! | - |
| 188 | Returns the type of history that this history state records. | - |
| 189 | */ | - |
| 190 | QHistoryState::HistoryType QHistoryState::historyType() const | - |
| 191 | { | - |
| 192 | Q_D(const QHistoryState); executed (the execution status of this line is deduced): const QHistoryStatePrivate * const d = d_func(); | - |
| 193 | return d->historyType; executed: return d->historyType;Execution Count:5 | 5 |
| 194 | } | - |
| 195 | | - |
| 196 | /*! | - |
| 197 | Sets the \a type of history that this history state records. | - |
| 198 | */ | - |
| 199 | void QHistoryState::setHistoryType(HistoryType type) | - |
| 200 | { | - |
| 201 | Q_D(QHistoryState); executed (the execution status of this line is deduced): QHistoryStatePrivate * const d = d_func(); | - |
| 202 | d->historyType = type; executed (the execution status of this line is deduced): d->historyType = type; | - |
| 203 | } executed: }Execution Count:3 | 3 |
| 204 | | - |
| 205 | /*! | - |
| 206 | \reimp | - |
| 207 | */ | - |
| 208 | void QHistoryState::onEntry(QEvent *event) | - |
| 209 | { | - |
| 210 | Q_UNUSED(event); never executed (the execution status of this line is deduced): (void)event;; | - |
| 211 | } | 0 |
| 212 | | - |
| 213 | /*! | - |
| 214 | \reimp | - |
| 215 | */ | - |
| 216 | void QHistoryState::onExit(QEvent *event) | - |
| 217 | { | - |
| 218 | Q_UNUSED(event); never executed (the execution status of this line is deduced): (void)event;; | - |
| 219 | } | 0 |
| 220 | | - |
| 221 | /*! | - |
| 222 | \reimp | - |
| 223 | */ | - |
| 224 | bool QHistoryState::event(QEvent *e) | - |
| 225 | { | - |
| 226 | return QAbstractState::event(e); never executed: return QAbstractState::event(e); | 0 |
| 227 | } | - |
| 228 | | - |
| 229 | QT_END_NAMESPACE | - |
| 230 | | - |
| 231 | #endif //QT_NO_STATEMACHINE | - |
| 232 | | - |
| | |