| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/statemachine/qstatemachine.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 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 The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qstatemachine.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #ifndef QT_NO_STATEMACHINE | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | #include "qstate.h" | - | ||||||||||||||||||
| 45 | #include "qstate_p.h" | - | ||||||||||||||||||
| 46 | #include "qstatemachine_p.h" | - | ||||||||||||||||||
| 47 | #include "qabstracttransition.h" | - | ||||||||||||||||||
| 48 | #include "qabstracttransition_p.h" | - | ||||||||||||||||||
| 49 | #include "qsignaltransition.h" | - | ||||||||||||||||||
| 50 | #include "qsignaltransition_p.h" | - | ||||||||||||||||||
| 51 | #include "qsignaleventgenerator_p.h" | - | ||||||||||||||||||
| 52 | #include "qabstractstate.h" | - | ||||||||||||||||||
| 53 | #include "qabstractstate_p.h" | - | ||||||||||||||||||
| 54 | #include "qfinalstate.h" | - | ||||||||||||||||||
| 55 | #include "qhistorystate.h" | - | ||||||||||||||||||
| 56 | #include "qhistorystate_p.h" | - | ||||||||||||||||||
| 57 | #include "private/qobject_p.h" | - | ||||||||||||||||||
| 58 | #include "private/qthread_p.h" | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 61 | #include "qeventtransition.h" | - | ||||||||||||||||||
| 62 | #include "qeventtransition_p.h" | - | ||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 66 | #include "qpropertyanimation.h" | - | ||||||||||||||||||
| 67 | #include "qanimationgroup.h" | - | ||||||||||||||||||
| 68 | #include <private/qvariantanimation_p.h> | - | ||||||||||||||||||
| 69 | #endif | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | #include <QtCore/qmetaobject.h> | - | ||||||||||||||||||
| 72 | #include <qdebug.h> | - | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | #include <algorithm> | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | /*! | - | ||||||||||||||||||
| 79 | \class QStateMachine | - | ||||||||||||||||||
| 80 | \inmodule QtCore | - | ||||||||||||||||||
| 81 | \reentrant | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | \brief The QStateMachine class provides a hierarchical finite state machine. | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | \since 4.6 | - | ||||||||||||||||||
| 86 | \ingroup statemachine | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | QStateMachine is based on the concepts and notation of | - | ||||||||||||||||||
| 89 | \l{http://www.wisdom.weizmann.ac.il/~dharel/SCANNED.PAPERS/Statecharts.pdf}{Statecharts}. | - | ||||||||||||||||||
| 90 | QStateMachine is part of \l{The State Machine Framework}. | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | A state machine manages a set of states (classes that inherit from | - | ||||||||||||||||||
| 93 | QAbstractState) and transitions (descendants of | - | ||||||||||||||||||
| 94 | QAbstractTransition) between those states; these states and | - | ||||||||||||||||||
| 95 | transitions define a state graph. Once a state graph has been | - | ||||||||||||||||||
| 96 | built, the state machine can execute it. QStateMachine's | - | ||||||||||||||||||
| 97 | execution algorithm is based on the \l{http://www.w3.org/TR/scxml/}{State Chart XML (SCXML)} | - | ||||||||||||||||||
| 98 | algorithm. The framework's \l{The State Machine | - | ||||||||||||||||||
| 99 | Framework}{overview} gives several state graphs and the code to | - | ||||||||||||||||||
| 100 | build them. | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | Use the addState() function to add a top-level state to the state machine. | - | ||||||||||||||||||
| 103 | States are removed with the removeState() function. Removing states while | - | ||||||||||||||||||
| 104 | the machine is running is discouraged. | - | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | Before the machine can be started, the \l{initialState}{initial | - | ||||||||||||||||||
| 107 | state} must be set. The initial state is the state that the | - | ||||||||||||||||||
| 108 | machine enters when started. You can then start() the state | - | ||||||||||||||||||
| 109 | machine. The started() signal is emitted when the initial state is | - | ||||||||||||||||||
| 110 | entered. | - | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | The machine is event driven and keeps its own event loop. Events | - | ||||||||||||||||||
| 113 | are posted to the machine through postEvent(). Note that this | - | ||||||||||||||||||
| 114 | means that it executes asynchronously, and that it will not | - | ||||||||||||||||||
| 115 | progress without a running event loop. You will normally not have | - | ||||||||||||||||||
| 116 | to post events to the machine directly as Qt's transitions, e.g., | - | ||||||||||||||||||
| 117 | QEventTransition and its subclasses, handle this. But for custom | - | ||||||||||||||||||
| 118 | transitions triggered by events, postEvent() is useful. | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | The state machine processes events and takes transitions until a | - | ||||||||||||||||||
| 121 | top-level final state is entered; the state machine then emits the | - | ||||||||||||||||||
| 122 | finished() signal. You can also stop() the state machine | - | ||||||||||||||||||
| 123 | explicitly. The stopped() signal is emitted in this case. | - | ||||||||||||||||||
| 124 | - | |||||||||||||||||||
| 125 | The following snippet shows a state machine that will finish when a button | - | ||||||||||||||||||
| 126 | is clicked: | - | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | \snippet code/src_corelib_statemachine_qstatemachine.cpp simple state machine | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | This code example uses QState, which inherits QAbstractState. The | - | ||||||||||||||||||
| 131 | QState class provides a state that you can use to set properties | - | ||||||||||||||||||
| 132 | and invoke methods on \l{QObject}s when the state is entered or | - | ||||||||||||||||||
| 133 | exited. It also contains convenience functions for adding | - | ||||||||||||||||||
| 134 | transitions, e.g., \l{QSignalTransition}s as in this example. See | - | ||||||||||||||||||
| 135 | the QState class description for further details. | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | If an error is encountered, the machine will look for an | - | ||||||||||||||||||
| 138 | \l{errorState}{error state}, and if one is available, it will | - | ||||||||||||||||||
| 139 | enter this state. The types of errors possible are described by the | - | ||||||||||||||||||
| 140 | \l{QStateMachine::}{Error} enum. After the error state is entered, | - | ||||||||||||||||||
| 141 | the type of the error can be retrieved with error(). The execution | - | ||||||||||||||||||
| 142 | of the state graph will not stop when the error state is entered. If | - | ||||||||||||||||||
| 143 | no error state applies to the erroneous state, the machine will stop | - | ||||||||||||||||||
| 144 | executing and an error message will be printed to the console. | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | \sa QAbstractState, QAbstractTransition, QState, {The State Machine Framework} | - | ||||||||||||||||||
| 147 | */ | - | ||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | /*! | - | ||||||||||||||||||
| 150 | \property QStateMachine::errorString | - | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | \brief the error string of this state machine | - | ||||||||||||||||||
| 153 | */ | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | /*! | - | ||||||||||||||||||
| 156 | \property QStateMachine::globalRestorePolicy | - | ||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | \brief the restore policy for states of this state machine. | - | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | The default value of this property is | - | ||||||||||||||||||
| 161 | QState::DontRestoreProperties. | - | ||||||||||||||||||
| 162 | */ | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | /*! | - | ||||||||||||||||||
| 165 | \property QStateMachine::running | - | ||||||||||||||||||
| 166 | \since 5.4 | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | \brief the running state of this state machine | - | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | \sa start(), stop(), started(), stopped(), runningChanged() | - | ||||||||||||||||||
| 171 | */ | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 174 | /*! | - | ||||||||||||||||||
| 175 | \property QStateMachine::animated | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | \brief whether animations are enabled | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | The default value of this property is \c true. | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | \sa QAbstractTransition::addAnimation() | - | ||||||||||||||||||
| 182 | */ | - | ||||||||||||||||||
| 183 | #endif | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | // #define QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 186 | // #define QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | struct CalculationCache { | - | ||||||||||||||||||
| 189 | struct TransitionInfo { | - | ||||||||||||||||||
| 190 | QList<QAbstractState*> effectiveTargetStates; | - | ||||||||||||||||||
| 191 | QSet<QAbstractState*> exitSet; | - | ||||||||||||||||||
| 192 | QAbstractState *transitionDomain; | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | bool effectiveTargetStatesIsKnown: 1; | - | ||||||||||||||||||
| 195 | bool exitSetIsKnown : 1; | - | ||||||||||||||||||
| 196 | bool transitionDomainIsKnown : 1; | - | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | TransitionInfo() | - | ||||||||||||||||||
| 199 | : transitionDomain(0) | - | ||||||||||||||||||
| 200 | , effectiveTargetStatesIsKnown(false) | - | ||||||||||||||||||
| 201 | , exitSetIsKnown(false) | - | ||||||||||||||||||
| 202 | , transitionDomainIsKnown(false) | - | ||||||||||||||||||
| 203 | {} executed 1394 times by 2 tests: end of blockExecuted by:
| 1394 | ||||||||||||||||||
| 204 | }; | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | typedef QHash<QAbstractTransition *, TransitionInfo> TransitionInfoCache; | - | ||||||||||||||||||
| 207 | TransitionInfoCache cache; | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | bool effectiveTargetStates(QAbstractTransition *t, QList<QAbstractState *> *targets) const | - | ||||||||||||||||||
| 210 | { | - | ||||||||||||||||||
| 211 | Q_ASSERT(targets); | - | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | TransitionInfoCache::const_iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 214 | if (cacheIt == cache.end() || !cacheIt->effectiveTargetStatesIsKnown)
| 0-1394 | ||||||||||||||||||
| 215 | return false; executed 1394 times by 2 tests: return false;Executed by:
| 1394 | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | *targets = cacheIt->effectiveTargetStates; | - | ||||||||||||||||||
| 218 | return true; executed 1237 times by 2 tests: return true;Executed by:
| 1237 | ||||||||||||||||||
| 219 | } | - | ||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | void insert(QAbstractTransition *t, const QList<QAbstractState *> &targets) | - | ||||||||||||||||||
| 222 | { | - | ||||||||||||||||||
| 223 | TransitionInfoCache::iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 224 | TransitionInfo &ti = cacheIt == cache.end()
| 0-1394 | ||||||||||||||||||
| 225 | ? *cache.insert(t, TransitionInfo()) | - | ||||||||||||||||||
| 226 | : *cacheIt; | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | Q_ASSERT(!ti.effectiveTargetStatesIsKnown); | - | ||||||||||||||||||
| 229 | ti.effectiveTargetStates = targets; | - | ||||||||||||||||||
| 230 | ti.effectiveTargetStatesIsKnown = true; | - | ||||||||||||||||||
| 231 | } executed 1394 times by 2 tests: end of blockExecuted by:
| 1394 | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | bool exitSet(QAbstractTransition *t, QSet<QAbstractState *> *exits) const | - | ||||||||||||||||||
| 234 | { | - | ||||||||||||||||||
| 235 | Q_ASSERT(exits); | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | TransitionInfoCache::const_iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 238 | if (cacheIt == cache.end() || !cacheIt->exitSetIsKnown)
| 0-1241 | ||||||||||||||||||
| 239 | return false; executed 1241 times by 2 tests: return false;Executed by:
| 1241 | ||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | *exits = cacheIt->exitSet; | - | ||||||||||||||||||
| 242 | return true; executed 19 times by 1 test: return true;Executed by:
| 19 | ||||||||||||||||||
| 243 | } | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | void insert(QAbstractTransition *t, const QSet<QAbstractState *> &exits) | - | ||||||||||||||||||
| 246 | { | - | ||||||||||||||||||
| 247 | TransitionInfoCache::iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 248 | TransitionInfo &ti = cacheIt == cache.end()
| 0-1241 | ||||||||||||||||||
| 249 | ? *cache.insert(t, TransitionInfo()) | - | ||||||||||||||||||
| 250 | : *cacheIt; | - | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | Q_ASSERT(!ti.exitSetIsKnown); | - | ||||||||||||||||||
| 253 | ti.exitSet = exits; | - | ||||||||||||||||||
| 254 | ti.exitSetIsKnown = true; | - | ||||||||||||||||||
| 255 | } executed 1241 times by 2 tests: end of blockExecuted by:
| 1241 | ||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | bool transitionDomain(QAbstractTransition *t, QAbstractState **domain) const | - | ||||||||||||||||||
| 258 | { | - | ||||||||||||||||||
| 259 | Q_ASSERT(domain); | - | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | TransitionInfoCache::const_iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 262 | if (cacheIt == cache.end() || !cacheIt->transitionDomainIsKnown)
| 0-2620 | ||||||||||||||||||
| 263 | return false; executed 1389 times by 2 tests: return false;Executed by:
| 1389 | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | *domain = cacheIt->transitionDomain; | - | ||||||||||||||||||
| 266 | return true; executed 1231 times by 2 tests: return true;Executed by:
| 1231 | ||||||||||||||||||
| 267 | } | - | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | void insert(QAbstractTransition *t, QAbstractState *domain) | - | ||||||||||||||||||
| 270 | { | - | ||||||||||||||||||
| 271 | TransitionInfoCache::iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 272 | TransitionInfo &ti = cacheIt == cache.end()
| 0-1387 | ||||||||||||||||||
| 273 | ? *cache.insert(t, TransitionInfo()) | - | ||||||||||||||||||
| 274 | : *cacheIt; | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | Q_ASSERT(!ti.transitionDomainIsKnown); | - | ||||||||||||||||||
| 277 | ti.transitionDomain = domain; | - | ||||||||||||||||||
| 278 | ti.transitionDomainIsKnown = true; | - | ||||||||||||||||||
| 279 | } executed 1387 times by 2 tests: end of blockExecuted by:
| 1387 | ||||||||||||||||||
| 280 | }; | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | function isDescendant(state1, state2) | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | Returns 'true' if state1 is a descendant of state2 (a child, or a child of a child, or a child of a | - | ||||||||||||||||||
| 287 | child of a child, etc.) Otherwise returns 'false'. | - | ||||||||||||||||||
| 288 | */ | - | ||||||||||||||||||
| 289 | static inline bool isDescendant(const QAbstractState *state1, const QAbstractState *state2) | - | ||||||||||||||||||
| 290 | { | - | ||||||||||||||||||
| 291 | Q_ASSERT(state1 != 0); | - | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | for (QAbstractState *it = state1->parentState(); it != 0; it = it->parentState()) {
| 1681-9869 | ||||||||||||||||||
| 294 | if (it == state2)
| 3496-6373 | ||||||||||||||||||
| 295 | return true; executed 3496 times by 2 tests: return true;Executed by:
| 3496 | ||||||||||||||||||
| 296 | } executed 6373 times by 2 tests: end of blockExecuted by:
| 6373 | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | return false; executed 1681 times by 2 tests: return false;Executed by:
| 1681 | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | static bool containsDecendantOf(const QSet<QAbstractState *> &states, const QAbstractState *node) | - | ||||||||||||||||||
| 302 | { | - | ||||||||||||||||||
| 303 | for (QAbstractState *s : states) | - | ||||||||||||||||||
| 304 | if (isDescendant(s, node))
| 36-354 | ||||||||||||||||||
| 305 | return true; executed 36 times by 1 test: return true;Executed by:
| 36 | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | return false; executed 56 times by 1 test: return false;Executed by:
| 56 | ||||||||||||||||||
| 308 | } | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | static int descendantDepth(const QAbstractState *state, const QAbstractState *ancestor) | - | ||||||||||||||||||
| 311 | { | - | ||||||||||||||||||
| 312 | int depth = 0; | - | ||||||||||||||||||
| 313 | for (const QAbstractState *it = state; it != 0; it = it->parentState()) {
| 0-62 | ||||||||||||||||||
| 314 | if (it == ancestor)
| 24-38 | ||||||||||||||||||
| 315 | break; executed 24 times by 1 test: break;Executed by:
| 24 | ||||||||||||||||||
| 316 | ++depth; | - | ||||||||||||||||||
| 317 | } executed 38 times by 1 test: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 318 | return depth; executed 24 times by 1 test: return depth;Executed by:
| 24 | ||||||||||||||||||
| 319 | } | - | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | function getProperAncestors(state1, state2) | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | If state2 is null, returns the set of all ancestors of state1 in ancestry order (state1's parent | - | ||||||||||||||||||
| 326 | followed by the parent's parent, etc. up to an including the <scxml> element). If state2 is | - | ||||||||||||||||||
| 327 | non-null, returns in ancestry order the set of all ancestors of state1, up to but not including | - | ||||||||||||||||||
| 328 | state2. (A "proper ancestor" of a state is its parent, or the parent's parent, or the parent's | - | ||||||||||||||||||
| 329 | parent's parent, etc.))If state2 is state1's parent, or equal to state1, or a descendant of state1, | - | ||||||||||||||||||
| 330 | this returns the empty set. | - | ||||||||||||||||||
| 331 | */ | - | ||||||||||||||||||
| 332 | static QVector<QState*> getProperAncestors(const QAbstractState *state, const QAbstractState *upperBound) | - | ||||||||||||||||||
| 333 | { | - | ||||||||||||||||||
| 334 | Q_ASSERT(state != 0); | - | ||||||||||||||||||
| 335 | QVector<QState*> result; | - | ||||||||||||||||||
| 336 | result.reserve(16); | - | ||||||||||||||||||
| 337 | for (QState *it = state->parentState(); it && it != upperBound; it = it->parentState()) {
| 1468-8455 | ||||||||||||||||||
| 338 | result.append(it); | - | ||||||||||||||||||
| 339 | } executed 6987 times by 2 tests: end of blockExecuted by:
| 6987 | ||||||||||||||||||
| 340 | return result; executed 6957 times by 2 tests: return result;Executed by:
| 6957 | ||||||||||||||||||
| 341 | } | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 344 | - | |||||||||||||||||||
| 345 | function getEffectiveTargetStates(transition) | - | ||||||||||||||||||
| 346 | - | |||||||||||||||||||
| 347 | Returns the states that will be the target when 'transition' is taken, dereferencing any history states. | - | ||||||||||||||||||
| 348 | - | |||||||||||||||||||
| 349 | function getEffectiveTargetStates(transition) | - | ||||||||||||||||||
| 350 | targets = new OrderedSet() | - | ||||||||||||||||||
| 351 | for s in transition.target | - | ||||||||||||||||||
| 352 | if isHistoryState(s): | - | ||||||||||||||||||
| 353 | if historyValue[s.id]: | - | ||||||||||||||||||
| 354 | targets.union(historyValue[s.id]) | - | ||||||||||||||||||
| 355 | else: | - | ||||||||||||||||||
| 356 | targets.union(getEffectiveTargetStates(s.transition)) | - | ||||||||||||||||||
| 357 | else: | - | ||||||||||||||||||
| 358 | targets.add(s) | - | ||||||||||||||||||
| 359 | return targets | - | ||||||||||||||||||
| 360 | */ | - | ||||||||||||||||||
| 361 | static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *transition, CalculationCache *cache) | - | ||||||||||||||||||
| 362 | { | - | ||||||||||||||||||
| 363 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 364 | - | |||||||||||||||||||
| 365 | QList<QAbstractState *> targetsList; | - | ||||||||||||||||||
| 366 | if (cache->effectiveTargetStates(transition, &targetsList))
| 1237-1394 | ||||||||||||||||||
| 367 | return targetsList; executed 1237 times by 2 tests: return targetsList;Executed by:
| 1237 | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | QSet<QAbstractState *> targets; | - | ||||||||||||||||||
| 370 | const auto targetStates = transition->targetStates(); | - | ||||||||||||||||||
| 371 | for (QAbstractState *s : targetStates) { | - | ||||||||||||||||||
| 372 | if (QHistoryState *historyState = QStateMachinePrivate::toHistoryState(s)) {
| 9-1381 | ||||||||||||||||||
| 373 | QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(historyState)->configuration; | - | ||||||||||||||||||
| 374 | if (!historyConfiguration.isEmpty()) {
| 4-5 | ||||||||||||||||||
| 375 | // There is a saved history, so apply that. | - | ||||||||||||||||||
| 376 | targets.unite(historyConfiguration.toSet()); | - | ||||||||||||||||||
| 377 | } else if (QAbstractTransition *defaultTransition = historyState->defaultTransition()) { executed 5 times by 1 test: end of blockExecuted by:
| 1-5 | ||||||||||||||||||
| 378 | // No saved history, take all default transition targets. | - | ||||||||||||||||||
| 379 | targets.unite(defaultTransition->targetStates().toSet()); | - | ||||||||||||||||||
| 380 | } else { executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 381 | // Woops, we found a history state without a default state. That's not valid! | - | ||||||||||||||||||
| 382 | QStateMachinePrivate *m = QStateMachinePrivate::get(historyState->machine()); | - | ||||||||||||||||||
| 383 | m->setError(QStateMachine::NoDefaultStateInHistoryStateError, historyState); | - | ||||||||||||||||||
| 384 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 385 | } else { | - | ||||||||||||||||||
| 386 | targets.insert(s); | - | ||||||||||||||||||
| 387 | } executed 1381 times by 2 tests: end of blockExecuted by:
| 1381 | ||||||||||||||||||
| 388 | } | - | ||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | targetsList = targets.toList(); | - | ||||||||||||||||||
| 391 | cache->insert(transition, targetsList); | - | ||||||||||||||||||
| 392 | return targetsList; executed 1394 times by 2 tests: return targetsList;Executed by:
| 1394 | ||||||||||||||||||
| 393 | } | - | ||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | QStateMachinePrivate::QStateMachinePrivate() | - | ||||||||||||||||||
| 396 | { | - | ||||||||||||||||||
| 397 | isMachine = true; | - | ||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | state = NotRunning; | - | ||||||||||||||||||
| 400 | processing = false; | - | ||||||||||||||||||
| 401 | processingScheduled = false; | - | ||||||||||||||||||
| 402 | stop = false; | - | ||||||||||||||||||
| 403 | stopProcessingReason = EventQueueEmpty; | - | ||||||||||||||||||
| 404 | error = QStateMachine::NoError; | - | ||||||||||||||||||
| 405 | globalRestorePolicy = QState::DontRestoreProperties; | - | ||||||||||||||||||
| 406 | signalEventGenerator = 0; | - | ||||||||||||||||||
| 407 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 408 | animated = true; | - | ||||||||||||||||||
| 409 | #endif | - | ||||||||||||||||||
| 410 | } executed 145 times by 2 tests: end of blockExecuted by:
| 145 | ||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | QStateMachinePrivate::~QStateMachinePrivate() | - | ||||||||||||||||||
| 413 | { | - | ||||||||||||||||||
| 414 | qDeleteAll(internalEventQueue); | - | ||||||||||||||||||
| 415 | qDeleteAll(externalEventQueue); | - | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | for (QHash<int, DelayedEvent>::const_iterator it = delayedEvents.begin(), eit = delayedEvents.end(); it != eit; ++it) {
| 0-145 | ||||||||||||||||||
| 418 | delete it.value().event; | - | ||||||||||||||||||
| 419 | } never executed: end of block | 0 | ||||||||||||||||||
| 420 | } executed 145 times by 2 tests: end of blockExecuted by:
| 145 | ||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | QState *QStateMachinePrivate::rootState() const | - | ||||||||||||||||||
| 423 | { | - | ||||||||||||||||||
| 424 | return const_cast<QStateMachine*>(q_func()); executed 5261 times by 2 tests: return const_cast<QStateMachine*>(q_func());Executed by:
| 5261 | ||||||||||||||||||
| 425 | } | - | ||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | static QEvent *cloneEvent(QEvent *e) | - | ||||||||||||||||||
| 428 | { | - | ||||||||||||||||||
| 429 | switch (e->type()) { | - | ||||||||||||||||||
| 430 | case QEvent::None: never executed: case QEvent::None: | 0 | ||||||||||||||||||
| 431 | return new QEvent(*e); never executed: return new QEvent(*e); | 0 | ||||||||||||||||||
| 432 | case QEvent::Timer: executed 7 times by 1 test: case QEvent::Timer:Executed by:
| 7 | ||||||||||||||||||
| 433 | return new QTimerEvent(*static_cast<QTimerEvent*>(e)); executed 7 times by 1 test: return new QTimerEvent(*static_cast<QTimerEvent*>(e));Executed by:
| 7 | ||||||||||||||||||
| 434 | default: never executed: default: | 0 | ||||||||||||||||||
| 435 | Q_ASSERT_X(false, "cloneEvent()", "not implemented"); | - | ||||||||||||||||||
| 436 | break; never executed: break; | 0 | ||||||||||||||||||
| 437 | } | - | ||||||||||||||||||
| 438 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 439 | } | - | ||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | const QStateMachinePrivate::Handler qt_kernel_statemachine_handler = { | - | ||||||||||||||||||
| 442 | cloneEvent | - | ||||||||||||||||||
| 443 | }; | - | ||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | const QStateMachinePrivate::Handler *QStateMachinePrivate::handler = &qt_kernel_statemachine_handler; | - | ||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler() | - | ||||||||||||||||||
| 448 | { | - | ||||||||||||||||||
| 449 | return &qt_kernel_statemachine_handler; executed 7 times by 1 test: return &qt_kernel_statemachine_handler;Executed by:
| 7 | ||||||||||||||||||
| 450 | } | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | static int indexOfDescendant(QState *s, QAbstractState *desc) | - | ||||||||||||||||||
| 453 | { | - | ||||||||||||||||||
| 454 | QList<QAbstractState*> childStates = QStatePrivate::get(s)->childStates(); | - | ||||||||||||||||||
| 455 | for (int i = 0; i < childStates.size(); ++i) {
| 0-819 | ||||||||||||||||||
| 456 | QAbstractState *c = childStates.at(i); | - | ||||||||||||||||||
| 457 | if ((c == desc) || isDescendant(desc, c)) {
| 179-640 | ||||||||||||||||||
| 458 | return i; executed 514 times by 1 test: return i;Executed by:
| 514 | ||||||||||||||||||
| 459 | } | - | ||||||||||||||||||
| 460 | } executed 305 times by 1 test: end of blockExecuted by:
| 305 | ||||||||||||||||||
| 461 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 462 | } | - | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | bool QStateMachinePrivate::transitionStateEntryLessThan(QAbstractTransition *t1, QAbstractTransition *t2) | - | ||||||||||||||||||
| 465 | { | - | ||||||||||||||||||
| 466 | QState *s1 = t1->sourceState(), *s2 = t2->sourceState(); | - | ||||||||||||||||||
| 467 | if (s1 == s2) {
| 6-12 | ||||||||||||||||||
| 468 | QList<QAbstractTransition*> transitions = QStatePrivate::get(s1)->transitions(); | - | ||||||||||||||||||
| 469 | return transitions.indexOf(t1) < transitions.indexOf(t2); executed 6 times by 1 test: return transitions.indexOf(t1) < transitions.indexOf(t2);Executed by:
| 6 | ||||||||||||||||||
| 470 | } else if (isDescendant(s1, s2)) {
| 0-12 | ||||||||||||||||||
| 471 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 472 | } else if (isDescendant(s2, s1)) {
| 0-12 | ||||||||||||||||||
| 473 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 474 | } else { | - | ||||||||||||||||||
| 475 | Q_ASSERT(s1->machine() != 0); | - | ||||||||||||||||||
| 476 | QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); | - | ||||||||||||||||||
| 477 | QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); | - | ||||||||||||||||||
| 478 | Q_ASSERT(lca != 0); | - | ||||||||||||||||||
| 479 | int s1Depth = descendantDepth(s1, lca); | - | ||||||||||||||||||
| 480 | int s2Depth = descendantDepth(s2, lca); | - | ||||||||||||||||||
| 481 | if (s1Depth == s2Depth)
| 4-8 | ||||||||||||||||||
| 482 | return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2)); executed 8 times by 1 test: return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));Executed by:
| 8 | ||||||||||||||||||
| 483 | else | - | ||||||||||||||||||
| 484 | return s1Depth > s2Depth; executed 4 times by 1 test: return s1Depth > s2Depth;Executed by:
| 4 | ||||||||||||||||||
| 485 | } | - | ||||||||||||||||||
| 486 | } | - | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState *s2) | - | ||||||||||||||||||
| 489 | { | - | ||||||||||||||||||
| 490 | if (s1->parent() == s2->parent()) {
| 40-425 | ||||||||||||||||||
| 491 | return s1->parent()->children().indexOf(s1) executed 40 times by 1 test: return s1->parent()->children().indexOf(s1) < s2->parent()->children().indexOf(s2);Executed by:
| 40 | ||||||||||||||||||
| 492 | < s2->parent()->children().indexOf(s2); executed 40 times by 1 test: return s1->parent()->children().indexOf(s1) < s2->parent()->children().indexOf(s2);Executed by:
| 40 | ||||||||||||||||||
| 493 | } else if (isDescendant(s1, s2)) {
| 134-291 | ||||||||||||||||||
| 494 | return false; executed 134 times by 2 tests: return false;Executed by:
| 134 | ||||||||||||||||||
| 495 | } else if (isDescendant(s2, s1)) {
| 68-223 | ||||||||||||||||||
| 496 | return true; executed 68 times by 1 test: return true;Executed by:
| 68 | ||||||||||||||||||
| 497 | } else { | - | ||||||||||||||||||
| 498 | Q_ASSERT(s1->machine() != 0); | - | ||||||||||||||||||
| 499 | QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); | - | ||||||||||||||||||
| 500 | QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); | - | ||||||||||||||||||
| 501 | Q_ASSERT(lca != 0); | - | ||||||||||||||||||
| 502 | return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2)); executed 223 times by 1 test: return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));Executed by:
| 223 | ||||||||||||||||||
| 503 | } | - | ||||||||||||||||||
| 504 | } | - | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState *s2) | - | ||||||||||||||||||
| 507 | { | - | ||||||||||||||||||
| 508 | if (s1->parent() == s2->parent()) {
| 10-130 | ||||||||||||||||||
| 509 | return s2->parent()->children().indexOf(s2) executed 10 times by 1 test: return s2->parent()->children().indexOf(s2) < s1->parent()->children().indexOf(s1);Executed by:
| 10 | ||||||||||||||||||
| 510 | < s1->parent()->children().indexOf(s1); executed 10 times by 1 test: return s2->parent()->children().indexOf(s2) < s1->parent()->children().indexOf(s1);Executed by:
| 10 | ||||||||||||||||||
| 511 | } else if (isDescendant(s1, s2)) {
| 50-80 | ||||||||||||||||||
| 512 | return true; executed 50 times by 2 tests: return true;Executed by:
| 50 | ||||||||||||||||||
| 513 | } else if (isDescendant(s2, s1)) {
| 26-54 | ||||||||||||||||||
| 514 | return false; executed 54 times by 2 tests: return false;Executed by:
| 54 | ||||||||||||||||||
| 515 | } else { | - | ||||||||||||||||||
| 516 | Q_ASSERT(s1->machine() != 0); | - | ||||||||||||||||||
| 517 | QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); | - | ||||||||||||||||||
| 518 | QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); | - | ||||||||||||||||||
| 519 | Q_ASSERT(lca != 0); | - | ||||||||||||||||||
| 520 | return (indexOfDescendant(lca, s2) < indexOfDescendant(lca, s1)); executed 26 times by 1 test: return (indexOfDescendant(lca, s2) < indexOfDescendant(lca, s1));Executed by:
| 26 | ||||||||||||||||||
| 521 | } | - | ||||||||||||||||||
| 522 | } | - | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | QState *QStateMachinePrivate::findLCA(const QList<QAbstractState*> &states, bool onlyCompound) const | - | ||||||||||||||||||
| 525 | { | - | ||||||||||||||||||
| 526 | if (states.isEmpty())
| 0-1652 | ||||||||||||||||||
| 527 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 528 | QVector<QState*> ancestors = getProperAncestors(states.at(0), rootState()->parentState()); | - | ||||||||||||||||||
| 529 | for (int i = 0; i < ancestors.size(); ++i) {
| 4-1931 | ||||||||||||||||||
| 530 | QState *anc = ancestors.at(i); | - | ||||||||||||||||||
| 531 | if (onlyCompound && !isCompound(anc))
| 12-1415 | ||||||||||||||||||
| 532 | continue; executed 12 times by 1 test: continue;Executed by:
| 12 | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | bool ok = true; | - | ||||||||||||||||||
| 535 | for (int j = states.size() - 1; (j > 0) && ok; --j) {
| 0-1919 | ||||||||||||||||||
| 536 | const QAbstractState *s = states.at(j); | - | ||||||||||||||||||
| 537 | if (!isDescendant(s, anc))
| 271-1497 | ||||||||||||||||||
| 538 | ok = false; executed 271 times by 1 test: ok = false;Executed by:
| 271 | ||||||||||||||||||
| 539 | } executed 1768 times by 2 tests: end of blockExecuted by:
| 1768 | ||||||||||||||||||
| 540 | if (ok)
| 271-1648 | ||||||||||||||||||
| 541 | return anc; executed 1648 times by 2 tests: return anc;Executed by:
| 1648 | ||||||||||||||||||
| 542 | } executed 271 times by 1 test: end of blockExecuted by:
| 271 | ||||||||||||||||||
| 543 | return 0; executed 4 times by 1 test: return 0;Executed by:
| 4 | ||||||||||||||||||
| 544 | } | - | ||||||||||||||||||
| 545 | - | |||||||||||||||||||
| 546 | QState *QStateMachinePrivate::findLCCA(const QList<QAbstractState*> &states) const | - | ||||||||||||||||||
| 547 | { | - | ||||||||||||||||||
| 548 | return findLCA(states, true); executed 1391 times by 2 tests: return findLCA(states, true);Executed by:
| 1391 | ||||||||||||||||||
| 549 | } | - | ||||||||||||||||||
| 550 | - | |||||||||||||||||||
| 551 | QList<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *event, CalculationCache *cache) | - | ||||||||||||||||||
| 552 | { | - | ||||||||||||||||||
| 553 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 554 | Q_Q(const QStateMachine); | - | ||||||||||||||||||
| 555 | - | |||||||||||||||||||
| 556 | QVarLengthArray<QAbstractState *> configuration_sorted; | - | ||||||||||||||||||
| 557 | for (QAbstractState *s : qAsConst(configuration)) { | - | ||||||||||||||||||
| 558 | if (isAtomic(s))
| 386-3838 | ||||||||||||||||||
| 559 | configuration_sorted.append(s); executed 3838 times by 2 tests: configuration_sorted.append(s);Executed by:
| 3838 | ||||||||||||||||||
| 560 | } executed 4224 times by 2 tests: end of blockExecuted by:
| 4224 | ||||||||||||||||||
| 561 | std::sort(configuration_sorted.begin(), configuration_sorted.end(), stateEntryLessThan); | - | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | QList<QAbstractTransition*> enabledTransitions; | - | ||||||||||||||||||
| 564 | const_cast<QStateMachine*>(q)->beginSelectTransitions(event); | - | ||||||||||||||||||
| 565 | for (QAbstractState *state : qAsConst(configuration_sorted)) { | - | ||||||||||||||||||
| 566 | QVector<QState*> lst = getProperAncestors(state, Q_NULLPTR); | - | ||||||||||||||||||
| 567 | if (QState *grp = toStandardState(state))
| 23-3815 | ||||||||||||||||||
| 568 | lst.prepend(grp); executed 3815 times by 2 tests: lst.prepend(grp);Executed by:
| 3815 | ||||||||||||||||||
| 569 | bool found = false; | - | ||||||||||||||||||
| 570 | for (int j = 0; (j < lst.size()) && !found; ++j) {
| 1244-8136 | ||||||||||||||||||
| 571 | QState *s = lst.at(j); | - | ||||||||||||||||||
| 572 | QList<QAbstractTransition*> transitions = QStatePrivate::get(s)->transitions(); | - | ||||||||||||||||||
| 573 | for (int k = 0; k < transitions.size(); ++k) {
| 5648-5945 | ||||||||||||||||||
| 574 | QAbstractTransition *t = transitions.at(k); | - | ||||||||||||||||||
| 575 | if (QAbstractTransitionPrivate::get(t)->callEventTest(event)) {
| 1244-4701 | ||||||||||||||||||
| 576 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 577 | qDebug() << q << ": selecting transition" << t; | - | ||||||||||||||||||
| 578 | #endif | - | ||||||||||||||||||
| 579 | enabledTransitions.append(t); | - | ||||||||||||||||||
| 580 | found = true; | - | ||||||||||||||||||
| 581 | break; executed 1244 times by 2 tests: break;Executed by:
| 1244 | ||||||||||||||||||
| 582 | } | - | ||||||||||||||||||
| 583 | } executed 4701 times by 2 tests: end of blockExecuted by:
| 4701 | ||||||||||||||||||
| 584 | } executed 6892 times by 2 tests: end of blockExecuted by:
| 6892 | ||||||||||||||||||
| 585 | } executed 3838 times by 2 tests: end of blockExecuted by:
| 3838 | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | if (!enabledTransitions.isEmpty()) {
| 1235-2515 | ||||||||||||||||||
| 588 | removeConflictingTransitions(enabledTransitions, cache); | - | ||||||||||||||||||
| 589 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 590 | qDebug() << q << ": enabled transitions after removing conflicts:" << enabledTransitions; | - | ||||||||||||||||||
| 591 | #endif | - | ||||||||||||||||||
| 592 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 593 | const_cast<QStateMachine*>(q)->endSelectTransitions(event); | - | ||||||||||||||||||
| 594 | return enabledTransitions; executed 3750 times by 2 tests: return enabledTransitions;Executed by:
| 3750 | ||||||||||||||||||
| 595 | } | - | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 598 | - | |||||||||||||||||||
| 599 | function removeConflictingTransitions(enabledTransitions): | - | ||||||||||||||||||
| 600 | filteredTransitions = new OrderedSet() | - | ||||||||||||||||||
| 601 | // toList sorts the transitions in the order of the states that selected them | - | ||||||||||||||||||
| 602 | for t1 in enabledTransitions.toList(): | - | ||||||||||||||||||
| 603 | t1Preempted = false; | - | ||||||||||||||||||
| 604 | transitionsToRemove = new OrderedSet() | - | ||||||||||||||||||
| 605 | for t2 in filteredTransitions.toList(): | - | ||||||||||||||||||
| 606 | if computeExitSet([t1]).hasIntersection(computeExitSet([t2])): | - | ||||||||||||||||||
| 607 | if isDescendant(t1.source, t2.source): | - | ||||||||||||||||||
| 608 | transitionsToRemove.add(t2) | - | ||||||||||||||||||
| 609 | else: | - | ||||||||||||||||||
| 610 | t1Preempted = true | - | ||||||||||||||||||
| 611 | break | - | ||||||||||||||||||
| 612 | if not t1Preempted: | - | ||||||||||||||||||
| 613 | for t3 in transitionsToRemove.toList(): | - | ||||||||||||||||||
| 614 | filteredTransitions.delete(t3) | - | ||||||||||||||||||
| 615 | filteredTransitions.add(t1) | - | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | return filteredTransitions | - | ||||||||||||||||||
| 618 | - | |||||||||||||||||||
| 619 | Note: the implementation below does not build the transitionsToRemove, but removes them in-place. | - | ||||||||||||||||||
| 620 | */ | - | ||||||||||||||||||
| 621 | void QStateMachinePrivate::removeConflictingTransitions(QList<QAbstractTransition*> &enabledTransitions, CalculationCache *cache) | - | ||||||||||||||||||
| 622 | { | - | ||||||||||||||||||
| 623 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | if (enabledTransitions.size() < 2)
| 6-1229 | ||||||||||||||||||
| 626 | return; // There is no transition to conflict with. executed 1229 times by 2 tests: return;Executed by:
| 1229 | ||||||||||||||||||
| 627 | - | |||||||||||||||||||
| 628 | QList<QAbstractTransition*> filteredTransitions; | - | ||||||||||||||||||
| 629 | filteredTransitions.reserve(enabledTransitions.size()); | - | ||||||||||||||||||
| 630 | std::sort(enabledTransitions.begin(), enabledTransitions.end(), transitionStateEntryLessThan); | - | ||||||||||||||||||
| 631 | - | |||||||||||||||||||
| 632 | for (QAbstractTransition *t1 : qAsConst(enabledTransitions)) { | - | ||||||||||||||||||
| 633 | bool t1Preempted = false; | - | ||||||||||||||||||
| 634 | const QSet<QAbstractState*> exitSetT1 = computeExitSet_Unordered(t1, cache); | - | ||||||||||||||||||
| 635 | QList<QAbstractTransition*>::iterator t2It = filteredTransitions.begin(); | - | ||||||||||||||||||
| 636 | while (t2It != filteredTransitions.end()) {
| 9-10 | ||||||||||||||||||
| 637 | QAbstractTransition *t2 = *t2It; | - | ||||||||||||||||||
| 638 | if (t1 == t2) {
| 3-7 | ||||||||||||||||||
| 639 | // Special case: someone added the same transition object to a state twice. In this | - | ||||||||||||||||||
| 640 | // case, t2 (which is already in the list) "preempts" t1. | - | ||||||||||||||||||
| 641 | t1Preempted = true; | - | ||||||||||||||||||
| 642 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 643 | } | - | ||||||||||||||||||
| 644 | - | |||||||||||||||||||
| 645 | QSet<QAbstractState*> exitSetT2 = computeExitSet_Unordered(t2, cache); | - | ||||||||||||||||||
| 646 | if (!exitSetT1.intersects(exitSetT2)) {
| 3-4 | ||||||||||||||||||
| 647 | // No conflict, no cry. Next patient please. | - | ||||||||||||||||||
| 648 | ++t2It; | - | ||||||||||||||||||
| 649 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 650 | // Houston, we have a conflict. Check which transition can be removed. | - | ||||||||||||||||||
| 651 | if (isDescendant(t1->sourceState(), t2->sourceState())) {
| 0-3 | ||||||||||||||||||
| 652 | // t1 preempts t2, so we can remove t2 | - | ||||||||||||||||||
| 653 | t2It = filteredTransitions.erase(t2It); | - | ||||||||||||||||||
| 654 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 655 | // t2 preempts t1, so there's no use in looking further and we don't need to add | - | ||||||||||||||||||
| 656 | // t1 to the list. | - | ||||||||||||||||||
| 657 | t1Preempted = true; | - | ||||||||||||||||||
| 658 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 659 | } | - | ||||||||||||||||||
| 660 | } | - | ||||||||||||||||||
| 661 | } | - | ||||||||||||||||||
| 662 | if (!t1Preempted)
| 6-9 | ||||||||||||||||||
| 663 | filteredTransitions.append(t1); executed 9 times by 1 test: filteredTransitions.append(t1);Executed by:
| 9 | ||||||||||||||||||
| 664 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | enabledTransitions = filteredTransitions; | - | ||||||||||||||||||
| 667 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 668 | - | |||||||||||||||||||
| 669 | void QStateMachinePrivate::microstep(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions, | - | ||||||||||||||||||
| 670 | CalculationCache *cache) | - | ||||||||||||||||||
| 671 | { | - | ||||||||||||||||||
| 672 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 673 | - | |||||||||||||||||||
| 674 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 675 | qDebug() << q_func() << ": begin microstep( enabledTransitions:" << enabledTransitions << ')'; | - | ||||||||||||||||||
| 676 | qDebug() << q_func() << ": configuration before exiting states:" << configuration; | - | ||||||||||||||||||
| 677 | #endif | - | ||||||||||||||||||
| 678 | QList<QAbstractState*> exitedStates = computeExitSet(enabledTransitions, cache); | - | ||||||||||||||||||
| 679 | QHash<RestorableId, QVariant> pendingRestorables = computePendingRestorables(exitedStates); | - | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | QSet<QAbstractState*> statesForDefaultEntry; | - | ||||||||||||||||||
| 682 | QList<QAbstractState*> enteredStates = computeEntrySet(enabledTransitions, statesForDefaultEntry, cache); | - | ||||||||||||||||||
| 683 | - | |||||||||||||||||||
| 684 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 685 | qDebug() << q_func() << ": computed exit set:" << exitedStates; | - | ||||||||||||||||||
| 686 | qDebug() << q_func() << ": computed entry set:" << enteredStates; | - | ||||||||||||||||||
| 687 | #endif | - | ||||||||||||||||||
| 688 | - | |||||||||||||||||||
| 689 | QHash<QAbstractState*, QVector<QPropertyAssignment> > assignmentsForEnteredStates = | - | ||||||||||||||||||
| 690 | computePropertyAssignments(enteredStates, pendingRestorables); | - | ||||||||||||||||||
| 691 | if (!pendingRestorables.isEmpty()) {
| 23-1212 | ||||||||||||||||||
| 692 | // Add "implicit" assignments for restored properties to the first | - | ||||||||||||||||||
| 693 | // (outermost) entered state | - | ||||||||||||||||||
| 694 | Q_ASSERT(!enteredStates.isEmpty()); | - | ||||||||||||||||||
| 695 | QAbstractState *s = enteredStates.constFirst(); | - | ||||||||||||||||||
| 696 | assignmentsForEnteredStates[s] << restorablesToPropertyList(pendingRestorables); | - | ||||||||||||||||||
| 697 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | exitStates(event, exitedStates, assignmentsForEnteredStates); | - | ||||||||||||||||||
| 700 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 701 | qDebug() << q_func() << ": configuration after exiting states:" << configuration; | - | ||||||||||||||||||
| 702 | #endif | - | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | executeTransitionContent(event, enabledTransitions); | - | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 707 | QList<QAbstractAnimation *> selectedAnimations = selectAnimations(enabledTransitions); | - | ||||||||||||||||||
| 708 | #endif | - | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | enterStates(event, exitedStates, enteredStates, statesForDefaultEntry, assignmentsForEnteredStates | - | ||||||||||||||||||
| 711 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 712 | , selectedAnimations | - | ||||||||||||||||||
| 713 | #endif | - | ||||||||||||||||||
| 714 | ); | - | ||||||||||||||||||
| 715 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 716 | qDebug() << q_func() << ": configuration after entering states:" << configuration; | - | ||||||||||||||||||
| 717 | qDebug() << q_func() << ": end microstep"; | - | ||||||||||||||||||
| 718 | #endif | - | ||||||||||||||||||
| 719 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 720 | - | |||||||||||||||||||
| 721 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | procedure computeExitSet(enabledTransitions) | - | ||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | For each transition t in enabledTransitions, if t is targetless then do nothing, else compute the | - | ||||||||||||||||||
| 726 | transition's domain. (This will be the source state in the case of internal transitions) or the | - | ||||||||||||||||||
| 727 | least common compound ancestor state of the source state and target states of t (in the case of | - | ||||||||||||||||||
| 728 | external transitions. Add to the statesToExit set all states in the configuration that are | - | ||||||||||||||||||
| 729 | descendants of the domain. | - | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | function computeExitSet(transitions) | - | ||||||||||||||||||
| 732 | statesToExit = new OrderedSet | - | ||||||||||||||||||
| 733 | for t in transitions: | - | ||||||||||||||||||
| 734 | if (t.target): | - | ||||||||||||||||||
| 735 | domain = getTransitionDomain(t) | - | ||||||||||||||||||
| 736 | for s in configuration: | - | ||||||||||||||||||
| 737 | if isDescendant(s,domain): | - | ||||||||||||||||||
| 738 | statesToExit.add(s) | - | ||||||||||||||||||
| 739 | return statesToExit | - | ||||||||||||||||||
| 740 | */ | - | ||||||||||||||||||
| 741 | QList<QAbstractState*> QStateMachinePrivate::computeExitSet(const QList<QAbstractTransition*> &enabledTransitions, | - | ||||||||||||||||||
| 742 | CalculationCache *cache) | - | ||||||||||||||||||
| 743 | { | - | ||||||||||||||||||
| 744 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 745 | - | |||||||||||||||||||
| 746 | QList<QAbstractState*> statesToExit_sorted = computeExitSet_Unordered(enabledTransitions, cache).toList(); | - | ||||||||||||||||||
| 747 | std::sort(statesToExit_sorted.begin(), statesToExit_sorted.end(), stateExitLessThan); | - | ||||||||||||||||||
| 748 | return statesToExit_sorted; executed 1235 times by 2 tests: return statesToExit_sorted;Executed by:
| 1235 | ||||||||||||||||||
| 749 | } | - | ||||||||||||||||||
| 750 | - | |||||||||||||||||||
| 751 | QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(const QList<QAbstractTransition*> &enabledTransitions, | - | ||||||||||||||||||
| 752 | CalculationCache *cache) | - | ||||||||||||||||||
| 753 | { | - | ||||||||||||||||||
| 754 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 755 | - | |||||||||||||||||||
| 756 | QSet<QAbstractState*> statesToExit; | - | ||||||||||||||||||
| 757 | for (QAbstractTransition *t : enabledTransitions) | - | ||||||||||||||||||
| 758 | statesToExit.unite(computeExitSet_Unordered(t, cache)); executed 1238 times by 2 tests: statesToExit.unite(computeExitSet_Unordered(t, cache));Executed by:
| 1238 | ||||||||||||||||||
| 759 | return statesToExit; executed 1235 times by 2 tests: return statesToExit;Executed by:
| 1235 | ||||||||||||||||||
| 760 | } | - | ||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(QAbstractTransition *t, | - | ||||||||||||||||||
| 763 | CalculationCache *cache) | - | ||||||||||||||||||
| 764 | { | - | ||||||||||||||||||
| 765 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 766 | - | |||||||||||||||||||
| 767 | QSet<QAbstractState*> statesToExit; | - | ||||||||||||||||||
| 768 | if (cache->exitSet(t, &statesToExit))
| 19-1241 | ||||||||||||||||||
| 769 | return statesToExit; executed 19 times by 1 test: return statesToExit;Executed by:
| 19 | ||||||||||||||||||
| 770 | - | |||||||||||||||||||
| 771 | QList<QAbstractState *> effectiveTargetStates = getEffectiveTargetStates(t, cache); | - | ||||||||||||||||||
| 772 | QAbstractState *domain = getTransitionDomain(t, effectiveTargetStates, cache); | - | ||||||||||||||||||
| 773 | if (domain == Q_NULLPTR && !t->targetStates().isEmpty()) {
| 4-1232 | ||||||||||||||||||
| 774 | // So we didn't find the least common ancestor for the source and target states of the | - | ||||||||||||||||||
| 775 | // transition. If there were not target states, that would be fine: then the transition | - | ||||||||||||||||||
| 776 | // will fire any events or signals, but not exit the state. | - | ||||||||||||||||||
| 777 | // | - | ||||||||||||||||||
| 778 | // However, there are target states, so it's either a node without a parent (or parent's | - | ||||||||||||||||||
| 779 | // parent, etc), or the state belongs to a different state machine. Either way, this | - | ||||||||||||||||||
| 780 | // makes the state machine invalid. | - | ||||||||||||||||||
| 781 | if (error == QStateMachine::NoError)
| 1-3 | ||||||||||||||||||
| 782 | setError(QStateMachine::NoCommonAncestorForTransitionError, t->sourceState()); executed 3 times by 1 test: setError(QStateMachine::NoCommonAncestorForTransitionError, t->sourceState());Executed by:
| 3 | ||||||||||||||||||
| 783 | QList<QAbstractState *> lst = pendingErrorStates.toList(); | - | ||||||||||||||||||
| 784 | lst.prepend(t->sourceState()); | - | ||||||||||||||||||
| 785 | - | |||||||||||||||||||
| 786 | domain = findLCCA(lst); | - | ||||||||||||||||||
| 787 | Q_ASSERT(domain != 0); | - | ||||||||||||||||||
| 788 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | for (QAbstractState* s : qAsConst(configuration)) { | - | ||||||||||||||||||
| 791 | if (isDescendant(s, domain))
| 104-1315 | ||||||||||||||||||
| 792 | statesToExit.insert(s); executed 1315 times by 2 tests: statesToExit.insert(s);Executed by:
| 1315 | ||||||||||||||||||
| 793 | } executed 1419 times by 2 tests: end of blockExecuted by:
| 1419 | ||||||||||||||||||
| 794 | - | |||||||||||||||||||
| 795 | cache->insert(t, statesToExit); | - | ||||||||||||||||||
| 796 | return statesToExit; executed 1241 times by 2 tests: return statesToExit;Executed by:
| 1241 | ||||||||||||||||||
| 797 | } | - | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | void QStateMachinePrivate::exitStates(QEvent *event, const QList<QAbstractState*> &statesToExit_sorted, | - | ||||||||||||||||||
| 800 | const QHash<QAbstractState*, QVector<QPropertyAssignment> > &assignmentsForEnteredStates) | - | ||||||||||||||||||
| 801 | { | - | ||||||||||||||||||
| 802 | for (int i = 0; i < statesToExit_sorted.size(); ++i) {
| 1235-1298 | ||||||||||||||||||
| 803 | QAbstractState *s = statesToExit_sorted.at(i); | - | ||||||||||||||||||
| 804 | if (QState *grp = toStandardState(s)) {
| 7-1291 | ||||||||||||||||||
| 805 | QList<QHistoryState*> hlst = QStatePrivate::get(grp)->historyStates(); | - | ||||||||||||||||||
| 806 | for (int j = 0; j < hlst.size(); ++j) {
| 9-1291 | ||||||||||||||||||
| 807 | QHistoryState *h = hlst.at(j); | - | ||||||||||||||||||
| 808 | QHistoryStatePrivate::get(h)->configuration.clear(); | - | ||||||||||||||||||
| 809 | QSet<QAbstractState*>::const_iterator it; | - | ||||||||||||||||||
| 810 | for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
| 9-27 | ||||||||||||||||||
| 811 | QAbstractState *s0 = *it; | - | ||||||||||||||||||
| 812 | if (QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) {
| 11-16 | ||||||||||||||||||
| 813 | if (isAtomic(s0) && isDescendant(s0, s))
| 0-6 | ||||||||||||||||||
| 814 | QHistoryStatePrivate::get(h)->configuration.append(s0); executed 5 times by 1 test: QHistoryStatePrivate::get(h)->configuration.append(s0);Executed by:
| 5 | ||||||||||||||||||
| 815 | } else if (s0->parentState() == s) { executed 11 times by 1 test: end of blockExecuted by:
| 8-11 | ||||||||||||||||||
| 816 | QHistoryStatePrivate::get(h)->configuration.append(s0); | - | ||||||||||||||||||
| 817 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 818 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 819 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 820 | qDebug() << q_func() << ": recorded" << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow") | - | ||||||||||||||||||
| 821 | << "history for" << s << "in" << h << ':' << QHistoryStatePrivate::get(h)->configuration; | - | ||||||||||||||||||
| 822 | #endif | - | ||||||||||||||||||
| 823 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 824 | } executed 1291 times by 2 tests: end of blockExecuted by:
| 1291 | ||||||||||||||||||
| 825 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 826 | for (int i = 0; i < statesToExit_sorted.size(); ++i) {
| 1235-1298 | ||||||||||||||||||
| 827 | QAbstractState *s = statesToExit_sorted.at(i); | - | ||||||||||||||||||
| 828 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 829 | qDebug() << q_func() << ": exiting" << s; | - | ||||||||||||||||||
| 830 | #endif | - | ||||||||||||||||||
| 831 | QAbstractStatePrivate::get(s)->callOnExit(event); | - | ||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 834 | terminateActiveAnimations(s, assignmentsForEnteredStates); | - | ||||||||||||||||||
| 835 | #else | - | ||||||||||||||||||
| 836 | Q_UNUSED(assignmentsForEnteredStates); | - | ||||||||||||||||||
| 837 | #endif | - | ||||||||||||||||||
| 838 | - | |||||||||||||||||||
| 839 | configuration.remove(s); | - | ||||||||||||||||||
| 840 | QAbstractStatePrivate::get(s)->emitExited(); | - | ||||||||||||||||||
| 841 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 842 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 843 | - | |||||||||||||||||||
| 844 | void QStateMachinePrivate::executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions) | - | ||||||||||||||||||
| 845 | { | - | ||||||||||||||||||
| 846 | for (int i = 0; i < enabledTransitions.size(); ++i) {
| 1388-1391 | ||||||||||||||||||
| 847 | QAbstractTransition *t = enabledTransitions.at(i); | - | ||||||||||||||||||
| 848 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 849 | qDebug() << q_func() << ": triggering" << t; | - | ||||||||||||||||||
| 850 | #endif | - | ||||||||||||||||||
| 851 | QAbstractTransitionPrivate::get(t)->callOnTransition(event); | - | ||||||||||||||||||
| 852 | QAbstractTransitionPrivate::get(t)->emitTriggered(); | - | ||||||||||||||||||
| 853 | } executed 1391 times by 2 tests: end of blockExecuted by:
| 1391 | ||||||||||||||||||
| 854 | } executed 1388 times by 2 tests: end of blockExecuted by:
| 1388 | ||||||||||||||||||
| 855 | - | |||||||||||||||||||
| 856 | QList<QAbstractState*> QStateMachinePrivate::computeEntrySet(const QList<QAbstractTransition *> &enabledTransitions, | - | ||||||||||||||||||
| 857 | QSet<QAbstractState *> &statesForDefaultEntry, | - | ||||||||||||||||||
| 858 | CalculationCache *cache) | - | ||||||||||||||||||
| 859 | { | - | ||||||||||||||||||
| 860 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | QSet<QAbstractState*> statesToEnter; | - | ||||||||||||||||||
| 863 | if (pendingErrorStates.isEmpty()) {
| 1-1387 | ||||||||||||||||||
| 864 | for (QAbstractTransition *t : enabledTransitions) { | - | ||||||||||||||||||
| 865 | const auto targetStates = t->targetStates(); | - | ||||||||||||||||||
| 866 | for (QAbstractState *s : targetStates) | - | ||||||||||||||||||
| 867 | addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); executed 1386 times by 2 tests: addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);Executed by:
| 1386 | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | const QList<QAbstractState *> effectiveTargetStates = getEffectiveTargetStates(t, cache); | - | ||||||||||||||||||
| 870 | QAbstractState *ancestor = getTransitionDomain(t, effectiveTargetStates, cache); | - | ||||||||||||||||||
| 871 | for (QAbstractState *s : effectiveTargetStates) | - | ||||||||||||||||||
| 872 | addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry); executed 1390 times by 2 tests: addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry);Executed by:
| 1390 | ||||||||||||||||||
| 873 | } executed 1390 times by 2 tests: end of blockExecuted by:
| 1390 | ||||||||||||||||||
| 874 | } executed 1387 times by 2 tests: end of blockExecuted by:
| 1387 | ||||||||||||||||||
| 875 | - | |||||||||||||||||||
| 876 | // Did an error occur while selecting transitions? Then we enter the error state. | - | ||||||||||||||||||
| 877 | if (!pendingErrorStates.isEmpty()) {
| 9-1379 | ||||||||||||||||||
| 878 | statesToEnter.clear(); | - | ||||||||||||||||||
| 879 | statesToEnter = pendingErrorStates; | - | ||||||||||||||||||
| 880 | statesForDefaultEntry = pendingErrorStatesForDefaultEntry; | - | ||||||||||||||||||
| 881 | pendingErrorStates.clear(); | - | ||||||||||||||||||
| 882 | pendingErrorStatesForDefaultEntry.clear(); | - | ||||||||||||||||||
| 883 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 884 | - | |||||||||||||||||||
| 885 | QList<QAbstractState*> statesToEnter_sorted = statesToEnter.toList(); | - | ||||||||||||||||||
| 886 | std::sort(statesToEnter_sorted.begin(), statesToEnter_sorted.end(), stateEntryLessThan); | - | ||||||||||||||||||
| 887 | return statesToEnter_sorted; executed 1388 times by 2 tests: return statesToEnter_sorted;Executed by:
| 1388 | ||||||||||||||||||
| 888 | } | - | ||||||||||||||||||
| 889 | - | |||||||||||||||||||
| 890 | /* The algorithm as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 891 | - | |||||||||||||||||||
| 892 | function getTransitionDomain(transition) | - | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | Return the compound state such that 1) all states that are exited or entered as a result of taking | - | ||||||||||||||||||
| 895 | 'transition' are descendants of it 2) no descendant of it has this property. | - | ||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | function getTransitionDomain(t) | - | ||||||||||||||||||
| 898 | tstates = getEffectiveTargetStates(t) | - | ||||||||||||||||||
| 899 | if not tstates: | - | ||||||||||||||||||
| 900 | return null | - | ||||||||||||||||||
| 901 | elif t.type == "internal" and isCompoundState(t.source) and tstates.every(lambda s: isDescendant(s,t.source)): | - | ||||||||||||||||||
| 902 | return t.source | - | ||||||||||||||||||
| 903 | else: | - | ||||||||||||||||||
| 904 | return findLCCA([t.source].append(tstates)) | - | ||||||||||||||||||
| 905 | */ | - | ||||||||||||||||||
| 906 | QAbstractState *QStateMachinePrivate::getTransitionDomain(QAbstractTransition *t, | - | ||||||||||||||||||
| 907 | const QList<QAbstractState *> &effectiveTargetStates, | - | ||||||||||||||||||
| 908 | CalculationCache *cache) const | - | ||||||||||||||||||
| 909 | { | - | ||||||||||||||||||
| 910 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 911 | - | |||||||||||||||||||
| 912 | if (effectiveTargetStates.isEmpty())
| 11-2620 | ||||||||||||||||||
| 913 | return 0; executed 11 times by 1 test: return 0;Executed by:
| 11 | ||||||||||||||||||
| 914 | - | |||||||||||||||||||
| 915 | QAbstractState *domain = Q_NULLPTR; | - | ||||||||||||||||||
| 916 | if (cache->transitionDomain(t, &domain))
| 1231-1389 | ||||||||||||||||||
| 917 | return domain; executed 1231 times by 2 tests: return domain;Executed by:
| 1231 | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | if (t->transitionType() == QAbstractTransition::InternalTransition) {
| 2-1387 | ||||||||||||||||||
| 920 | if (QState *tSource = t->sourceState()) {
| 0-2 | ||||||||||||||||||
| 921 | if (isCompound(tSource)) {
| 0-2 | ||||||||||||||||||
| 922 | bool allDescendants = true; | - | ||||||||||||||||||
| 923 | for (QAbstractState *s : effectiveTargetStates) { | - | ||||||||||||||||||
| 924 | if (!isDescendant(s, tSource)) {
| 0-2 | ||||||||||||||||||
| 925 | allDescendants = false; | - | ||||||||||||||||||
| 926 | break; never executed: break; | 0 | ||||||||||||||||||
| 927 | } | - | ||||||||||||||||||
| 928 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 929 | - | |||||||||||||||||||
| 930 | if (allDescendants)
| 0-2 | ||||||||||||||||||
| 931 | return tSource; executed 2 times by 1 test: return tSource;Executed by:
| 2 | ||||||||||||||||||
| 932 | } never executed: end of block | 0 | ||||||||||||||||||
| 933 | } never executed: end of block | 0 | ||||||||||||||||||
| 934 | } never executed: end of block | 0 | ||||||||||||||||||
| 935 | - | |||||||||||||||||||
| 936 | QList<QAbstractState *> states(effectiveTargetStates); | - | ||||||||||||||||||
| 937 | if (QAbstractState *src = t->sourceState())
| 153-1234 | ||||||||||||||||||
| 938 | states.prepend(src); executed 1234 times by 2 tests: states.prepend(src);Executed by:
| 1234 | ||||||||||||||||||
| 939 | domain = findLCCA(states); | - | ||||||||||||||||||
| 940 | cache->insert(t, domain); | - | ||||||||||||||||||
| 941 | return domain; executed 1387 times by 2 tests: return domain;Executed by:
| 1387 | ||||||||||||||||||
| 942 | } | - | ||||||||||||||||||
| 943 | - | |||||||||||||||||||
| 944 | void QStateMachinePrivate::enterStates(QEvent *event, const QList<QAbstractState*> &exitedStates_sorted, | - | ||||||||||||||||||
| 945 | const QList<QAbstractState*> &statesToEnter_sorted, | - | ||||||||||||||||||
| 946 | const QSet<QAbstractState*> &statesForDefaultEntry, | - | ||||||||||||||||||
| 947 | QHash<QAbstractState*, QVector<QPropertyAssignment> > &propertyAssignmentsForState | - | ||||||||||||||||||
| 948 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 949 | , const QList<QAbstractAnimation *> &selectedAnimations | - | ||||||||||||||||||
| 950 | #endif | - | ||||||||||||||||||
| 951 | ) | - | ||||||||||||||||||
| 952 | { | - | ||||||||||||||||||
| 953 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 954 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 955 | #endif | - | ||||||||||||||||||
| 956 | for (int i = 0; i < statesToEnter_sorted.size(); ++i) {
| 1388-1507 | ||||||||||||||||||
| 957 | QAbstractState *s = statesToEnter_sorted.at(i); | - | ||||||||||||||||||
| 958 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 959 | qDebug() << q << ": entering" << s; | - | ||||||||||||||||||
| 960 | #endif | - | ||||||||||||||||||
| 961 | configuration.insert(s); | - | ||||||||||||||||||
| 962 | registerTransitions(s); | - | ||||||||||||||||||
| 963 | - | |||||||||||||||||||
| 964 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 965 | initializeAnimations(s, selectedAnimations, exitedStates_sorted, propertyAssignmentsForState); | - | ||||||||||||||||||
| 966 | #endif | - | ||||||||||||||||||
| 967 | - | |||||||||||||||||||
| 968 | // Immediately set the properties that are not animated. | - | ||||||||||||||||||
| 969 | { | - | ||||||||||||||||||
| 970 | QVector<QPropertyAssignment> assignments = propertyAssignmentsForState.value(s); | - | ||||||||||||||||||
| 971 | for (int i = 0; i < assignments.size(); ++i) {
| 97-1507 | ||||||||||||||||||
| 972 | const QPropertyAssignment &assn = assignments.at(i); | - | ||||||||||||||||||
| 973 | if (globalRestorePolicy == QState::RestoreProperties) {
| 43-54 | ||||||||||||||||||
| 974 | if (assn.explicitlySet) {
| 18-36 | ||||||||||||||||||
| 975 | if (!hasRestorable(s, assn.object, assn.propertyName)) {
| 2-34 | ||||||||||||||||||
| 976 | QVariant value = savedValueForRestorable(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 977 | unregisterRestorables(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 978 | registerRestorable(s, assn.object, assn.propertyName, value); | - | ||||||||||||||||||
| 979 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 980 | } else { executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 981 | // The property is being restored, hence no need to | - | ||||||||||||||||||
| 982 | // save the current value. Discard any saved values in | - | ||||||||||||||||||
| 983 | // exited states, since those are now stale. | - | ||||||||||||||||||
| 984 | unregisterRestorables(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 985 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 986 | } | - | ||||||||||||||||||
| 987 | assn.write(); | - | ||||||||||||||||||
| 988 | } executed 97 times by 2 tests: end of blockExecuted by:
| 97 | ||||||||||||||||||
| 989 | } | - | ||||||||||||||||||
| 990 | - | |||||||||||||||||||
| 991 | QAbstractStatePrivate::get(s)->callOnEntry(event); | - | ||||||||||||||||||
| 992 | QAbstractStatePrivate::get(s)->emitEntered(); | - | ||||||||||||||||||
| 993 | - | |||||||||||||||||||
| 994 | // FIXME: | - | ||||||||||||||||||
| 995 | // See the "initial transitions" comment in addDescendantStatesToEnter first, then implement: | - | ||||||||||||||||||
| 996 | // if (statesForDefaultEntry.contains(s)) { | - | ||||||||||||||||||
| 997 | // // ### executeContent(s.initial.transition.children()) | - | ||||||||||||||||||
| 998 | // } | - | ||||||||||||||||||
| 999 | Q_UNUSED(statesForDefaultEntry); | - | ||||||||||||||||||
| 1000 | - | |||||||||||||||||||
| 1001 | if (QHistoryState *h = toHistoryState(s))
| 0-1507 | ||||||||||||||||||
| 1002 | QAbstractTransitionPrivate::get(h->defaultTransition())->callOnTransition(event); never executed: QAbstractTransitionPrivate::get(h->defaultTransition())->callOnTransition(event); | 0 | ||||||||||||||||||
| 1003 | - | |||||||||||||||||||
| 1004 | // Emit propertiesAssigned signal if the state has no animated properties. | - | ||||||||||||||||||
| 1005 | { | - | ||||||||||||||||||
| 1006 | QState *ss = toStandardState(s); | - | ||||||||||||||||||
| 1007 | if (ss
| 72-1435 | ||||||||||||||||||
| 1008 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1009 | && !animationsForState.contains(s)
| 32-1403 | ||||||||||||||||||
| 1010 | #endif | - | ||||||||||||||||||
| 1011 | ) | - | ||||||||||||||||||
| 1012 | QStatePrivate::get(ss)->emitPropertiesAssigned(); executed 1403 times by 2 tests: QStatePrivate::get(ss)->emitPropertiesAssigned();Executed by:
| 1403 | ||||||||||||||||||
| 1013 | } | - | ||||||||||||||||||
| 1014 | - | |||||||||||||||||||
| 1015 | if (isFinal(s)) {
| 72-1435 | ||||||||||||||||||
| 1016 | QState *parent = s->parentState(); | - | ||||||||||||||||||
| 1017 | if (parent) {
| 0-72 | ||||||||||||||||||
| 1018 | if (parent != rootState()) {
| 9-63 | ||||||||||||||||||
| 1019 | QFinalState *finalState = qobject_cast<QFinalState *>(s); | - | ||||||||||||||||||
| 1020 | Q_ASSERT(finalState); | - | ||||||||||||||||||
| 1021 | emitStateFinished(parent, finalState); | - | ||||||||||||||||||
| 1022 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 1023 | QState *grandparent = parent->parentState(); | - | ||||||||||||||||||
| 1024 | if (grandparent && isParallel(grandparent)) {
| 5-60 | ||||||||||||||||||
| 1025 | bool allChildStatesFinal = true; | - | ||||||||||||||||||
| 1026 | QList<QAbstractState*> childStates = QStatePrivate::get(grandparent)->childStates(); | - | ||||||||||||||||||
| 1027 | for (int j = 0; j < childStates.size(); ++j) {
| 3-16 | ||||||||||||||||||
| 1028 | QAbstractState *cs = childStates.at(j); | - | ||||||||||||||||||
| 1029 | if (!isInFinalState(cs)) {
| 4-12 | ||||||||||||||||||
| 1030 | allChildStatesFinal = false; | - | ||||||||||||||||||
| 1031 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 1032 | } | - | ||||||||||||||||||
| 1033 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1034 | if (allChildStatesFinal && (grandparent != rootState())) {
| 1-4 | ||||||||||||||||||
| 1035 | QFinalState *finalState = qobject_cast<QFinalState *>(s); | - | ||||||||||||||||||
| 1036 | Q_ASSERT(finalState); | - | ||||||||||||||||||
| 1037 | emitStateFinished(grandparent, finalState); | - | ||||||||||||||||||
| 1038 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1039 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 1040 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 1041 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 1042 | } executed 1507 times by 2 tests: end of blockExecuted by:
| 1507 | ||||||||||||||||||
| 1043 | { | - | ||||||||||||||||||
| 1044 | QSet<QAbstractState*>::const_iterator it; | - | ||||||||||||||||||
| 1045 | for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
| 1324-1591 | ||||||||||||||||||
| 1046 | if (isFinal(*it)) {
| 74-1517 | ||||||||||||||||||
| 1047 | QState *parent = (*it)->parentState(); | - | ||||||||||||||||||
| 1048 | if (((parent == rootState())
| 11-63 | ||||||||||||||||||
| 1049 | && (rootState()->childMode() == QState::ExclusiveStates))
| 0-63 | ||||||||||||||||||
| 1050 | || ((parent->parentState() == rootState())
| 3-8 | ||||||||||||||||||
| 1051 | && (rootState()->childMode() == QState::ParallelStates)
| 1-2 | ||||||||||||||||||
| 1052 | && isInFinalState(rootState()))) {
| 0-1 | ||||||||||||||||||
| 1053 | processing = false; | - | ||||||||||||||||||
| 1054 | stopProcessingReason = Finished; | - | ||||||||||||||||||
| 1055 | break; executed 64 times by 1 test: break;Executed by:
| 64 | ||||||||||||||||||
| 1056 | } | - | ||||||||||||||||||
| 1057 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1058 | } executed 1527 times by 2 tests: end of blockExecuted by:
| 1527 | ||||||||||||||||||
| 1059 | } | - | ||||||||||||||||||
| 1060 | // qDebug() << "configuration:" << configuration.toList(); | - | ||||||||||||||||||
| 1061 | } executed 1388 times by 2 tests: end of blockExecuted by:
| 1388 | ||||||||||||||||||
| 1062 | - | |||||||||||||||||||
| 1063 | /* The algorithm as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ has a bug. See | - | ||||||||||||||||||
| 1064 | * QTBUG-44963 for details. The algorithm here is as described in | - | ||||||||||||||||||
| 1065 | * http://www.w3.org/Voice/2013/scxml-irp/SCXML.htm as of Friday March 13, 2015. | - | ||||||||||||||||||
| 1066 | - | |||||||||||||||||||
| 1067 | procedure addDescendantStatesToEnter(state,statesToEnter,statesForDefaultEntry, defaultHistoryContent): | - | ||||||||||||||||||
| 1068 | if isHistoryState(state): | - | ||||||||||||||||||
| 1069 | if historyValue[state.id]: | - | ||||||||||||||||||
| 1070 | for s in historyValue[state.id]: | - | ||||||||||||||||||
| 1071 | addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1072 | for s in historyValue[state.id]: | - | ||||||||||||||||||
| 1073 | addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1074 | else: | - | ||||||||||||||||||
| 1075 | defaultHistoryContent[state.parent.id] = state.transition.content | - | ||||||||||||||||||
| 1076 | for s in state.transition.target: | - | ||||||||||||||||||
| 1077 | addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1078 | for s in state.transition.target: | - | ||||||||||||||||||
| 1079 | addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1080 | else: | - | ||||||||||||||||||
| 1081 | statesToEnter.add(state) | - | ||||||||||||||||||
| 1082 | if isCompoundState(state): | - | ||||||||||||||||||
| 1083 | statesForDefaultEntry.add(state) | - | ||||||||||||||||||
| 1084 | for s in state.initial.transition.target: | - | ||||||||||||||||||
| 1085 | addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1086 | for s in state.initial.transition.target: | - | ||||||||||||||||||
| 1087 | addAncestorStatesToEnter(s, state, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1088 | else: | - | ||||||||||||||||||
| 1089 | if isParallelState(state): | - | ||||||||||||||||||
| 1090 | for child in getChildStates(state): | - | ||||||||||||||||||
| 1091 | if not statesToEnter.some(lambda s: isDescendant(s,child)): | - | ||||||||||||||||||
| 1092 | addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1093 | */ | - | ||||||||||||||||||
| 1094 | void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state, | - | ||||||||||||||||||
| 1095 | QSet<QAbstractState*> &statesToEnter, | - | ||||||||||||||||||
| 1096 | QSet<QAbstractState*> &statesForDefaultEntry) | - | ||||||||||||||||||
| 1097 | { | - | ||||||||||||||||||
| 1098 | if (QHistoryState *h = toHistoryState(state)) {
| 13-1506 | ||||||||||||||||||
| 1099 | const QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(h)->configuration; | - | ||||||||||||||||||
| 1100 | if (!historyConfiguration.isEmpty()) {
| 6-7 | ||||||||||||||||||
| 1101 | for (QAbstractState *s : historyConfiguration) | - | ||||||||||||||||||
| 1102 | addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); executed 11 times by 2 tests: addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);Executed by:
| 11 | ||||||||||||||||||
| 1103 | for (QAbstractState *s : historyConfiguration) | - | ||||||||||||||||||
| 1104 | addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry); executed 11 times by 2 tests: addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry);Executed by:
| 11 | ||||||||||||||||||
| 1105 | - | |||||||||||||||||||
| 1106 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1107 | qDebug() << q_func() << ": restoring" | - | ||||||||||||||||||
| 1108 | << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow") | - | ||||||||||||||||||
| 1109 | << "history from" << state << ':' << historyConfiguration; | - | ||||||||||||||||||
| 1110 | #endif | - | ||||||||||||||||||
| 1111 | } else { executed 7 times by 2 tests: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 1112 | QList<QAbstractState*> defaultHistoryContent; | - | ||||||||||||||||||
| 1113 | if (QAbstractTransition *t = QHistoryStatePrivate::get(h)->defaultTransition)
| 0-6 | ||||||||||||||||||
| 1114 | defaultHistoryContent = t->targetStates(); executed 6 times by 2 tests: defaultHistoryContent = t->targetStates();Executed by:
| 6 | ||||||||||||||||||
| 1115 | - | |||||||||||||||||||
| 1116 | if (defaultHistoryContent.isEmpty()) {
| 0-6 | ||||||||||||||||||
| 1117 | setError(QStateMachine::NoDefaultStateInHistoryStateError, h); | - | ||||||||||||||||||
| 1118 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1119 | for (QAbstractState *s : qAsConst(defaultHistoryContent)) | - | ||||||||||||||||||
| 1120 | addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); executed 7 times by 2 tests: addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);Executed by:
| 7 | ||||||||||||||||||
| 1121 | for (QAbstractState *s : qAsConst(defaultHistoryContent)) | - | ||||||||||||||||||
| 1122 | addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry); executed 7 times by 2 tests: addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry);Executed by:
| 7 | ||||||||||||||||||
| 1123 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1124 | qDebug() << q_func() << ": initial history targets for" << state << ':' << defaultHistoryContent; | - | ||||||||||||||||||
| 1125 | #endif | - | ||||||||||||||||||
| 1126 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 1127 | } | - | ||||||||||||||||||
| 1128 | } else { | - | ||||||||||||||||||
| 1129 | if (state == rootState()) {
| 1-1505 | ||||||||||||||||||
| 1130 | // Error has already been set by exitStates(). | - | ||||||||||||||||||
| 1131 | Q_ASSERT(error != QStateMachine::NoError); | - | ||||||||||||||||||
| 1132 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 1133 | } | - | ||||||||||||||||||
| 1134 | statesToEnter.insert(state); | - | ||||||||||||||||||
| 1135 | if (isCompound(state)) {
| 65-1440 | ||||||||||||||||||
| 1136 | statesForDefaultEntry.insert(state); | - | ||||||||||||||||||
| 1137 | if (QAbstractState *initial = toStandardState(state)->initialState()) {
| 16-49 | ||||||||||||||||||
| 1138 | Q_ASSERT(initial->machine() == q_func()); | - | ||||||||||||||||||
| 1139 | - | |||||||||||||||||||
| 1140 | // FIXME: | - | ||||||||||||||||||
| 1141 | // Qt does not support initial transitions (which is a problem for parallel states). | - | ||||||||||||||||||
| 1142 | // The way it simulates this for other states, is by having a single initial state. | - | ||||||||||||||||||
| 1143 | // See also the FIXME in enterStates. | - | ||||||||||||||||||
| 1144 | statesForDefaultEntry.insert(initial); | - | ||||||||||||||||||
| 1145 | - | |||||||||||||||||||
| 1146 | addDescendantStatesToEnter(initial, statesToEnter, statesForDefaultEntry); | - | ||||||||||||||||||
| 1147 | addAncestorStatesToEnter(initial, state, statesToEnter, statesForDefaultEntry); | - | ||||||||||||||||||
| 1148 | } else { executed 49 times by 2 tests: end of blockExecuted by:
| 49 | ||||||||||||||||||
| 1149 | setError(QStateMachine::NoInitialStateError, state); | - | ||||||||||||||||||
| 1150 | return; executed 16 times by 1 test: return;Executed by:
| 16 | ||||||||||||||||||
| 1151 | } | - | ||||||||||||||||||
| 1152 | } else if (isParallel(state)) {
| 15-1425 | ||||||||||||||||||
| 1153 | QState *grp = toStandardState(state); | - | ||||||||||||||||||
| 1154 | const auto childStates = QStatePrivate::get(grp)->childStates(); | - | ||||||||||||||||||
| 1155 | for (QAbstractState *child : childStates) { | - | ||||||||||||||||||
| 1156 | if (!containsDecendantOf(statesToEnter, child))
| 0-29 | ||||||||||||||||||
| 1157 | addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry); executed 29 times by 1 test: addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry);Executed by:
| 29 | ||||||||||||||||||
| 1158 | } executed 29 times by 1 test: end of blockExecuted by:
| 29 | ||||||||||||||||||
| 1159 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 1160 | } executed 1489 times by 2 tests: end of blockExecuted by:
| 1489 | ||||||||||||||||||
| 1161 | } | - | ||||||||||||||||||
| 1162 | - | |||||||||||||||||||
| 1163 | - | |||||||||||||||||||
| 1164 | /* The algorithm as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 1165 | - | |||||||||||||||||||
| 1166 | procedure addAncestorStatesToEnter(state, ancestor, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1167 | for anc in getProperAncestors(state,ancestor): | - | ||||||||||||||||||
| 1168 | statesToEnter.add(anc) | - | ||||||||||||||||||
| 1169 | if isParallelState(anc): | - | ||||||||||||||||||
| 1170 | for child in getChildStates(anc): | - | ||||||||||||||||||
| 1171 | if not statesToEnter.some(lambda s: isDescendant(s,child)): | - | ||||||||||||||||||
| 1172 | addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1173 | */ | - | ||||||||||||||||||
| 1174 | void QStateMachinePrivate::addAncestorStatesToEnter(QAbstractState *s, QAbstractState *ancestor, | - | ||||||||||||||||||
| 1175 | QSet<QAbstractState*> &statesToEnter, | - | ||||||||||||||||||
| 1176 | QSet<QAbstractState*> &statesForDefaultEntry) | - | ||||||||||||||||||
| 1177 | { | - | ||||||||||||||||||
| 1178 | const auto properAncestors = getProperAncestors(s, ancestor); | - | ||||||||||||||||||
| 1179 | for (QState *anc : properAncestors) { | - | ||||||||||||||||||
| 1180 | if (!anc->parentState())
| 2-66 | ||||||||||||||||||
| 1181 | continue; executed 2 times by 1 test: continue;Executed by:
| 2 | ||||||||||||||||||
| 1182 | statesToEnter.insert(anc); | - | ||||||||||||||||||
| 1183 | if (isParallel(anc)) {
| 31-35 | ||||||||||||||||||
| 1184 | const auto childStates = QStatePrivate::get(anc)->childStates(); | - | ||||||||||||||||||
| 1185 | for (QAbstractState *child : childStates) { | - | ||||||||||||||||||
| 1186 | if (!containsDecendantOf(statesToEnter, child))
| 27-36 | ||||||||||||||||||
| 1187 | addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry); executed 27 times by 1 test: addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry);Executed by:
| 27 | ||||||||||||||||||
| 1188 | } executed 63 times by 1 test: end of blockExecuted by:
| 63 | ||||||||||||||||||
| 1189 | } executed 35 times by 1 test: end of blockExecuted by:
| 35 | ||||||||||||||||||
| 1190 | } executed 66 times by 1 test: end of blockExecuted by:
| 66 | ||||||||||||||||||
| 1191 | } executed 1467 times by 2 tests: end of blockExecuted by:
| 1467 | ||||||||||||||||||
| 1192 | - | |||||||||||||||||||
| 1193 | bool QStateMachinePrivate::isFinal(const QAbstractState *s) | - | ||||||||||||||||||
| 1194 | { | - | ||||||||||||||||||
| 1195 | return s && (QAbstractStatePrivate::get(s)->stateType == QAbstractStatePrivate::FinalState); executed 3561 times by 2 tests: return s && (QAbstractStatePrivate::get(s)->stateType == QAbstractStatePrivate::FinalState);Executed by:
| 3561 | ||||||||||||||||||
| 1196 | } | - | ||||||||||||||||||
| 1197 | - | |||||||||||||||||||
| 1198 | bool QStateMachinePrivate::isParallel(const QAbstractState *s) | - | ||||||||||||||||||
| 1199 | { | - | ||||||||||||||||||
| 1200 | const QState *ss = toStandardState(s); | - | ||||||||||||||||||
| 1201 | return ss && (QStatePrivate::get(ss)->childMode == QState::ParallelStates); executed 4385 times by 2 tests: return ss && (QStatePrivate::get(ss)->childMode == QState::ParallelStates);Executed by:
| 4385 | ||||||||||||||||||
| 1202 | } | - | ||||||||||||||||||
| 1203 | - | |||||||||||||||||||
| 1204 | bool QStateMachinePrivate::isCompound(const QAbstractState *s) const | - | ||||||||||||||||||
| 1205 | { | - | ||||||||||||||||||
| 1206 | const QState *group = toStandardState(s); | - | ||||||||||||||||||
| 1207 | if (!group)
| 72-2869 | ||||||||||||||||||
| 1208 | return false; executed 72 times by 1 test: return false;Executed by:
| 72 | ||||||||||||||||||
| 1209 | bool isMachine = QStatePrivate::get(group)->isMachine; | - | ||||||||||||||||||
| 1210 | // Don't treat the machine as compound if it's a sub-state of this machine | - | ||||||||||||||||||
| 1211 | if (isMachine && (group != rootState()))
| 3-1517 | ||||||||||||||||||
| 1212 | return false; executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||
| 1213 | return (!isParallel(group) && !QStatePrivate::get(group)->childStates().isEmpty()); executed 2866 times by 2 tests: return (!isParallel(group) && !QStatePrivate::get(group)->childStates().isEmpty());Executed by:
| 2866 | ||||||||||||||||||
| 1214 | } | - | ||||||||||||||||||
| 1215 | - | |||||||||||||||||||
| 1216 | bool QStateMachinePrivate::isAtomic(const QAbstractState *s) const | - | ||||||||||||||||||
| 1217 | { | - | ||||||||||||||||||
| 1218 | const QState *ss = toStandardState(s); | - | ||||||||||||||||||
| 1219 | return (ss && QStatePrivate::get(ss)->childStates().isEmpty()) executed 4235 times by 2 tests: return (ss && QStatePrivate::get(ss)->childStates().isEmpty()) || isFinal(s) || (ss && QStatePrivate::get(ss)->isMachine && (ss != rootState()));Executed by:
| 4235 | ||||||||||||||||||
| 1220 | || isFinal(s) executed 4235 times by 2 tests: return (ss && QStatePrivate::get(ss)->childStates().isEmpty()) || isFinal(s) || (ss && QStatePrivate::get(ss)->isMachine && (ss != rootState()));Executed by:
| 4235 | ||||||||||||||||||
| 1221 | // Treat the machine as atomic if it's a sub-state of this machine executed 4235 times by 2 tests: return (ss && QStatePrivate::get(ss)->childStates().isEmpty()) || isFinal(s) || (ss && QStatePrivate::get(ss)->isMachine && (ss != rootState()));Executed by:
| 4235 | ||||||||||||||||||
| 1222 | || (ss && QStatePrivate::get(ss)->isMachine && (ss != rootState())); executed 4235 times by 2 tests: return (ss && QStatePrivate::get(ss)->childStates().isEmpty()) || isFinal(s) || (ss && QStatePrivate::get(ss)->isMachine && (ss != rootState()));Executed by:
| 4235 | ||||||||||||||||||
| 1223 | } | - | ||||||||||||||||||
| 1224 | - | |||||||||||||||||||
| 1225 | QState *QStateMachinePrivate::toStandardState(QAbstractState *state) | - | ||||||||||||||||||
| 1226 | { | - | ||||||||||||||||||
| 1227 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::StandardState))
| 0-9813 | ||||||||||||||||||
| 1228 | return static_cast<QState*>(state); executed 9566 times by 2 tests: return static_cast<QState*>(state);Executed by:
| 9566 | ||||||||||||||||||
| 1229 | return 0; executed 247 times by 1 test: return 0;Executed by:
| 247 | ||||||||||||||||||
| 1230 | } | - | ||||||||||||||||||
| 1231 | - | |||||||||||||||||||
| 1232 | const QState *QStateMachinePrivate::toStandardState(const QAbstractState *state) | - | ||||||||||||||||||
| 1233 | { | - | ||||||||||||||||||
| 1234 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::StandardState))
| 0-11561 | ||||||||||||||||||
| 1235 | return static_cast<const QState*>(state); executed 11394 times by 2 tests: return static_cast<const QState*>(state);Executed by:
| 11394 | ||||||||||||||||||
| 1236 | return 0; executed 167 times by 1 test: return 0;Executed by:
| 167 | ||||||||||||||||||
| 1237 | } | - | ||||||||||||||||||
| 1238 | - | |||||||||||||||||||
| 1239 | QFinalState *QStateMachinePrivate::toFinalState(QAbstractState *state) | - | ||||||||||||||||||
| 1240 | { | - | ||||||||||||||||||
| 1241 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::FinalState))
| 0 | ||||||||||||||||||
| 1242 | return static_cast<QFinalState*>(state); never executed: return static_cast<QFinalState*>(state); | 0 | ||||||||||||||||||
| 1243 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1244 | } | - | ||||||||||||||||||
| 1245 | - | |||||||||||||||||||
| 1246 | QHistoryState *QStateMachinePrivate::toHistoryState(QAbstractState *state) | - | ||||||||||||||||||
| 1247 | { | - | ||||||||||||||||||
| 1248 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::HistoryState))
| 0-4416 | ||||||||||||||||||
| 1249 | return static_cast<QHistoryState*>(state); executed 22 times by 2 tests: return static_cast<QHistoryState*>(state);Executed by:
| 22 | ||||||||||||||||||
| 1250 | return 0; executed 4394 times by 2 tests: return 0;Executed by:
| 4394 | ||||||||||||||||||
| 1251 | } | - | ||||||||||||||||||
| 1252 | - | |||||||||||||||||||
| 1253 | bool QStateMachinePrivate::isInFinalState(QAbstractState* s) const | - | ||||||||||||||||||
| 1254 | { | - | ||||||||||||||||||
| 1255 | if (isCompound(s)) {
| 1-18 | ||||||||||||||||||
| 1256 | QState *grp = toStandardState(s); | - | ||||||||||||||||||
| 1257 | QList<QAbstractState*> lst = QStatePrivate::get(grp)->childStates(); | - | ||||||||||||||||||
| 1258 | for (int i = 0; i < lst.size(); ++i) {
| 4-30 | ||||||||||||||||||
| 1259 | QAbstractState *cs = lst.at(i); | - | ||||||||||||||||||
| 1260 | if (isFinal(cs) && configuration.contains(cs))
| 4-18 | ||||||||||||||||||
| 1261 | return true; executed 14 times by 1 test: return true;Executed by:
| 14 | ||||||||||||||||||
| 1262 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 1263 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||
| 1264 | } else if (isParallel(s)) {
| 0-1 | ||||||||||||||||||
| 1265 | QState *grp = toStandardState(s); | - | ||||||||||||||||||
| 1266 | QList<QAbstractState*> lst = QStatePrivate::get(grp)->childStates(); | - | ||||||||||||||||||
| 1267 | for (int i = 0; i < lst.size(); ++i) {
| 1-2 | ||||||||||||||||||
| 1268 | QAbstractState *cs = lst.at(i); | - | ||||||||||||||||||
| 1269 | if (!isInFinalState(cs))
| 0-2 | ||||||||||||||||||
| 1270 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1271 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1272 | return true; executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||||||||
| 1273 | } | - | ||||||||||||||||||
| 1274 | else | - | ||||||||||||||||||
| 1275 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1276 | } | - | ||||||||||||||||||
| 1277 | - | |||||||||||||||||||
| 1278 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||
| 1279 | - | |||||||||||||||||||
| 1280 | /*! | - | ||||||||||||||||||
| 1281 | \internal | - | ||||||||||||||||||
| 1282 | Returns \c true if the given state has saved the value of the given property, | - | ||||||||||||||||||
| 1283 | otherwise returns \c false. | - | ||||||||||||||||||
| 1284 | */ | - | ||||||||||||||||||
| 1285 | bool QStateMachinePrivate::hasRestorable(QAbstractState *state, QObject *object, | - | ||||||||||||||||||
| 1286 | const QByteArray &propertyName) const | - | ||||||||||||||||||
| 1287 | { | - | ||||||||||||||||||
| 1288 | RestorableId id(object, propertyName); | - | ||||||||||||||||||
| 1289 | return registeredRestorablesForState.value(state).contains(id); executed 48 times by 1 test: return registeredRestorablesForState.value(state).contains(id);Executed by:
| 48 | ||||||||||||||||||
| 1290 | } | - | ||||||||||||||||||
| 1291 | - | |||||||||||||||||||
| 1292 | /*! | - | ||||||||||||||||||
| 1293 | \internal | - | ||||||||||||||||||
| 1294 | Returns the value to save for the property identified by \a id. | - | ||||||||||||||||||
| 1295 | If an exited state (member of \a exitedStates_sorted) has saved a value for | - | ||||||||||||||||||
| 1296 | the property, the saved value from the last (outermost) state that will be | - | ||||||||||||||||||
| 1297 | exited is returned (in practice carrying the saved value on to the next | - | ||||||||||||||||||
| 1298 | state). Otherwise, the current value of the property is returned. | - | ||||||||||||||||||
| 1299 | */ | - | ||||||||||||||||||
| 1300 | QVariant QStateMachinePrivate::savedValueForRestorable(const QList<QAbstractState*> &exitedStates_sorted, | - | ||||||||||||||||||
| 1301 | QObject *object, const QByteArray &propertyName) const | - | ||||||||||||||||||
| 1302 | { | - | ||||||||||||||||||
| 1303 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1304 | qDebug() << q_func() << ": savedValueForRestorable(" << exitedStates_sorted << object << propertyName << ')'; | - | ||||||||||||||||||
| 1305 | #endif | - | ||||||||||||||||||
| 1306 | for (int i = exitedStates_sorted.size() - 1; i >= 0; --i) {
| 29-38 | ||||||||||||||||||
| 1307 | QAbstractState *s = exitedStates_sorted.at(i); | - | ||||||||||||||||||
| 1308 | QHash<RestorableId, QVariant> restorables = registeredRestorablesForState.value(s); | - | ||||||||||||||||||
| 1309 | QHash<RestorableId, QVariant>::const_iterator it = restorables.constFind(RestorableId(object, propertyName)); | - | ||||||||||||||||||
| 1310 | if (it != restorables.constEnd()) {
| 17-21 | ||||||||||||||||||
| 1311 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1312 | qDebug() << q_func() << ": using" << it.value() << "from" << s; | - | ||||||||||||||||||
| 1313 | #endif | - | ||||||||||||||||||
| 1314 | return it.value(); executed 17 times by 1 test: return it.value();Executed by:
| 17 | ||||||||||||||||||
| 1315 | } | - | ||||||||||||||||||
| 1316 | } executed 21 times by 1 test: end of blockExecuted by:
| 21 | ||||||||||||||||||
| 1317 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1318 | qDebug() << q_func() << ": falling back to current value"; | - | ||||||||||||||||||
| 1319 | #endif | - | ||||||||||||||||||
| 1320 | return object->property(propertyName); executed 29 times by 1 test: return object->property(propertyName);Executed by:
| 29 | ||||||||||||||||||
| 1321 | } | - | ||||||||||||||||||
| 1322 | - | |||||||||||||||||||
| 1323 | void QStateMachinePrivate::registerRestorable(QAbstractState *state, QObject *object, const QByteArray &propertyName, | - | ||||||||||||||||||
| 1324 | const QVariant &value) | - | ||||||||||||||||||
| 1325 | { | - | ||||||||||||||||||
| 1326 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1327 | qDebug() << q_func() << ": registerRestorable(" << state << object << propertyName << value << ')'; | - | ||||||||||||||||||
| 1328 | #endif | - | ||||||||||||||||||
| 1329 | RestorableId id(object, propertyName); | - | ||||||||||||||||||
| 1330 | QHash<RestorableId, QVariant> &restorables = registeredRestorablesForState[state]; | - | ||||||||||||||||||
| 1331 | if (!restorables.contains(id))
| 0-46 | ||||||||||||||||||
| 1332 | restorables.insert(id, value); executed 46 times by 1 test: restorables.insert(id, value);Executed by:
| 46 | ||||||||||||||||||
| 1333 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1334 | else | - | ||||||||||||||||||
| 1335 | qDebug() << q_func() << ": (already registered)"; | - | ||||||||||||||||||
| 1336 | #endif | - | ||||||||||||||||||
| 1337 | } executed 46 times by 1 test: end of blockExecuted by:
| 46 | ||||||||||||||||||
| 1338 | - | |||||||||||||||||||
| 1339 | void QStateMachinePrivate::unregisterRestorables(const QList<QAbstractState *> &states, QObject *object, | - | ||||||||||||||||||
| 1340 | const QByteArray &propertyName) | - | ||||||||||||||||||
| 1341 | { | - | ||||||||||||||||||
| 1342 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1343 | qDebug() << q_func() << ": unregisterRestorables(" << states << object << propertyName << ')'; | - | ||||||||||||||||||
| 1344 | #endif | - | ||||||||||||||||||
| 1345 | RestorableId id(object, propertyName); | - | ||||||||||||||||||
| 1346 | for (int i = 0; i < states.size(); ++i) {
| 65-70 | ||||||||||||||||||
| 1347 | QAbstractState *s = states.at(i); | - | ||||||||||||||||||
| 1348 | QHash<QAbstractState*, QHash<RestorableId, QVariant> >::iterator it; | - | ||||||||||||||||||
| 1349 | it = registeredRestorablesForState.find(s); | - | ||||||||||||||||||
| 1350 | if (it == registeredRestorablesForState.end())
| 24-46 | ||||||||||||||||||
| 1351 | continue; executed 24 times by 1 test: continue;Executed by:
| 24 | ||||||||||||||||||
| 1352 | QHash<RestorableId, QVariant> &restorables = it.value(); | - | ||||||||||||||||||
| 1353 | const auto it2 = restorables.constFind(id); | - | ||||||||||||||||||
| 1354 | if (it2 == restorables.cend())
| 9-37 | ||||||||||||||||||
| 1355 | continue; executed 9 times by 1 test: continue;Executed by:
| 9 | ||||||||||||||||||
| 1356 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1357 | qDebug() << q_func() << ": unregistered for" << s; | - | ||||||||||||||||||
| 1358 | #endif | - | ||||||||||||||||||
| 1359 | restorables.erase(it2); | - | ||||||||||||||||||
| 1360 | if (restorables.isEmpty())
| 5-32 | ||||||||||||||||||
| 1361 | registeredRestorablesForState.erase(it); executed 32 times by 1 test: registeredRestorablesForState.erase(it);Executed by:
| 32 | ||||||||||||||||||
| 1362 | } executed 37 times by 1 test: end of blockExecuted by:
| 37 | ||||||||||||||||||
| 1363 | } executed 65 times by 1 test: end of blockExecuted by:
| 65 | ||||||||||||||||||
| 1364 | - | |||||||||||||||||||
| 1365 | QVector<QPropertyAssignment> QStateMachinePrivate::restorablesToPropertyList(const QHash<RestorableId, QVariant> &restorables) const | - | ||||||||||||||||||
| 1366 | { | - | ||||||||||||||||||
| 1367 | QVector<QPropertyAssignment> result; | - | ||||||||||||||||||
| 1368 | QHash<RestorableId, QVariant>::const_iterator it; | - | ||||||||||||||||||
| 1369 | for (it = restorables.constBegin(); it != restorables.constEnd(); ++it) {
| 23-25 | ||||||||||||||||||
| 1370 | const RestorableId &id = it.key(); | - | ||||||||||||||||||
| 1371 | if (!id.object()) {
| 1-24 | ||||||||||||||||||
| 1372 | // Property object was deleted | - | ||||||||||||||||||
| 1373 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||||||||
| 1374 | } | - | ||||||||||||||||||
| 1375 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1376 | qDebug() << q_func() << ": restoring" << id.object() << id.proertyName() << "to" << it.value(); | - | ||||||||||||||||||
| 1377 | #endif | - | ||||||||||||||||||
| 1378 | result.append(QPropertyAssignment(id.object(), id.propertyName(), it.value(), /*explicitlySet=*/false)); | - | ||||||||||||||||||
| 1379 | } executed 24 times by 1 test: end of blockExecuted by:
| 24 | ||||||||||||||||||
| 1380 | return result; executed 23 times by 1 test: return result;Executed by:
| 23 | ||||||||||||||||||
| 1381 | } | - | ||||||||||||||||||
| 1382 | - | |||||||||||||||||||
| 1383 | /*! | - | ||||||||||||||||||
| 1384 | \internal | - | ||||||||||||||||||
| 1385 | Computes the set of properties whose values should be restored given that | - | ||||||||||||||||||
| 1386 | the states \a statesToExit_sorted will be exited. | - | ||||||||||||||||||
| 1387 | - | |||||||||||||||||||
| 1388 | If a particular (object, propertyName) pair occurs more than once (i.e., | - | ||||||||||||||||||
| 1389 | because nested states are being exited), the value from the last (outermost) | - | ||||||||||||||||||
| 1390 | exited state takes precedence. | - | ||||||||||||||||||
| 1391 | - | |||||||||||||||||||
| 1392 | The result of this function must be filtered according to the explicit | - | ||||||||||||||||||
| 1393 | property assignments (QState::assignProperty()) of the entered states | - | ||||||||||||||||||
| 1394 | before the property restoration is actually performed; i.e., if an entered | - | ||||||||||||||||||
| 1395 | state assigns to a property that would otherwise be restored, that property | - | ||||||||||||||||||
| 1396 | should not be restored after all, but the saved value from the exited state | - | ||||||||||||||||||
| 1397 | should be remembered by the entered state (see registerRestorable()). | - | ||||||||||||||||||
| 1398 | */ | - | ||||||||||||||||||
| 1399 | QHash<QStateMachinePrivate::RestorableId, QVariant> QStateMachinePrivate::computePendingRestorables( | - | ||||||||||||||||||
| 1400 | const QList<QAbstractState*> &statesToExit_sorted) const | - | ||||||||||||||||||
| 1401 | { | - | ||||||||||||||||||
| 1402 | QHash<QStateMachinePrivate::RestorableId, QVariant> restorables; | - | ||||||||||||||||||
| 1403 | for (int i = statesToExit_sorted.size() - 1; i >= 0; --i) {
| 1235-1298 | ||||||||||||||||||
| 1404 | QAbstractState *s = statesToExit_sorted.at(i); | - | ||||||||||||||||||
| 1405 | QHash<QStateMachinePrivate::RestorableId, QVariant> rs = registeredRestorablesForState.value(s); | - | ||||||||||||||||||
| 1406 | QHash<QStateMachinePrivate::RestorableId, QVariant>::const_iterator it; | - | ||||||||||||||||||
| 1407 | for (it = rs.constBegin(); it != rs.constEnd(); ++it) {
| 39-1298 | ||||||||||||||||||
| 1408 | if (!restorables.contains(it.key()))
| 1-38 | ||||||||||||||||||
| 1409 | restorables.insert(it.key(), it.value()); executed 38 times by 1 test: restorables.insert(it.key(), it.value());Executed by:
| 38 | ||||||||||||||||||
| 1410 | } executed 39 times by 1 test: end of blockExecuted by:
| 39 | ||||||||||||||||||
| 1411 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 1412 | return restorables; executed 1235 times by 2 tests: return restorables;Executed by:
| 1235 | ||||||||||||||||||
| 1413 | } | - | ||||||||||||||||||
| 1414 | - | |||||||||||||||||||
| 1415 | /*! | - | ||||||||||||||||||
| 1416 | \internal | - | ||||||||||||||||||
| 1417 | Computes the ordered sets of property assignments for the states to be | - | ||||||||||||||||||
| 1418 | entered, \a statesToEnter_sorted. Also filters \a pendingRestorables (removes | - | ||||||||||||||||||
| 1419 | properties that should not be restored because they are assigned by an | - | ||||||||||||||||||
| 1420 | entered state). | - | ||||||||||||||||||
| 1421 | */ | - | ||||||||||||||||||
| 1422 | QHash<QAbstractState*, QVector<QPropertyAssignment> > QStateMachinePrivate::computePropertyAssignments( | - | ||||||||||||||||||
| 1423 | const QList<QAbstractState*> &statesToEnter_sorted, QHash<RestorableId, QVariant> &pendingRestorables) const | - | ||||||||||||||||||
| 1424 | { | - | ||||||||||||||||||
| 1425 | QHash<QAbstractState*, QVector<QPropertyAssignment> > assignmentsForState; | - | ||||||||||||||||||
| 1426 | for (int i = 0; i < statesToEnter_sorted.size(); ++i) {
| 1388-1507 | ||||||||||||||||||
| 1427 | QState *s = toStandardState(statesToEnter_sorted.at(i)); | - | ||||||||||||||||||
| 1428 | if (!s)
| 72-1435 | ||||||||||||||||||
| 1429 | continue; executed 72 times by 1 test: continue;Executed by:
| 72 | ||||||||||||||||||
| 1430 | - | |||||||||||||||||||
| 1431 | QVector<QPropertyAssignment> &assignments = QStatePrivate::get(s)->propertyAssignments; | - | ||||||||||||||||||
| 1432 | for (int j = 0; j < assignments.size(); ++j) {
| 110-1435 | ||||||||||||||||||
| 1433 | const QPropertyAssignment &assn = assignments.at(j); | - | ||||||||||||||||||
| 1434 | if (assn.objectDeleted()) {
| 1-109 | ||||||||||||||||||
| 1435 | assignments.removeAt(j--); | - | ||||||||||||||||||
| 1436 | } else { executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 1437 | pendingRestorables.remove(RestorableId(assn.object, assn.propertyName)); | - | ||||||||||||||||||
| 1438 | assignmentsForState[s].append(assn); | - | ||||||||||||||||||
| 1439 | } executed 109 times by 2 tests: end of blockExecuted by:
| 109 | ||||||||||||||||||
| 1440 | } | - | ||||||||||||||||||
| 1441 | } executed 1435 times by 2 tests: end of blockExecuted by:
| 1435 | ||||||||||||||||||
| 1442 | return assignmentsForState; executed 1388 times by 2 tests: return assignmentsForState;Executed by:
| 1388 | ||||||||||||||||||
| 1443 | } | - | ||||||||||||||||||
| 1444 | - | |||||||||||||||||||
| 1445 | #endif // QT_NO_PROPERTIES | - | ||||||||||||||||||
| 1446 | - | |||||||||||||||||||
| 1447 | QAbstractState *QStateMachinePrivate::findErrorState(QAbstractState *context) | - | ||||||||||||||||||
| 1448 | { | - | ||||||||||||||||||
| 1449 | // Find error state recursively in parent hierarchy if not set explicitly for context state | - | ||||||||||||||||||
| 1450 | QAbstractState *errorState = 0; | - | ||||||||||||||||||
| 1451 | if (context != 0) {
| 9-40 | ||||||||||||||||||
| 1452 | QState *s = toStandardState(context); | - | ||||||||||||||||||
| 1453 | if (s != 0)
| 1-39 | ||||||||||||||||||
| 1454 | errorState = s->errorState(); executed 39 times by 1 test: errorState = s->errorState();Executed by:
| 39 | ||||||||||||||||||
| 1455 | - | |||||||||||||||||||
| 1456 | if (errorState == 0)
| 11-29 | ||||||||||||||||||
| 1457 | errorState = findErrorState(context->parentState()); executed 29 times by 1 test: errorState = findErrorState(context->parentState());Executed by:
| 29 | ||||||||||||||||||
| 1458 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 1459 | - | |||||||||||||||||||
| 1460 | return errorState; executed 49 times by 1 test: return errorState;Executed by:
| 49 | ||||||||||||||||||
| 1461 | } | - | ||||||||||||||||||
| 1462 | - | |||||||||||||||||||
| 1463 | void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractState *currentContext) | - | ||||||||||||||||||
| 1464 | { | - | ||||||||||||||||||
| 1465 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1466 | - | |||||||||||||||||||
| 1467 | error = errorCode; | - | ||||||||||||||||||
| 1468 | switch (errorCode) { | - | ||||||||||||||||||
| 1469 | case QStateMachine::NoInitialStateError: executed 16 times by 1 test: case QStateMachine::NoInitialStateError:Executed by:
| 16 | ||||||||||||||||||
| 1470 | Q_ASSERT(currentContext != 0); | - | ||||||||||||||||||
| 1471 | - | |||||||||||||||||||
| 1472 | errorString = QStateMachine::tr("Missing initial state in compound state '%1'") | - | ||||||||||||||||||
| 1473 | .arg(currentContext->objectName()); | - | ||||||||||||||||||
| 1474 | - | |||||||||||||||||||
| 1475 | break; executed 16 times by 1 test: break;Executed by:
| 16 | ||||||||||||||||||
| 1476 | case QStateMachine::NoDefaultStateInHistoryStateError: executed 1 time by 1 test: case QStateMachine::NoDefaultStateInHistoryStateError:Executed by:
| 1 | ||||||||||||||||||
| 1477 | Q_ASSERT(currentContext != 0); | - | ||||||||||||||||||
| 1478 | - | |||||||||||||||||||
| 1479 | errorString = QStateMachine::tr("Missing default state in history state '%1'") | - | ||||||||||||||||||
| 1480 | .arg(currentContext->objectName()); | - | ||||||||||||||||||
| 1481 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 1482 | - | |||||||||||||||||||
| 1483 | case QStateMachine::NoCommonAncestorForTransitionError: executed 3 times by 1 test: case QStateMachine::NoCommonAncestorForTransitionError:Executed by:
| 3 | ||||||||||||||||||
| 1484 | Q_ASSERT(currentContext != 0); | - | ||||||||||||||||||
| 1485 | - | |||||||||||||||||||
| 1486 | errorString = QStateMachine::tr("No common ancestor for targets and source of transition from state '%1'") | - | ||||||||||||||||||
| 1487 | .arg(currentContext->objectName()); | - | ||||||||||||||||||
| 1488 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 1489 | default: never executed: default: | 0 | ||||||||||||||||||
| 1490 | errorString = QStateMachine::tr("Unknown error"); | - | ||||||||||||||||||
| 1491 | }; never executed: end of block | 0 | ||||||||||||||||||
| 1492 | - | |||||||||||||||||||
| 1493 | pendingErrorStates.clear(); | - | ||||||||||||||||||
| 1494 | pendingErrorStatesForDefaultEntry.clear(); | - | ||||||||||||||||||
| 1495 | - | |||||||||||||||||||
| 1496 | QAbstractState *currentErrorState = findErrorState(currentContext); | - | ||||||||||||||||||
| 1497 | - | |||||||||||||||||||
| 1498 | // Avoid infinite loop if the error state itself has an error | - | ||||||||||||||||||
| 1499 | if (currentContext == currentErrorState)
| 1-19 | ||||||||||||||||||
| 1500 | currentErrorState = 0; executed 1 time by 1 test: currentErrorState = 0;Executed by:
| 1 | ||||||||||||||||||
| 1501 | - | |||||||||||||||||||
| 1502 | Q_ASSERT(currentErrorState != rootState()); | - | ||||||||||||||||||
| 1503 | - | |||||||||||||||||||
| 1504 | if (currentErrorState != 0) {
| 10 | ||||||||||||||||||
| 1505 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1506 | qDebug() << q << ": entering error state" << currentErrorState << "from" << currentContext; | - | ||||||||||||||||||
| 1507 | #endif | - | ||||||||||||||||||
| 1508 | pendingErrorStates.insert(currentErrorState); | - | ||||||||||||||||||
| 1509 | addDescendantStatesToEnter(currentErrorState, pendingErrorStates, pendingErrorStatesForDefaultEntry); | - | ||||||||||||||||||
| 1510 | addAncestorStatesToEnter(currentErrorState, rootState(), pendingErrorStates, pendingErrorStatesForDefaultEntry); | - | ||||||||||||||||||
| 1511 | pendingErrorStates -= configuration; | - | ||||||||||||||||||
| 1512 | } else { executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1513 | qWarning("Unrecoverable error detected in running state machine: %s", | - | ||||||||||||||||||
| 1514 | qPrintable(errorString)); | - | ||||||||||||||||||
| 1515 | q->stop(); | - | ||||||||||||||||||
| 1516 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1517 | } | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1520 | - | |||||||||||||||||||
| 1521 | QStateMachinePrivate::InitializeAnimationResult | - | ||||||||||||||||||
| 1522 | QStateMachinePrivate::initializeAnimation(QAbstractAnimation *abstractAnimation, | - | ||||||||||||||||||
| 1523 | const QPropertyAssignment &prop) | - | ||||||||||||||||||
| 1524 | { | - | ||||||||||||||||||
| 1525 | InitializeAnimationResult result; | - | ||||||||||||||||||
| 1526 | QAnimationGroup *group = qobject_cast<QAnimationGroup*>(abstractAnimation); | - | ||||||||||||||||||
| 1527 | if (group) {
| 5-50 | ||||||||||||||||||
| 1528 | for (int i = 0; i < group->animationCount(); ++i) {
| 5-8 | ||||||||||||||||||
| 1529 | QAbstractAnimation *animationChild = group->animationAt(i); | - | ||||||||||||||||||
| 1530 | const auto ret = initializeAnimation(animationChild, prop); | - | ||||||||||||||||||
| 1531 | result.handledAnimations << ret.handledAnimations; | - | ||||||||||||||||||
| 1532 | result.localResetEndValues << ret.localResetEndValues; | - | ||||||||||||||||||
| 1533 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 1534 | } else { executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 1535 | QPropertyAnimation *animation = qobject_cast<QPropertyAnimation *>(abstractAnimation); | - | ||||||||||||||||||
| 1536 | if (animation != 0
| 0-50 | ||||||||||||||||||
| 1537 | && prop.object == animation->targetObject()
| 4-46 | ||||||||||||||||||
| 1538 | && prop.propertyName == animation->propertyName()) {
| 10-36 | ||||||||||||||||||
| 1539 | - | |||||||||||||||||||
| 1540 | // Only change end value if it is undefined | - | ||||||||||||||||||
| 1541 | if (!animation->endValue().isValid()) {
| 1-35 | ||||||||||||||||||
| 1542 | animation->setEndValue(prop.value); | - | ||||||||||||||||||
| 1543 | result.localResetEndValues.append(animation); | - | ||||||||||||||||||
| 1544 | } executed 35 times by 1 test: end of blockExecuted by:
| 35 | ||||||||||||||||||
| 1545 | result.handledAnimations.append(animation); | - | ||||||||||||||||||
| 1546 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 1547 | } executed 50 times by 1 test: end of blockExecuted by:
| 50 | ||||||||||||||||||
| 1548 | return result; executed 55 times by 1 test: return result;Executed by:
| 55 | ||||||||||||||||||
| 1549 | } | - | ||||||||||||||||||
| 1550 | - | |||||||||||||||||||
| 1551 | void QStateMachinePrivate::_q_animationFinished() | - | ||||||||||||||||||
| 1552 | { | - | ||||||||||||||||||
| 1553 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1554 | QAbstractAnimation *anim = qobject_cast<QAbstractAnimation*>(q->sender()); | - | ||||||||||||||||||
| 1555 | Q_ASSERT(anim != 0); | - | ||||||||||||||||||
| 1556 | QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished())); | - | ||||||||||||||||||
| 1557 | if (resetAnimationEndValues.contains(anim)) {
| 0-15 | ||||||||||||||||||
| 1558 | qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize | - | ||||||||||||||||||
| 1559 | resetAnimationEndValues.remove(anim); | - | ||||||||||||||||||
| 1560 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 1561 | - | |||||||||||||||||||
| 1562 | QAbstractState *state = stateForAnimation.take(anim); | - | ||||||||||||||||||
| 1563 | Q_ASSERT(state != 0); | - | ||||||||||||||||||
| 1564 | - | |||||||||||||||||||
| 1565 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||
| 1566 | // Set the final property value. | - | ||||||||||||||||||
| 1567 | QPropertyAssignment assn = propertyForAnimation.take(anim); | - | ||||||||||||||||||
| 1568 | assn.write(); | - | ||||||||||||||||||
| 1569 | if (!assn.explicitlySet)
| 1-14 | ||||||||||||||||||
| 1570 | unregisterRestorables(QList<QAbstractState*>() << state, assn.object, assn.propertyName); executed 1 time by 1 test: unregisterRestorables(QList<QAbstractState*>() << state, assn.object, assn.propertyName);Executed by:
| 1 | ||||||||||||||||||
| 1571 | #endif | - | ||||||||||||||||||
| 1572 | - | |||||||||||||||||||
| 1573 | QHash<QAbstractState*, QList<QAbstractAnimation*> >::iterator it; | - | ||||||||||||||||||
| 1574 | it = animationsForState.find(state); | - | ||||||||||||||||||
| 1575 | Q_ASSERT(it != animationsForState.end()); | - | ||||||||||||||||||
| 1576 | QList<QAbstractAnimation*> &animations = it.value(); | - | ||||||||||||||||||
| 1577 | animations.removeOne(anim); | - | ||||||||||||||||||
| 1578 | if (animations.isEmpty()) {
| 3-12 | ||||||||||||||||||
| 1579 | animationsForState.erase(it); | - | ||||||||||||||||||
| 1580 | QStatePrivate::get(toStandardState(state))->emitPropertiesAssigned(); | - | ||||||||||||||||||
| 1581 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1582 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 1583 | - | |||||||||||||||||||
| 1584 | QList<QAbstractAnimation *> QStateMachinePrivate::selectAnimations(const QList<QAbstractTransition *> &transitionList) const | - | ||||||||||||||||||
| 1585 | { | - | ||||||||||||||||||
| 1586 | QList<QAbstractAnimation *> selectedAnimations; | - | ||||||||||||||||||
| 1587 | if (animated) {
| 0-1388 | ||||||||||||||||||
| 1588 | for (int i = 0; i < transitionList.size(); ++i) {
| 1388-1391 | ||||||||||||||||||
| 1589 | QAbstractTransition *transition = transitionList.at(i); | - | ||||||||||||||||||
| 1590 | - | |||||||||||||||||||
| 1591 | selectedAnimations << transition->animations(); | - | ||||||||||||||||||
| 1592 | selectedAnimations << defaultAnimationsForSource.values(transition->sourceState()); | - | ||||||||||||||||||
| 1593 | - | |||||||||||||||||||
| 1594 | QList<QAbstractState *> targetStates = transition->targetStates(); | - | ||||||||||||||||||
| 1595 | for (int j=0; j<targetStates.size(); ++j)
| 1387-1391 | ||||||||||||||||||
| 1596 | selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j)); executed 1387 times by 2 tests: selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j));Executed by:
| 1387 | ||||||||||||||||||
| 1597 | } executed 1391 times by 2 tests: end of blockExecuted by:
| 1391 | ||||||||||||||||||
| 1598 | selectedAnimations << defaultAnimations; | - | ||||||||||||||||||
| 1599 | } executed 1388 times by 2 tests: end of blockExecuted by:
| 1388 | ||||||||||||||||||
| 1600 | return selectedAnimations; executed 1388 times by 2 tests: return selectedAnimations;Executed by:
| 1388 | ||||||||||||||||||
| 1601 | } | - | ||||||||||||||||||
| 1602 | - | |||||||||||||||||||
| 1603 | void QStateMachinePrivate::terminateActiveAnimations(QAbstractState *state, | - | ||||||||||||||||||
| 1604 | const QHash<QAbstractState*, QVector<QPropertyAssignment> > &assignmentsForEnteredStates) | - | ||||||||||||||||||
| 1605 | { | - | ||||||||||||||||||
| 1606 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1607 | QList<QAbstractAnimation*> animations = animationsForState.take(state); | - | ||||||||||||||||||
| 1608 | for (int i = 0; i < animations.size(); ++i) {
| 20-1298 | ||||||||||||||||||
| 1609 | QAbstractAnimation *anim = animations.at(i); | - | ||||||||||||||||||
| 1610 | QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished())); | - | ||||||||||||||||||
| 1611 | stateForAnimation.remove(anim); | - | ||||||||||||||||||
| 1612 | - | |||||||||||||||||||
| 1613 | // Stop the (top-level) animation. | - | ||||||||||||||||||
| 1614 | // ### Stopping nested animation has weird behavior. | - | ||||||||||||||||||
| 1615 | QAbstractAnimation *topLevelAnim = anim; | - | ||||||||||||||||||
| 1616 | while (QAnimationGroup *group = topLevelAnim->group())
| 0-20 | ||||||||||||||||||
| 1617 | topLevelAnim = group; never executed: topLevelAnim = group; | 0 | ||||||||||||||||||
| 1618 | topLevelAnim->stop(); | - | ||||||||||||||||||
| 1619 | - | |||||||||||||||||||
| 1620 | if (resetAnimationEndValues.contains(anim)) {
| 1-19 | ||||||||||||||||||
| 1621 | qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize | - | ||||||||||||||||||
| 1622 | resetAnimationEndValues.remove(anim); | - | ||||||||||||||||||
| 1623 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||
| 1624 | QPropertyAssignment assn = propertyForAnimation.take(anim); | - | ||||||||||||||||||
| 1625 | Q_ASSERT(assn.object != 0); | - | ||||||||||||||||||
| 1626 | // If there is no property assignment that sets this property, | - | ||||||||||||||||||
| 1627 | // set the property to its target value. | - | ||||||||||||||||||
| 1628 | bool found = false; | - | ||||||||||||||||||
| 1629 | QHash<QAbstractState*, QVector<QPropertyAssignment> >::const_iterator it; | - | ||||||||||||||||||
| 1630 | for (it = assignmentsForEnteredStates.constBegin(); it != assignmentsForEnteredStates.constEnd(); ++it) {
| 18-20 | ||||||||||||||||||
| 1631 | const QVector<QPropertyAssignment> &assignments = it.value(); | - | ||||||||||||||||||
| 1632 | for (int j = 0; j < assignments.size(); ++j) {
| 8-18 | ||||||||||||||||||
| 1633 | if (assignments.at(j).hasTarget(assn.object, assn.propertyName)) {
| 8-10 | ||||||||||||||||||
| 1634 | found = true; | - | ||||||||||||||||||
| 1635 | break; executed 10 times by 1 test: break;Executed by:
| 10 | ||||||||||||||||||
| 1636 | } | - | ||||||||||||||||||
| 1637 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 1638 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 1639 | if (!found) {
| 10 | ||||||||||||||||||
| 1640 | assn.write(); | - | ||||||||||||||||||
| 1641 | if (!assn.explicitlySet)
| 0-10 | ||||||||||||||||||
| 1642 | unregisterRestorables(QList<QAbstractState*>() << state, assn.object, assn.propertyName); never executed: unregisterRestorables(QList<QAbstractState*>() << state, assn.object, assn.propertyName); | 0 | ||||||||||||||||||
| 1643 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1644 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 1645 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 1646 | - | |||||||||||||||||||
| 1647 | void QStateMachinePrivate::initializeAnimations(QAbstractState *state, const QList<QAbstractAnimation *> &selectedAnimations, | - | ||||||||||||||||||
| 1648 | const QList<QAbstractState*> &exitedStates_sorted, | - | ||||||||||||||||||
| 1649 | QHash<QAbstractState*, QVector<QPropertyAssignment> > &assignmentsForEnteredStates) | - | ||||||||||||||||||
| 1650 | { | - | ||||||||||||||||||
| 1651 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1652 | if (!assignmentsForEnteredStates.contains(state))
| 115-1392 | ||||||||||||||||||
| 1653 | return; executed 1392 times by 2 tests: return;Executed by:
| 1392 | ||||||||||||||||||
| 1654 | QVector<QPropertyAssignment> &assignments = assignmentsForEnteredStates[state]; | - | ||||||||||||||||||
| 1655 | for (int i = 0; i < selectedAnimations.size(); ++i) {
| 41-85 | ||||||||||||||||||
| 1656 | QAbstractAnimation *anim = selectedAnimations.at(i); | - | ||||||||||||||||||
| 1657 | QVector<QPropertyAssignment>::iterator it; | - | ||||||||||||||||||
| 1658 | for (it = assignments.begin(); it != assignments.end(); ) {
| 41-47 | ||||||||||||||||||
| 1659 | const QPropertyAssignment &assn = *it; | - | ||||||||||||||||||
| 1660 | const auto ret = initializeAnimation(anim, assn); | - | ||||||||||||||||||
| 1661 | if (!ret.handledAnimations.isEmpty()) {
| 11-36 | ||||||||||||||||||
| 1662 | for (int j = 0; j < ret.handledAnimations.size(); ++j) {
| 36 | ||||||||||||||||||
| 1663 | QAbstractAnimation *a = ret.handledAnimations.at(j); | - | ||||||||||||||||||
| 1664 | propertyForAnimation.insert(a, assn); | - | ||||||||||||||||||
| 1665 | stateForAnimation.insert(a, state); | - | ||||||||||||||||||
| 1666 | animationsForState[state].append(a); | - | ||||||||||||||||||
| 1667 | // ### connect to just the top-level animation? | - | ||||||||||||||||||
| 1668 | QObject::connect(a, SIGNAL(finished()), q, SLOT(_q_animationFinished()), Qt::UniqueConnection); | - | ||||||||||||||||||
| 1669 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 1670 | if ((globalRestorePolicy == QState::RestoreProperties)
| 12-24 | ||||||||||||||||||
| 1671 | && !hasRestorable(state, assn.object, assn.propertyName)) {
| 0-12 | ||||||||||||||||||
| 1672 | QVariant value = savedValueForRestorable(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 1673 | unregisterRestorables(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 1674 | registerRestorable(state, assn.object, assn.propertyName, value); | - | ||||||||||||||||||
| 1675 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1676 | it = assignments.erase(it); | - | ||||||||||||||||||
| 1677 | } else { executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 1678 | ++it; | - | ||||||||||||||||||
| 1679 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 1680 | for (int j = 0; j < ret.localResetEndValues.size(); ++j)
| 35-47 | ||||||||||||||||||
| 1681 | resetAnimationEndValues.insert(ret.localResetEndValues.at(j)); executed 35 times by 1 test: resetAnimationEndValues.insert(ret.localResetEndValues.at(j));Executed by:
| 35 | ||||||||||||||||||
| 1682 | } executed 47 times by 1 test: end of blockExecuted by:
| 47 | ||||||||||||||||||
| 1683 | // We require that at least one animation is valid. | - | ||||||||||||||||||
| 1684 | // ### generalize | - | ||||||||||||||||||
| 1685 | QList<QVariantAnimation*> variantAnims = anim->findChildren<QVariantAnimation*>(); | - | ||||||||||||||||||
| 1686 | if (QVariantAnimation *va = qobject_cast<QVariantAnimation*>(anim))
| 3-38 | ||||||||||||||||||
| 1687 | variantAnims.append(va); executed 38 times by 1 test: variantAnims.append(va);Executed by:
| 38 | ||||||||||||||||||
| 1688 | - | |||||||||||||||||||
| 1689 | bool hasValidEndValue = false; | - | ||||||||||||||||||
| 1690 | for (int j = 0; j < variantAnims.size(); ++j) {
| 2-41 | ||||||||||||||||||
| 1691 | if (variantAnims.at(j)->endValue().isValid()) {
| 2-39 | ||||||||||||||||||
| 1692 | hasValidEndValue = true; | - | ||||||||||||||||||
| 1693 | break; executed 39 times by 1 test: break;Executed by:
| 39 | ||||||||||||||||||
| 1694 | } | - | ||||||||||||||||||
| 1695 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1696 | - | |||||||||||||||||||
| 1697 | if (hasValidEndValue) {
| 2-39 | ||||||||||||||||||
| 1698 | if (anim->state() == QAbstractAnimation::Running) {
| 5-34 | ||||||||||||||||||
| 1699 | // The animation is still running. This can happen if the | - | ||||||||||||||||||
| 1700 | // animation is a group, and one of its children just finished, | - | ||||||||||||||||||
| 1701 | // and that caused a state to emit its propertiesAssigned() signal, and | - | ||||||||||||||||||
| 1702 | // that triggered a transition in the machine. | - | ||||||||||||||||||
| 1703 | // Just stop the animation so it is correctly restarted again. | - | ||||||||||||||||||
| 1704 | anim->stop(); | - | ||||||||||||||||||
| 1705 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 1706 | anim->start(); | - | ||||||||||||||||||
| 1707 | } executed 39 times by 1 test: end of blockExecuted by:
| 39 | ||||||||||||||||||
| 1708 | - | |||||||||||||||||||
| 1709 | if (assignments.isEmpty()) {
| 11-30 | ||||||||||||||||||
| 1710 | assignmentsForEnteredStates.remove(state); | - | ||||||||||||||||||
| 1711 | break; executed 30 times by 1 test: break;Executed by:
| 30 | ||||||||||||||||||
| 1712 | } | - | ||||||||||||||||||
| 1713 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 1714 | } executed 115 times by 2 tests: end of blockExecuted by:
| 115 | ||||||||||||||||||
| 1715 | - | |||||||||||||||||||
| 1716 | #endif // !QT_NO_ANIMATION | - | ||||||||||||||||||
| 1717 | - | |||||||||||||||||||
| 1718 | QAbstractTransition *QStateMachinePrivate::createInitialTransition() const | - | ||||||||||||||||||
| 1719 | { | - | ||||||||||||||||||
| 1720 | class InitialTransition : public QAbstractTransition | - | ||||||||||||||||||
| 1721 | { | - | ||||||||||||||||||
| 1722 | public: | - | ||||||||||||||||||
| 1723 | InitialTransition(const QList<QAbstractState *> &targets) | - | ||||||||||||||||||
| 1724 | : QAbstractTransition() | - | ||||||||||||||||||
| 1725 | { setTargetStates(targets); } executed 153 times by 2 tests: end of blockExecuted by:
| 153 | ||||||||||||||||||
| 1726 | protected: | - | ||||||||||||||||||
| 1727 | virtual bool eventTest(QEvent *) Q_DECL_OVERRIDE { return true; } never executed: return true; | 0 | ||||||||||||||||||
| 1728 | virtual void onTransition(QEvent *) Q_DECL_OVERRIDE {} | - | ||||||||||||||||||
| 1729 | }; | - | ||||||||||||||||||
| 1730 | - | |||||||||||||||||||
| 1731 | QState *root = rootState(); | - | ||||||||||||||||||
| 1732 | Q_ASSERT(root != 0); | - | ||||||||||||||||||
| 1733 | QList<QAbstractState *> targets; | - | ||||||||||||||||||
| 1734 | switch (root->childMode()) { | - | ||||||||||||||||||
| 1735 | case QState::ExclusiveStates: executed 152 times by 2 tests: case QState::ExclusiveStates:Executed by:
| 152 | ||||||||||||||||||
| 1736 | targets.append(root->initialState()); | - | ||||||||||||||||||
| 1737 | break; executed 152 times by 2 tests: break;Executed by:
| 152 | ||||||||||||||||||
| 1738 | case QState::ParallelStates: executed 1 time by 1 test: case QState::ParallelStates:Executed by:
| 1 | ||||||||||||||||||
| 1739 | targets = QStatePrivate::get(root)->childStates(); | - | ||||||||||||||||||
| 1740 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 1741 | } | - | ||||||||||||||||||
| 1742 | return new InitialTransition(targets); executed 153 times by 2 tests: return new InitialTransition(targets);Executed by:
| 153 | ||||||||||||||||||
| 1743 | } | - | ||||||||||||||||||
| 1744 | - | |||||||||||||||||||
| 1745 | void QStateMachinePrivate::clearHistory() | - | ||||||||||||||||||
| 1746 | { | - | ||||||||||||||||||
| 1747 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1748 | QList<QHistoryState*> historyStates = q->findChildren<QHistoryState*>(); | - | ||||||||||||||||||
| 1749 | for (int i = 0; i < historyStates.size(); ++i) {
| 10-153 | ||||||||||||||||||
| 1750 | QHistoryState *h = historyStates.at(i); | - | ||||||||||||||||||
| 1751 | QHistoryStatePrivate::get(h)->configuration.clear(); | - | ||||||||||||||||||
| 1752 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1753 | } executed 153 times by 2 tests: end of blockExecuted by:
| 153 | ||||||||||||||||||
| 1754 | - | |||||||||||||||||||
| 1755 | /*! | - | ||||||||||||||||||
| 1756 | \internal | - | ||||||||||||||||||
| 1757 | - | |||||||||||||||||||
| 1758 | Registers all signal transitions whose sender object lives in another thread. | - | ||||||||||||||||||
| 1759 | - | |||||||||||||||||||
| 1760 | Normally, signal transitions are lazily registered (when a state becomes | - | ||||||||||||||||||
| 1761 | active). But if the sender is in a different thread, the transition must be | - | ||||||||||||||||||
| 1762 | registered early to keep the state machine from "dropping" signals; e.g., | - | ||||||||||||||||||
| 1763 | a second (transition-bound) signal could be emitted on the sender thread | - | ||||||||||||||||||
| 1764 | before the state machine gets to process the first signal. | - | ||||||||||||||||||
| 1765 | */ | - | ||||||||||||||||||
| 1766 | void QStateMachinePrivate::registerMultiThreadedSignalTransitions() | - | ||||||||||||||||||
| 1767 | { | - | ||||||||||||||||||
| 1768 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1769 | QList<QSignalTransition*> transitions = rootState()->findChildren<QSignalTransition*>(); | - | ||||||||||||||||||
| 1770 | for (int i = 0; i < transitions.size(); ++i) {
| 81-153 | ||||||||||||||||||
| 1771 | QSignalTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 1772 | if ((t->machine() == q) && t->senderObject() && (t->senderObject()->thread() != q->thread()))
| 1-78 | ||||||||||||||||||
| 1773 | registerSignalTransition(t); executed 7 times by 1 test: registerSignalTransition(t);Executed by:
| 7 | ||||||||||||||||||
| 1774 | } executed 81 times by 2 tests: end of blockExecuted by:
| 81 | ||||||||||||||||||
| 1775 | } executed 153 times by 2 tests: end of blockExecuted by:
| 153 | ||||||||||||||||||
| 1776 | - | |||||||||||||||||||
| 1777 | void QStateMachinePrivate::_q_start() | - | ||||||||||||||||||
| 1778 | { | - | ||||||||||||||||||
| 1779 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1780 | Q_ASSERT(state == Starting); | - | ||||||||||||||||||
| 1781 | // iterate over a copy, since we emit signals which may cause | - | ||||||||||||||||||
| 1782 | // 'configuration' to change, resulting in undefined behavior when | - | ||||||||||||||||||
| 1783 | // iterating at the same time: | - | ||||||||||||||||||
| 1784 | const auto config = configuration; | - | ||||||||||||||||||
| 1785 | for (QAbstractState *state : config) { | - | ||||||||||||||||||
| 1786 | QAbstractStatePrivate *abstractStatePrivate = QAbstractStatePrivate::get(state); | - | ||||||||||||||||||
| 1787 | abstractStatePrivate->active = false; | - | ||||||||||||||||||
| 1788 | emit state->activeChanged(false); | - | ||||||||||||||||||
| 1789 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 1790 | configuration.clear(); | - | ||||||||||||||||||
| 1791 | qDeleteAll(internalEventQueue); | - | ||||||||||||||||||
| 1792 | internalEventQueue.clear(); | - | ||||||||||||||||||
| 1793 | qDeleteAll(externalEventQueue); | - | ||||||||||||||||||
| 1794 | externalEventQueue.clear(); | - | ||||||||||||||||||
| 1795 | clearHistory(); | - | ||||||||||||||||||
| 1796 | - | |||||||||||||||||||
| 1797 | registerMultiThreadedSignalTransitions(); | - | ||||||||||||||||||
| 1798 | - | |||||||||||||||||||
| 1799 | startupHook(); | - | ||||||||||||||||||
| 1800 | - | |||||||||||||||||||
| 1801 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1802 | qDebug() << q << ": starting"; | - | ||||||||||||||||||
| 1803 | #endif | - | ||||||||||||||||||
| 1804 | state = Running; | - | ||||||||||||||||||
| 1805 | processingScheduled = true; // we call _q_process() below | - | ||||||||||||||||||
| 1806 | - | |||||||||||||||||||
| 1807 | QList<QAbstractTransition*> transitions; | - | ||||||||||||||||||
| 1808 | CalculationCache calculationCache; | - | ||||||||||||||||||
| 1809 | QAbstractTransition *initialTransition = createInitialTransition(); | - | ||||||||||||||||||
| 1810 | transitions.append(initialTransition); | - | ||||||||||||||||||
| 1811 | - | |||||||||||||||||||
| 1812 | QEvent nullEvent(QEvent::None); | - | ||||||||||||||||||
| 1813 | executeTransitionContent(&nullEvent, transitions); | - | ||||||||||||||||||
| 1814 | QList<QAbstractState*> exitedStates = QList<QAbstractState*>(); | - | ||||||||||||||||||
| 1815 | QSet<QAbstractState*> statesForDefaultEntry; | - | ||||||||||||||||||
| 1816 | QList<QAbstractState*> enteredStates = computeEntrySet(transitions, statesForDefaultEntry, &calculationCache); | - | ||||||||||||||||||
| 1817 | QHash<RestorableId, QVariant> pendingRestorables; | - | ||||||||||||||||||
| 1818 | QHash<QAbstractState*, QVector<QPropertyAssignment> > assignmentsForEnteredStates = | - | ||||||||||||||||||
| 1819 | computePropertyAssignments(enteredStates, pendingRestorables); | - | ||||||||||||||||||
| 1820 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1821 | QList<QAbstractAnimation*> selectedAnimations = selectAnimations(transitions); | - | ||||||||||||||||||
| 1822 | #endif | - | ||||||||||||||||||
| 1823 | // enterStates() will set stopProcessingReason to Finished if a final | - | ||||||||||||||||||
| 1824 | // state is entered. | - | ||||||||||||||||||
| 1825 | stopProcessingReason = EventQueueEmpty; | - | ||||||||||||||||||
| 1826 | enterStates(&nullEvent, exitedStates, enteredStates, statesForDefaultEntry, | - | ||||||||||||||||||
| 1827 | assignmentsForEnteredStates | - | ||||||||||||||||||
| 1828 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1829 | , selectedAnimations | - | ||||||||||||||||||
| 1830 | #endif | - | ||||||||||||||||||
| 1831 | ); | - | ||||||||||||||||||
| 1832 | delete initialTransition; | - | ||||||||||||||||||
| 1833 | - | |||||||||||||||||||
| 1834 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1835 | qDebug() << q << ": initial configuration:" << configuration; | - | ||||||||||||||||||
| 1836 | #endif | - | ||||||||||||||||||
| 1837 | - | |||||||||||||||||||
| 1838 | emit q->started(QStateMachine::QPrivateSignal()); | - | ||||||||||||||||||
| 1839 | emit q->runningChanged(true); | - | ||||||||||||||||||
| 1840 | - | |||||||||||||||||||
| 1841 | if (stopProcessingReason == Finished) {
| 2-151 | ||||||||||||||||||
| 1842 | // The state machine immediately reached a final state. | - | ||||||||||||||||||
| 1843 | processingScheduled = false; | - | ||||||||||||||||||
| 1844 | state = NotRunning; | - | ||||||||||||||||||
| 1845 | unregisterAllTransitions(); | - | ||||||||||||||||||
| 1846 | emitFinished(); | - | ||||||||||||||||||
| 1847 | emit q->runningChanged(false); | - | ||||||||||||||||||
| 1848 | exitInterpreter(); | - | ||||||||||||||||||
| 1849 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1850 | _q_process(); | - | ||||||||||||||||||
| 1851 | } executed 151 times by 2 tests: end of blockExecuted by:
| 151 | ||||||||||||||||||
| 1852 | } | - | ||||||||||||||||||
| 1853 | - | |||||||||||||||||||
| 1854 | void QStateMachinePrivate::_q_process() | - | ||||||||||||||||||
| 1855 | { | - | ||||||||||||||||||
| 1856 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1857 | Q_ASSERT(state == Running); | - | ||||||||||||||||||
| 1858 | Q_ASSERT(!processing); | - | ||||||||||||||||||
| 1859 | processing = true; | - | ||||||||||||||||||
| 1860 | processingScheduled = false; | - | ||||||||||||||||||
| 1861 | beginMacrostep(); | - | ||||||||||||||||||
| 1862 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1863 | qDebug() << q << ": starting the event processing loop"; | - | ||||||||||||||||||
| 1864 | #endif | - | ||||||||||||||||||
| 1865 | bool didChange = false; | - | ||||||||||||||||||
| 1866 | while (processing) {
| 355-1548 | ||||||||||||||||||
| 1867 | if (stop) {
| 19-1529 | ||||||||||||||||||
| 1868 | processing = false; | - | ||||||||||||||||||
| 1869 | break; executed 19 times by 1 test: break;Executed by:
| 19 | ||||||||||||||||||
| 1870 | } | - | ||||||||||||||||||
| 1871 | QList<QAbstractTransition*> enabledTransitions; | - | ||||||||||||||||||
| 1872 | CalculationCache calculationCache; | - | ||||||||||||||||||
| 1873 | - | |||||||||||||||||||
| 1874 | QEvent *e = new QEvent(QEvent::None); | - | ||||||||||||||||||
| 1875 | enabledTransitions = selectTransitions(e, &calculationCache); | - | ||||||||||||||||||
| 1876 | if (enabledTransitions.isEmpty()) {
| 25-1504 | ||||||||||||||||||
| 1877 | delete e; | - | ||||||||||||||||||
| 1878 | e = 0; | - | ||||||||||||||||||
| 1879 | } executed 1504 times by 2 tests: end of blockExecuted by:
| 1504 | ||||||||||||||||||
| 1880 | while (enabledTransitions.isEmpty() && ((e = dequeueInternalEvent()) != 0)) {
| 99-1512 | ||||||||||||||||||
| 1881 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1882 | qDebug() << q << ": dequeued internal event" << e << "of type" << e->type(); | - | ||||||||||||||||||
| 1883 | #endif | - | ||||||||||||||||||
| 1884 | enabledTransitions = selectTransitions(e, &calculationCache); | - | ||||||||||||||||||
| 1885 | if (enabledTransitions.isEmpty()) {
| 8-91 | ||||||||||||||||||
| 1886 | delete e; | - | ||||||||||||||||||
| 1887 | e = 0; | - | ||||||||||||||||||
| 1888 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 1889 | } executed 99 times by 2 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1890 | while (enabledTransitions.isEmpty() && ((e = dequeueExternalEvent()) != 0)) {
| 294-2416 | ||||||||||||||||||
| 1891 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1892 | qDebug() << q << ": dequeued external event" << e << "of type" << e->type(); | - | ||||||||||||||||||
| 1893 | #endif | - | ||||||||||||||||||
| 1894 | enabledTransitions = selectTransitions(e, &calculationCache); | - | ||||||||||||||||||
| 1895 | if (enabledTransitions.isEmpty()) {
| 1003-1119 | ||||||||||||||||||
| 1896 | delete e; | - | ||||||||||||||||||
| 1897 | e = 0; | - | ||||||||||||||||||
| 1898 | } executed 1003 times by 1 test: end of blockExecuted by:
| 1003 | ||||||||||||||||||
| 1899 | } executed 2122 times by 2 tests: end of blockExecuted by:
| 2122 | ||||||||||||||||||
| 1900 | if (enabledTransitions.isEmpty()) {
| 294-1235 | ||||||||||||||||||
| 1901 | if (isInternalEventQueueEmpty()) {
| 1-293 | ||||||||||||||||||
| 1902 | processing = false; | - | ||||||||||||||||||
| 1903 | stopProcessingReason = EventQueueEmpty; | - | ||||||||||||||||||
| 1904 | noMicrostep(); | - | ||||||||||||||||||
| 1905 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1906 | qDebug() << q << ": no transitions enabled"; | - | ||||||||||||||||||
| 1907 | #endif | - | ||||||||||||||||||
| 1908 | } executed 293 times by 2 tests: end of blockExecuted by:
| 293 | ||||||||||||||||||
| 1909 | } else { executed 294 times by 2 tests: end of blockExecuted by:
| 294 | ||||||||||||||||||
| 1910 | didChange = true; | - | ||||||||||||||||||
| 1911 | q->beginMicrostep(e); | - | ||||||||||||||||||
| 1912 | microstep(e, enabledTransitions, &calculationCache); | - | ||||||||||||||||||
| 1913 | q->endMicrostep(e); | - | ||||||||||||||||||
| 1914 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 1915 | delete e; | - | ||||||||||||||||||
| 1916 | } executed 1529 times by 2 tests: end of blockExecuted by:
| 1529 | ||||||||||||||||||
| 1917 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1918 | qDebug() << q << ": finished the event processing loop"; | - | ||||||||||||||||||
| 1919 | #endif | - | ||||||||||||||||||
| 1920 | if (stop) {
| 22-352 | ||||||||||||||||||
| 1921 | stop = false; | - | ||||||||||||||||||
| 1922 | stopProcessingReason = Stopped; | - | ||||||||||||||||||
| 1923 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 1924 | - | |||||||||||||||||||
| 1925 | switch (stopProcessingReason) { | - | ||||||||||||||||||
| 1926 | case EventQueueEmpty: executed 291 times by 2 tests: case EventQueueEmpty:Executed by:
| 291 | ||||||||||||||||||
| 1927 | processedPendingEvents(didChange); | - | ||||||||||||||||||
| 1928 | break; executed 291 times by 2 tests: break;Executed by:
| 291 | ||||||||||||||||||
| 1929 | case Finished: executed 61 times by 1 test: case Finished:Executed by:
| 61 | ||||||||||||||||||
| 1930 | state = NotRunning; | - | ||||||||||||||||||
| 1931 | cancelAllDelayedEvents(); | - | ||||||||||||||||||
| 1932 | unregisterAllTransitions(); | - | ||||||||||||||||||
| 1933 | emitFinished(); | - | ||||||||||||||||||
| 1934 | emit q->runningChanged(false); | - | ||||||||||||||||||
| 1935 | break; executed 61 times by 1 test: break;Executed by:
| 61 | ||||||||||||||||||
| 1936 | case Stopped: executed 22 times by 1 test: case Stopped:Executed by:
| 22 | ||||||||||||||||||
| 1937 | state = NotRunning; | - | ||||||||||||||||||
| 1938 | cancelAllDelayedEvents(); | - | ||||||||||||||||||
| 1939 | unregisterAllTransitions(); | - | ||||||||||||||||||
| 1940 | emit q->stopped(QStateMachine::QPrivateSignal()); | - | ||||||||||||||||||
| 1941 | emit q->runningChanged(false); | - | ||||||||||||||||||
| 1942 | break; executed 22 times by 1 test: break;Executed by:
| 22 | ||||||||||||||||||
| 1943 | } | - | ||||||||||||||||||
| 1944 | endMacrostep(didChange); | - | ||||||||||||||||||
| 1945 | if (stopProcessingReason == Finished)
| 61-313 | ||||||||||||||||||
| 1946 | exitInterpreter(); executed 61 times by 1 test: exitInterpreter();Executed by:
| 61 | ||||||||||||||||||
| 1947 | } executed 374 times by 2 tests: end of blockExecuted by:
| 374 | ||||||||||||||||||
| 1948 | - | |||||||||||||||||||
| 1949 | void QStateMachinePrivate::_q_startDelayedEventTimer(int id, int delay) | - | ||||||||||||||||||
| 1950 | { | - | ||||||||||||||||||
| 1951 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1952 | QMutexLocker locker(&delayedEventsMutex); | - | ||||||||||||||||||
| 1953 | QHash<int, DelayedEvent>::iterator it = delayedEvents.find(id); | - | ||||||||||||||||||
| 1954 | if (it != delayedEvents.end()) {
| 1 | ||||||||||||||||||
| 1955 | DelayedEvent &e = it.value(); | - | ||||||||||||||||||
| 1956 | Q_ASSERT(!e.timerId); | - | ||||||||||||||||||
| 1957 | e.timerId = q->startTimer(delay); | - | ||||||||||||||||||
| 1958 | if (!e.timerId) {
| 0-1 | ||||||||||||||||||
| 1959 | qWarning("QStateMachine::postDelayedEvent: failed to start timer (id=%d, delay=%d)", id, delay); | - | ||||||||||||||||||
| 1960 | delete e.event; | - | ||||||||||||||||||
| 1961 | delayedEvents.erase(it); | - | ||||||||||||||||||
| 1962 | delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 1963 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1964 | timerIdToDelayedEventId.insert(e.timerId, id); | - | ||||||||||||||||||
| 1965 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 1966 | } else { | - | ||||||||||||||||||
| 1967 | // It's been cancelled already | - | ||||||||||||||||||
| 1968 | delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 1969 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 1970 | } | - | ||||||||||||||||||
| 1971 | - | |||||||||||||||||||
| 1972 | void QStateMachinePrivate::_q_killDelayedEventTimer(int id, int timerId) | - | ||||||||||||||||||
| 1973 | { | - | ||||||||||||||||||
| 1974 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1975 | q->killTimer(timerId); | - | ||||||||||||||||||
| 1976 | QMutexLocker locker(&delayedEventsMutex); | - | ||||||||||||||||||
| 1977 | delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 1978 | } never executed: end of block | 0 | ||||||||||||||||||
| 1979 | - | |||||||||||||||||||
| 1980 | void QStateMachinePrivate::postInternalEvent(QEvent *e) | - | ||||||||||||||||||
| 1981 | { | - | ||||||||||||||||||
| 1982 | QMutexLocker locker(&internalEventMutex); | - | ||||||||||||||||||
| 1983 | internalEventQueue.append(e); | - | ||||||||||||||||||
| 1984 | } executed 99 times by 2 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1985 | - | |||||||||||||||||||
| 1986 | void QStateMachinePrivate::postExternalEvent(QEvent *e) | - | ||||||||||||||||||
| 1987 | { | - | ||||||||||||||||||
| 1988 | QMutexLocker locker(&externalEventMutex); | - | ||||||||||||||||||
| 1989 | externalEventQueue.append(e); | - | ||||||||||||||||||
| 1990 | } executed 2123 times by 2 tests: end of blockExecuted by:
| 2123 | ||||||||||||||||||
| 1991 | - | |||||||||||||||||||
| 1992 | QEvent *QStateMachinePrivate::dequeueInternalEvent() | - | ||||||||||||||||||
| 1993 | { | - | ||||||||||||||||||
| 1994 | QMutexLocker locker(&internalEventMutex); | - | ||||||||||||||||||
| 1995 | if (internalEventQueue.isEmpty())
| 99-1413 | ||||||||||||||||||
| 1996 | return 0; executed 1413 times by 2 tests: return 0;Executed by:
| 1413 | ||||||||||||||||||
| 1997 | return internalEventQueue.takeFirst(); executed 99 times by 2 tests: return internalEventQueue.takeFirst();Executed by:
| 99 | ||||||||||||||||||
| 1998 | } | - | ||||||||||||||||||
| 1999 | - | |||||||||||||||||||
| 2000 | QEvent *QStateMachinePrivate::dequeueExternalEvent() | - | ||||||||||||||||||
| 2001 | { | - | ||||||||||||||||||
| 2002 | QMutexLocker locker(&externalEventMutex); | - | ||||||||||||||||||
| 2003 | if (externalEventQueue.isEmpty())
| 294-2122 | ||||||||||||||||||
| 2004 | return 0; executed 294 times by 2 tests: return 0;Executed by:
| 294 | ||||||||||||||||||
| 2005 | return externalEventQueue.takeFirst(); executed 2122 times by 2 tests: return externalEventQueue.takeFirst();Executed by:
| 2122 | ||||||||||||||||||
| 2006 | } | - | ||||||||||||||||||
| 2007 | - | |||||||||||||||||||
| 2008 | bool QStateMachinePrivate::isInternalEventQueueEmpty() | - | ||||||||||||||||||
| 2009 | { | - | ||||||||||||||||||
| 2010 | QMutexLocker locker(&internalEventMutex); | - | ||||||||||||||||||
| 2011 | return internalEventQueue.isEmpty(); executed 294 times by 2 tests: return internalEventQueue.isEmpty();Executed by:
| 294 | ||||||||||||||||||
| 2012 | } | - | ||||||||||||||||||
| 2013 | - | |||||||||||||||||||
| 2014 | bool QStateMachinePrivate::isExternalEventQueueEmpty() | - | ||||||||||||||||||
| 2015 | { | - | ||||||||||||||||||
| 2016 | QMutexLocker locker(&externalEventMutex); | - | ||||||||||||||||||
| 2017 | return externalEventQueue.isEmpty(); never executed: return externalEventQueue.isEmpty(); | 0 | ||||||||||||||||||
| 2018 | } | - | ||||||||||||||||||
| 2019 | - | |||||||||||||||||||
| 2020 | void QStateMachinePrivate::processEvents(EventProcessingMode processingMode) | - | ||||||||||||||||||
| 2021 | { | - | ||||||||||||||||||
| 2022 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2023 | if ((state != Running) || processing || processingScheduled)
| 0-2249 | ||||||||||||||||||
| 2024 | return; executed 2026 times by 1 test: return;Executed by:
| 2026 | ||||||||||||||||||
| 2025 | switch (processingMode) { | - | ||||||||||||||||||
| 2026 | case DirectProcessing: executed 93 times by 2 tests: case DirectProcessing:Executed by:
| 93 | ||||||||||||||||||
| 2027 | if (QThread::currentThread() == q->thread()) {
| 0-93 | ||||||||||||||||||
| 2028 | _q_process(); | - | ||||||||||||||||||
| 2029 | break; executed 93 times by 2 tests: break;Executed by:
| 93 | ||||||||||||||||||
| 2030 | } // fallthrough -- processing must be done in the machine thread | - | ||||||||||||||||||
| 2031 | case QueuedProcessing: code before this statement never executed: case QueuedProcessing:executed 130 times by 2 tests: case QueuedProcessing:Executed by:
| 0-130 | ||||||||||||||||||
| 2032 | processingScheduled = true; | - | ||||||||||||||||||
| 2033 | QMetaObject::invokeMethod(q, "_q_process", Qt::QueuedConnection); | - | ||||||||||||||||||
| 2034 | break; executed 130 times by 2 tests: break;Executed by:
| 130 | ||||||||||||||||||
| 2035 | } | - | ||||||||||||||||||
| 2036 | } executed 223 times by 2 tests: end of blockExecuted by:
| 223 | ||||||||||||||||||
| 2037 | - | |||||||||||||||||||
| 2038 | void QStateMachinePrivate::cancelAllDelayedEvents() | - | ||||||||||||||||||
| 2039 | { | - | ||||||||||||||||||
| 2040 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2041 | QMutexLocker locker(&delayedEventsMutex); | - | ||||||||||||||||||
| 2042 | QHash<int, DelayedEvent>::const_iterator it; | - | ||||||||||||||||||
| 2043 | for (it = delayedEvents.constBegin(); it != delayedEvents.constEnd(); ++it) {
| 2-83 | ||||||||||||||||||
| 2044 | const DelayedEvent &e = it.value(); | - | ||||||||||||||||||
| 2045 | if (e.timerId) {
| 0-2 | ||||||||||||||||||
| 2046 | timerIdToDelayedEventId.remove(e.timerId); | - | ||||||||||||||||||
| 2047 | q->killTimer(e.timerId); | - | ||||||||||||||||||
| 2048 | delayedEventIdFreeList.release(it.key()); | - | ||||||||||||||||||
| 2049 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2050 | // Cancellation will be detected in pending _q_startDelayedEventTimer() call | - | ||||||||||||||||||
| 2051 | } never executed: end of block | 0 | ||||||||||||||||||
| 2052 | delete e.event; | - | ||||||||||||||||||
| 2053 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2054 | delayedEvents.clear(); | - | ||||||||||||||||||
| 2055 | } executed 83 times by 1 test: end of blockExecuted by:
| 83 | ||||||||||||||||||
| 2056 | - | |||||||||||||||||||
| 2057 | /* | - | ||||||||||||||||||
| 2058 | This function is called when the state machine is performing no | - | ||||||||||||||||||
| 2059 | microstep because no transition is enabled (i.e. an event is ignored). | - | ||||||||||||||||||
| 2060 | - | |||||||||||||||||||
| 2061 | The default implementation does nothing. | - | ||||||||||||||||||
| 2062 | */ | - | ||||||||||||||||||
| 2063 | void QStateMachinePrivate::noMicrostep() | - | ||||||||||||||||||
| 2064 | { } | - | ||||||||||||||||||
| 2065 | - | |||||||||||||||||||
| 2066 | /* | - | ||||||||||||||||||
| 2067 | This function is called when the state machine has reached a stable | - | ||||||||||||||||||
| 2068 | state (no pending events), and has not finished yet. | - | ||||||||||||||||||
| 2069 | For each event the state machine receives it is guaranteed that | - | ||||||||||||||||||
| 2070 | 1) beginMacrostep is called | - | ||||||||||||||||||
| 2071 | 2) selectTransition is called at least once | - | ||||||||||||||||||
| 2072 | 3) begin/endMicrostep is called at least once or noMicrostep is called | - | ||||||||||||||||||
| 2073 | at least once (possibly both, but at least one) | - | ||||||||||||||||||
| 2074 | 4) the state machine either enters an infinite loop, or stops (runningChanged(false), | - | ||||||||||||||||||
| 2075 | and either finished or stopped are emitted), or processedPendingEvents() is called. | - | ||||||||||||||||||
| 2076 | 5) if the machine is not in an infinite loop endMacrostep is called | - | ||||||||||||||||||
| 2077 | 6) when the machine is finished and all processing (like signal emission) is done, | - | ||||||||||||||||||
| 2078 | exitInterpreter() is called. (This is the same name as the SCXML specification uses.) | - | ||||||||||||||||||
| 2079 | - | |||||||||||||||||||
| 2080 | didChange is set to true if at least one microstep was performed, it is possible | - | ||||||||||||||||||
| 2081 | that the machine returned to exactly the same state as before, but some transitions | - | ||||||||||||||||||
| 2082 | were triggered. | - | ||||||||||||||||||
| 2083 | - | |||||||||||||||||||
| 2084 | The default implementation does nothing. | - | ||||||||||||||||||
| 2085 | */ | - | ||||||||||||||||||
| 2086 | void QStateMachinePrivate::processedPendingEvents(bool didChange) | - | ||||||||||||||||||
| 2087 | { | - | ||||||||||||||||||
| 2088 | Q_UNUSED(didChange); | - | ||||||||||||||||||
| 2089 | } executed 291 times by 2 tests: end of blockExecuted by:
| 291 | ||||||||||||||||||
| 2090 | - | |||||||||||||||||||
| 2091 | void QStateMachinePrivate::beginMacrostep() | - | ||||||||||||||||||
| 2092 | { } | - | ||||||||||||||||||
| 2093 | - | |||||||||||||||||||
| 2094 | void QStateMachinePrivate::endMacrostep(bool didChange) | - | ||||||||||||||||||
| 2095 | { | - | ||||||||||||||||||
| 2096 | Q_UNUSED(didChange); | - | ||||||||||||||||||
| 2097 | } executed 374 times by 2 tests: end of blockExecuted by:
| 374 | ||||||||||||||||||
| 2098 | - | |||||||||||||||||||
| 2099 | void QStateMachinePrivate::exitInterpreter() | - | ||||||||||||||||||
| 2100 | { | - | ||||||||||||||||||
| 2101 | } | - | ||||||||||||||||||
| 2102 | - | |||||||||||||||||||
| 2103 | void QStateMachinePrivate::emitStateFinished(QState *forState, QFinalState *guiltyState) | - | ||||||||||||||||||
| 2104 | { | - | ||||||||||||||||||
| 2105 | Q_UNUSED(guiltyState); | - | ||||||||||||||||||
| 2106 | Q_ASSERT(guiltyState); | - | ||||||||||||||||||
| 2107 | - | |||||||||||||||||||
| 2108 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2109 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2110 | qDebug() << q << ": emitting finished signal for" << forState; | - | ||||||||||||||||||
| 2111 | #endif | - | ||||||||||||||||||
| 2112 | - | |||||||||||||||||||
| 2113 | QStatePrivate::get(forState)->emitFinished(); | - | ||||||||||||||||||
| 2114 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 2115 | - | |||||||||||||||||||
| 2116 | void QStateMachinePrivate::startupHook() | - | ||||||||||||||||||
| 2117 | { | - | ||||||||||||||||||
| 2118 | } | - | ||||||||||||||||||
| 2119 | - | |||||||||||||||||||
| 2120 | namespace _QStateMachine_Internal{ | - | ||||||||||||||||||
| 2121 | - | |||||||||||||||||||
| 2122 | class GoToStateTransition : public QAbstractTransition | - | ||||||||||||||||||
| 2123 | { | - | ||||||||||||||||||
| 2124 | Q_OBJECT | - | ||||||||||||||||||
| 2125 | public: | - | ||||||||||||||||||
| 2126 | GoToStateTransition(QAbstractState *target) | - | ||||||||||||||||||
| 2127 | : QAbstractTransition() | - | ||||||||||||||||||
| 2128 | { setTargetState(target); } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 2129 | protected: | - | ||||||||||||||||||
| 2130 | void onTransition(QEvent *) Q_DECL_OVERRIDE { deleteLater(); } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 2131 | bool eventTest(QEvent *) Q_DECL_OVERRIDE { return true; } executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 2132 | }; | - | ||||||||||||||||||
| 2133 | - | |||||||||||||||||||
| 2134 | } // namespace | - | ||||||||||||||||||
| 2135 | // mingw compiler tries to export QObject::findChild<GoToStateTransition>(), | - | ||||||||||||||||||
| 2136 | // which doesn't work if its in an anonymous namespace. | - | ||||||||||||||||||
| 2137 | using namespace _QStateMachine_Internal; | - | ||||||||||||||||||
| 2138 | /*! | - | ||||||||||||||||||
| 2139 | \internal | - | ||||||||||||||||||
| 2140 | - | |||||||||||||||||||
| 2141 | Causes this state machine to unconditionally transition to the given | - | ||||||||||||||||||
| 2142 | \a targetState. | - | ||||||||||||||||||
| 2143 | - | |||||||||||||||||||
| 2144 | Provides a backdoor for using the state machine "imperatively"; i.e. rather | - | ||||||||||||||||||
| 2145 | than defining explicit transitions, you drive the machine's execution by | - | ||||||||||||||||||
| 2146 | calling this function. It breaks the whole integrity of the | - | ||||||||||||||||||
| 2147 | transition-driven model, but is provided for pragmatic reasons. | - | ||||||||||||||||||
| 2148 | */ | - | ||||||||||||||||||
| 2149 | void QStateMachinePrivate::goToState(QAbstractState *targetState) | - | ||||||||||||||||||
| 2150 | { | - | ||||||||||||||||||
| 2151 | if (!targetState) {
| 0-7 | ||||||||||||||||||
| 2152 | qWarning("QStateMachine::goToState(): cannot go to null state"); | - | ||||||||||||||||||
| 2153 | return; never executed: return; | 0 | ||||||||||||||||||
| 2154 | } | - | ||||||||||||||||||
| 2155 | - | |||||||||||||||||||
| 2156 | if (configuration.contains(targetState))
| 2-5 | ||||||||||||||||||
| 2157 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 2158 | - | |||||||||||||||||||
| 2159 | Q_ASSERT(state == Running); | - | ||||||||||||||||||
| 2160 | QState *sourceState = 0; | - | ||||||||||||||||||
| 2161 | QSet<QAbstractState*>::const_iterator it; | - | ||||||||||||||||||
| 2162 | for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
| 0-5 | ||||||||||||||||||
| 2163 | sourceState = toStandardState(*it); | - | ||||||||||||||||||
| 2164 | if (sourceState != 0)
| 0-5 | ||||||||||||||||||
| 2165 | break; executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||
| 2166 | } never executed: end of block | 0 | ||||||||||||||||||
| 2167 | - | |||||||||||||||||||
| 2168 | Q_ASSERT(sourceState != 0); | - | ||||||||||||||||||
| 2169 | // Reuse previous GoToStateTransition in case of several calls to | - | ||||||||||||||||||
| 2170 | // goToState() in a row. | - | ||||||||||||||||||
| 2171 | GoToStateTransition *trans = sourceState->findChild<GoToStateTransition*>(); | - | ||||||||||||||||||
| 2172 | if (!trans) {
| 1-4 | ||||||||||||||||||
| 2173 | trans = new GoToStateTransition(targetState); | - | ||||||||||||||||||
| 2174 | sourceState->addTransition(trans); | - | ||||||||||||||||||
| 2175 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 2176 | trans->setTargetState(targetState); | - | ||||||||||||||||||
| 2177 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2178 | - | |||||||||||||||||||
| 2179 | processEvents(QueuedProcessing); | - | ||||||||||||||||||
| 2180 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 2181 | - | |||||||||||||||||||
| 2182 | void QStateMachinePrivate::registerTransitions(QAbstractState *state) | - | ||||||||||||||||||
| 2183 | { | - | ||||||||||||||||||
| 2184 | QState *group = toStandardState(state); | - | ||||||||||||||||||
| 2185 | if (!group)
| 72-1435 | ||||||||||||||||||
| 2186 | return; executed 72 times by 1 test: return;Executed by:
| 72 | ||||||||||||||||||
| 2187 | QList<QAbstractTransition*> transitions = QStatePrivate::get(group)->transitions(); | - | ||||||||||||||||||
| 2188 | for (int i = 0; i < transitions.size(); ++i) {
| 1435-2314 | ||||||||||||||||||
| 2189 | QAbstractTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 2190 | registerTransition(t); | - | ||||||||||||||||||
| 2191 | } executed 2314 times by 2 tests: end of blockExecuted by:
| 2314 | ||||||||||||||||||
| 2192 | } executed 1435 times by 2 tests: end of blockExecuted by:
| 1435 | ||||||||||||||||||
| 2193 | - | |||||||||||||||||||
| 2194 | void QStateMachinePrivate::maybeRegisterTransition(QAbstractTransition *transition) | - | ||||||||||||||||||
| 2195 | { | - | ||||||||||||||||||
| 2196 | if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
| 70-154 | ||||||||||||||||||
| 2197 | maybeRegisterSignalTransition(st); | - | ||||||||||||||||||
| 2198 | } executed 70 times by 2 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 2199 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2200 | else if (QEventTransition *et = qobject_cast<QEventTransition*>(transition)) {
| 16-138 | ||||||||||||||||||
| 2201 | maybeRegisterEventTransition(et); | - | ||||||||||||||||||
| 2202 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 2203 | #endif | - | ||||||||||||||||||
| 2204 | } executed 224 times by 2 tests: end of blockExecuted by:
| 224 | ||||||||||||||||||
| 2205 | - | |||||||||||||||||||
| 2206 | void QStateMachinePrivate::registerTransition(QAbstractTransition *transition) | - | ||||||||||||||||||
| 2207 | { | - | ||||||||||||||||||
| 2208 | if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
| 1083-1231 | ||||||||||||||||||
| 2209 | registerSignalTransition(st); | - | ||||||||||||||||||
| 2210 | } executed 1083 times by 2 tests: end of blockExecuted by:
| 1083 | ||||||||||||||||||
| 2211 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2212 | else if (QEventTransition *oet = qobject_cast<QEventTransition*>(transition)) {
| 20-1211 | ||||||||||||||||||
| 2213 | registerEventTransition(oet); | - | ||||||||||||||||||
| 2214 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 2215 | #endif | - | ||||||||||||||||||
| 2216 | } executed 2314 times by 2 tests: end of blockExecuted by:
| 2314 | ||||||||||||||||||
| 2217 | - | |||||||||||||||||||
| 2218 | void QStateMachinePrivate::unregisterTransition(QAbstractTransition *transition) | - | ||||||||||||||||||
| 2219 | { | - | ||||||||||||||||||
| 2220 | if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
| 2-3 | ||||||||||||||||||
| 2221 | unregisterSignalTransition(st); | - | ||||||||||||||||||
| 2222 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2223 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2224 | else if (QEventTransition *oet = qobject_cast<QEventTransition*>(transition)) {
| 1-2 | ||||||||||||||||||
| 2225 | unregisterEventTransition(oet); | - | ||||||||||||||||||
| 2226 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2227 | #endif | - | ||||||||||||||||||
| 2228 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 2229 | - | |||||||||||||||||||
| 2230 | void QStateMachinePrivate::maybeRegisterSignalTransition(QSignalTransition *transition) | - | ||||||||||||||||||
| 2231 | { | - | ||||||||||||||||||
| 2232 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2233 | if ((state == Running) && (configuration.contains(transition->sourceState())
| 1-200012 | ||||||||||||||||||
| 2234 | || (transition->senderObject() && (transition->senderObject()->thread() != q->thread())))) {
| 0-1 | ||||||||||||||||||
| 2235 | registerSignalTransition(transition); | - | ||||||||||||||||||
| 2236 | } executed 200011 times by 1 test: end of blockExecuted by:
| 200011 | ||||||||||||||||||
| 2237 | } executed 200080 times by 2 tests: end of blockExecuted by:
| 200080 | ||||||||||||||||||
| 2238 | - | |||||||||||||||||||
| 2239 | void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transition) | - | ||||||||||||||||||
| 2240 | { | - | ||||||||||||||||||
| 2241 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2242 | if (QSignalTransitionPrivate::get(transition)->signalIndex != -1)
| 1011-200090 | ||||||||||||||||||
| 2243 | return; // already registered executed 1011 times by 1 test: return;Executed by:
| 1011 | ||||||||||||||||||
| 2244 | const QObject *sender = QSignalTransitionPrivate::get(transition)->sender; | - | ||||||||||||||||||
| 2245 | if (!sender)
| 99734-100003 | ||||||||||||||||||
| 2246 | return; executed 100003 times by 1 test: return;Executed by:
| 100003 | ||||||||||||||||||
| 2247 | QByteArray signal = QSignalTransitionPrivate::get(transition)->signal; | - | ||||||||||||||||||
| 2248 | if (signal.isEmpty())
| 1-100086 | ||||||||||||||||||
| 2249 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2250 | if (signal.startsWith('0'+QSIGNAL_CODE))
| 2-100084 | ||||||||||||||||||
| 2251 | signal.remove(0, 1); executed 100084 times by 2 tests: signal.remove(0, 1);Executed by:
| 100084 | ||||||||||||||||||
| 2252 | const QMetaObject *meta = sender->metaObject(); | - | ||||||||||||||||||
| 2253 | int signalIndex = meta->indexOfSignal(signal); | - | ||||||||||||||||||
| 2254 | int originalSignalIndex = signalIndex; | - | ||||||||||||||||||
| 2255 | if (signalIndex == -1) {
| 1-100085 | ||||||||||||||||||
| 2256 | signalIndex = meta->indexOfSignal(QMetaObject::normalizedSignature(signal)); | - | ||||||||||||||||||
| 2257 | if (signalIndex == -1) {
| 0-1 | ||||||||||||||||||
| 2258 | qWarning("QSignalTransition: no such signal: %s::%s", | - | ||||||||||||||||||
| 2259 | meta->className(), signal.constData()); | - | ||||||||||||||||||
| 2260 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2261 | } | - | ||||||||||||||||||
| 2262 | originalSignalIndex = signalIndex; | - | ||||||||||||||||||
| 2263 | } never executed: end of block | 0 | ||||||||||||||||||
| 2264 | // The signal index we actually want to connect to is the one | - | ||||||||||||||||||
| 2265 | // that is going to be sent, i.e. the non-cloned original index. | - | ||||||||||||||||||
| 2266 | while (meta->method(signalIndex).attributes() & QMetaMethod::Cloned)
| 2-100085 | ||||||||||||||||||
| 2267 | --signalIndex; executed 2 times by 1 test: --signalIndex;Executed by:
| 2 | ||||||||||||||||||
| 2268 | - | |||||||||||||||||||
| 2269 | connectionsMutex.lock(); | - | ||||||||||||||||||
| 2270 | QVector<int> &connectedSignalIndexes = connections[sender]; | - | ||||||||||||||||||
| 2271 | if (connectedSignalIndexes.size() <= signalIndex)
| 13-100072 | ||||||||||||||||||
| 2272 | connectedSignalIndexes.resize(signalIndex+1); executed 100072 times by 2 tests: connectedSignalIndexes.resize(signalIndex+1);Executed by:
| 100072 | ||||||||||||||||||
| 2273 | if (connectedSignalIndexes.at(signalIndex) == 0) {
| 12-100073 | ||||||||||||||||||
| 2274 | if (!signalEventGenerator)
| 43-100030 | ||||||||||||||||||
| 2275 | signalEventGenerator = new QSignalEventGenerator(q); executed 43 times by 2 tests: signalEventGenerator = new QSignalEventGenerator(q);Executed by:
| 43 | ||||||||||||||||||
| 2276 | static const int generatorMethodOffset = QSignalEventGenerator::staticMetaObject.methodOffset(); | - | ||||||||||||||||||
| 2277 | bool ok = QMetaObject::connect(sender, signalIndex, signalEventGenerator, generatorMethodOffset); | - | ||||||||||||||||||
| 2278 | if (!ok) {
| 0-100073 | ||||||||||||||||||
| 2279 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2280 | qDebug() << q << ": FAILED to add signal transition from" << transition->sourceState() | - | ||||||||||||||||||
| 2281 | << ": ( sender =" << sender << ", signal =" << signal | - | ||||||||||||||||||
| 2282 | << ", targets =" << transition->targetStates() << ')'; | - | ||||||||||||||||||
| 2283 | #endif | - | ||||||||||||||||||
| 2284 | return; never executed: return; | 0 | ||||||||||||||||||
| 2285 | } | - | ||||||||||||||||||
| 2286 | } executed 100073 times by 2 tests: end of blockExecuted by:
| 100073 | ||||||||||||||||||
| 2287 | ++connectedSignalIndexes[signalIndex]; | - | ||||||||||||||||||
| 2288 | connectionsMutex.unlock(); | - | ||||||||||||||||||
| 2289 | - | |||||||||||||||||||
| 2290 | QSignalTransitionPrivate::get(transition)->signalIndex = signalIndex; | - | ||||||||||||||||||
| 2291 | QSignalTransitionPrivate::get(transition)->originalSignalIndex = originalSignalIndex; | - | ||||||||||||||||||
| 2292 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2293 | qDebug() << q << ": added signal transition from" << transition->sourceState() | - | ||||||||||||||||||
| 2294 | << ": ( sender =" << sender << ", signal =" << signal | - | ||||||||||||||||||
| 2295 | << ", targets =" << transition->targetStates() << ')'; | - | ||||||||||||||||||
| 2296 | #endif | - | ||||||||||||||||||
| 2297 | } executed 100085 times by 2 tests: end of blockExecuted by:
| 100085 | ||||||||||||||||||
| 2298 | - | |||||||||||||||||||
| 2299 | void QStateMachinePrivate::unregisterSignalTransition(QSignalTransition *transition) | - | ||||||||||||||||||
| 2300 | { | - | ||||||||||||||||||
| 2301 | int signalIndex = QSignalTransitionPrivate::get(transition)->signalIndex; | - | ||||||||||||||||||
| 2302 | if (signalIndex == -1)
| 0-100049 | ||||||||||||||||||
| 2303 | return; // not registered never executed: return; | 0 | ||||||||||||||||||
| 2304 | const QObject *sender = QSignalTransitionPrivate::get(transition)->sender; | - | ||||||||||||||||||
| 2305 | QSignalTransitionPrivate::get(transition)->signalIndex = -1; | - | ||||||||||||||||||
| 2306 | - | |||||||||||||||||||
| 2307 | connectionsMutex.lock(); | - | ||||||||||||||||||
| 2308 | QVector<int> &connectedSignalIndexes = connections[sender]; | - | ||||||||||||||||||
| 2309 | Q_ASSERT(connectedSignalIndexes.size() > signalIndex); | - | ||||||||||||||||||
| 2310 | Q_ASSERT(connectedSignalIndexes.at(signalIndex) != 0); | - | ||||||||||||||||||
| 2311 | if (--connectedSignalIndexes[signalIndex] == 0) {
| 1-100048 | ||||||||||||||||||
| 2312 | Q_ASSERT(signalEventGenerator != 0); | - | ||||||||||||||||||
| 2313 | static const int generatorMethodOffset = QSignalEventGenerator::staticMetaObject.methodOffset(); | - | ||||||||||||||||||
| 2314 | QMetaObject::disconnect(sender, signalIndex, signalEventGenerator, generatorMethodOffset); | - | ||||||||||||||||||
| 2315 | int sum = 0; | - | ||||||||||||||||||
| 2316 | for (int i = 0; i < connectedSignalIndexes.size(); ++i)
| 100048-300412 | ||||||||||||||||||
| 2317 | sum += connectedSignalIndexes.at(i); executed 300412 times by 1 test: sum += connectedSignalIndexes.at(i);Executed by:
| 300412 | ||||||||||||||||||
| 2318 | if (sum == 0)
| 10-100038 | ||||||||||||||||||
| 2319 | connections.remove(sender); executed 100038 times by 1 test: connections.remove(sender);Executed by:
| 100038 | ||||||||||||||||||
| 2320 | } executed 100048 times by 1 test: end of blockExecuted by:
| 100048 | ||||||||||||||||||
| 2321 | connectionsMutex.unlock(); | - | ||||||||||||||||||
| 2322 | } executed 100049 times by 1 test: end of blockExecuted by:
| 100049 | ||||||||||||||||||
| 2323 | - | |||||||||||||||||||
| 2324 | void QStateMachinePrivate::unregisterAllTransitions() | - | ||||||||||||||||||
| 2325 | { | - | ||||||||||||||||||
| 2326 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2327 | { | - | ||||||||||||||||||
| 2328 | QList<QSignalTransition*> transitions = rootState()->findChildren<QSignalTransition*>(); | - | ||||||||||||||||||
| 2329 | for (int i = 0; i < transitions.size(); ++i) {
| 47-85 | ||||||||||||||||||
| 2330 | QSignalTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 2331 | if (t->machine() == q)
| 3-44 | ||||||||||||||||||
| 2332 | unregisterSignalTransition(t); executed 44 times by 1 test: unregisterSignalTransition(t);Executed by:
| 44 | ||||||||||||||||||
| 2333 | } executed 47 times by 1 test: end of blockExecuted by:
| 47 | ||||||||||||||||||
| 2334 | } | - | ||||||||||||||||||
| 2335 | { | - | ||||||||||||||||||
| 2336 | QList<QEventTransition*> transitions = rootState()->findChildren<QEventTransition*>(); | - | ||||||||||||||||||
| 2337 | for (int i = 0; i < transitions.size(); ++i) {
| 15-85 | ||||||||||||||||||
| 2338 | QEventTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 2339 | if (t->machine() == q)
| 0-15 | ||||||||||||||||||
| 2340 | unregisterEventTransition(t); executed 15 times by 1 test: unregisterEventTransition(t);Executed by:
| 15 | ||||||||||||||||||
| 2341 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 2342 | } | - | ||||||||||||||||||
| 2343 | } executed 85 times by 1 test: end of blockExecuted by:
| 85 | ||||||||||||||||||
| 2344 | - | |||||||||||||||||||
| 2345 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2346 | void QStateMachinePrivate::maybeRegisterEventTransition(QEventTransition *transition) | - | ||||||||||||||||||
| 2347 | { | - | ||||||||||||||||||
| 2348 | if ((state == Running) && configuration.contains(transition->sourceState()))
| 1-15 | ||||||||||||||||||
| 2349 | registerEventTransition(transition); executed 7 times by 1 test: registerEventTransition(transition);Executed by:
| 7 | ||||||||||||||||||
| 2350 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 2351 | - | |||||||||||||||||||
| 2352 | void QStateMachinePrivate::registerEventTransition(QEventTransition *transition) | - | ||||||||||||||||||
| 2353 | { | - | ||||||||||||||||||
| 2354 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2355 | if (QEventTransitionPrivate::get(transition)->registered)
| 0-27 | ||||||||||||||||||
| 2356 | return; never executed: return; | 0 | ||||||||||||||||||
| 2357 | if (transition->eventType() >= QEvent::User) {
| 1-26 | ||||||||||||||||||
| 2358 | qWarning("QObject event transitions are not supported for custom types"); | - | ||||||||||||||||||
| 2359 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2360 | } | - | ||||||||||||||||||
| 2361 | QObject *object = QEventTransitionPrivate::get(transition)->object; | - | ||||||||||||||||||
| 2362 | if (!object)
| 0-26 | ||||||||||||||||||
| 2363 | return; never executed: return; | 0 | ||||||||||||||||||
| 2364 | QObjectPrivate *od = QObjectPrivate::get(object); | - | ||||||||||||||||||
| 2365 | if (!od->extraData || !od->extraData->eventFilters.contains(q))
| 5-21 | ||||||||||||||||||
| 2366 | object->installEventFilter(q); executed 19 times by 1 test: object->installEventFilter(q);Executed by:
| 19 | ||||||||||||||||||
| 2367 | ++qobjectEvents[object][transition->eventType()]; | - | ||||||||||||||||||
| 2368 | QEventTransitionPrivate::get(transition)->registered = true; | - | ||||||||||||||||||
| 2369 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2370 | qDebug() << q << ": added event transition from" << transition->sourceState() | - | ||||||||||||||||||
| 2371 | << ": ( object =" << object << ", event =" << transition->eventType() | - | ||||||||||||||||||
| 2372 | << ", targets =" << transition->targetStates() << ')'; | - | ||||||||||||||||||
| 2373 | #endif | - | ||||||||||||||||||
| 2374 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 2375 | - | |||||||||||||||||||
| 2376 | void QStateMachinePrivate::unregisterEventTransition(QEventTransition *transition) | - | ||||||||||||||||||
| 2377 | { | - | ||||||||||||||||||
| 2378 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2379 | if (!QEventTransitionPrivate::get(transition)->registered)
| 0-20 | ||||||||||||||||||
| 2380 | return; never executed: return; | 0 | ||||||||||||||||||
| 2381 | QObject *object = QEventTransitionPrivate::get(transition)->object; | - | ||||||||||||||||||
| 2382 | QHash<QEvent::Type, int> &events = qobjectEvents[object]; | - | ||||||||||||||||||
| 2383 | Q_ASSERT(events.value(transition->eventType()) > 0); | - | ||||||||||||||||||
| 2384 | if (--events[transition->eventType()] == 0) {
| 1-19 | ||||||||||||||||||
| 2385 | events.remove(transition->eventType()); | - | ||||||||||||||||||
| 2386 | int sum = 0; | - | ||||||||||||||||||
| 2387 | QHash<QEvent::Type, int>::const_iterator it; | - | ||||||||||||||||||
| 2388 | for (it = events.constBegin(); it != events.constEnd(); ++it)
| 3-19 | ||||||||||||||||||
| 2389 | sum += it.value(); executed 3 times by 1 test: sum += it.value();Executed by:
| 3 | ||||||||||||||||||
| 2390 | if (sum == 0) {
| 3-16 | ||||||||||||||||||
| 2391 | qobjectEvents.remove(object); | - | ||||||||||||||||||
| 2392 | object->removeEventFilter(q); | - | ||||||||||||||||||
| 2393 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 2394 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||
| 2395 | QEventTransitionPrivate::get(transition)->registered = false; | - | ||||||||||||||||||
| 2396 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 2397 | - | |||||||||||||||||||
| 2398 | void QStateMachinePrivate::handleFilteredEvent(QObject *watched, QEvent *event) | - | ||||||||||||||||||
| 2399 | { | - | ||||||||||||||||||
| 2400 | if (qobjectEvents.value(watched).contains(event->type())) {
| 2-25 | ||||||||||||||||||
| 2401 | postInternalEvent(new QStateMachine::WrappedEvent(watched, handler->cloneEvent(event))); | - | ||||||||||||||||||
| 2402 | processEvents(DirectProcessing); | - | ||||||||||||||||||
| 2403 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 2404 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 2405 | #endif | - | ||||||||||||||||||
| 2406 | - | |||||||||||||||||||
| 2407 | void QStateMachinePrivate::handleTransitionSignal(QObject *sender, int signalIndex, | - | ||||||||||||||||||
| 2408 | void **argv) | - | ||||||||||||||||||
| 2409 | { | - | ||||||||||||||||||
| 2410 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 2411 | connectionsMutex.lock(); | - | ||||||||||||||||||
| 2412 | Q_ASSERT(connections[sender].at(signalIndex) != 0); | - | ||||||||||||||||||
| 2413 | connectionsMutex.unlock(); | - | ||||||||||||||||||
| 2414 | #endif | - | ||||||||||||||||||
| 2415 | const QMetaObject *meta = sender->metaObject(); | - | ||||||||||||||||||
| 2416 | QMetaMethod method = meta->method(signalIndex); | - | ||||||||||||||||||
| 2417 | int argc = method.parameterCount(); | - | ||||||||||||||||||
| 2418 | QList<QVariant> vargs; | - | ||||||||||||||||||
| 2419 | vargs.reserve(argc); | - | ||||||||||||||||||
| 2420 | for (int i = 0; i < argc; ++i) {
| 10-70 | ||||||||||||||||||
| 2421 | int type = method.parameterType(i); | - | ||||||||||||||||||
| 2422 | vargs.append(QVariant(type, argv[i+1])); | - | ||||||||||||||||||
| 2423 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 2424 | - | |||||||||||||||||||
| 2425 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2426 | qDebug() << q_func() << ": sending signal event ( sender =" << sender | - | ||||||||||||||||||
| 2427 | << ", signal =" << method.methodSignature().constData() << ')'; | - | ||||||||||||||||||
| 2428 | #endif | - | ||||||||||||||||||
| 2429 | postInternalEvent(new QStateMachine::SignalEvent(sender, signalIndex, vargs)); | - | ||||||||||||||||||
| 2430 | processEvents(DirectProcessing); | - | ||||||||||||||||||
| 2431 | } executed 70 times by 2 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 2432 | - | |||||||||||||||||||
| 2433 | /*! | - | ||||||||||||||||||
| 2434 | Constructs a new state machine with the given \a parent. | - | ||||||||||||||||||
| 2435 | */ | - | ||||||||||||||||||
| 2436 | QStateMachine::QStateMachine(QObject *parent) | - | ||||||||||||||||||
| 2437 | : QState(*new QStateMachinePrivate, /*parentState=*/0) | - | ||||||||||||||||||
| 2438 | { | - | ||||||||||||||||||
| 2439 | // Can't pass the parent to the QState constructor, as it expects a QState | - | ||||||||||||||||||
| 2440 | // But this works as expected regardless of whether parent is a QState or not | - | ||||||||||||||||||
| 2441 | setParent(parent); | - | ||||||||||||||||||
| 2442 | } executed 139 times by 2 tests: end of blockExecuted by:
| 139 | ||||||||||||||||||
| 2443 | - | |||||||||||||||||||
| 2444 | /*! | - | ||||||||||||||||||
| 2445 | \since 5.0 | - | ||||||||||||||||||
| 2446 | - | |||||||||||||||||||
| 2447 | Constructs a new state machine with the given \a childMode | - | ||||||||||||||||||
| 2448 | and \a parent. | - | ||||||||||||||||||
| 2449 | */ | - | ||||||||||||||||||
| 2450 | QStateMachine::QStateMachine(QState::ChildMode childMode, QObject *parent) | - | ||||||||||||||||||
| 2451 | : QState(*new QStateMachinePrivate, /*parentState=*/0) | - | ||||||||||||||||||
| 2452 | { | - | ||||||||||||||||||
| 2453 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2454 | d->childMode = childMode; | - | ||||||||||||||||||
| 2455 | setParent(parent); // See comment in constructor above | - | ||||||||||||||||||
| 2456 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 2457 | - | |||||||||||||||||||
| 2458 | /*! | - | ||||||||||||||||||
| 2459 | \internal | - | ||||||||||||||||||
| 2460 | */ | - | ||||||||||||||||||
| 2461 | QStateMachine::QStateMachine(QStateMachinePrivate &dd, QObject *parent) | - | ||||||||||||||||||
| 2462 | : QState(dd, /*parentState=*/0) | - | ||||||||||||||||||
| 2463 | { | - | ||||||||||||||||||
| 2464 | setParent(parent); | - | ||||||||||||||||||
| 2465 | } never executed: end of block | 0 | ||||||||||||||||||
| 2466 | - | |||||||||||||||||||
| 2467 | /*! | - | ||||||||||||||||||
| 2468 | Destroys this state machine. | - | ||||||||||||||||||
| 2469 | */ | - | ||||||||||||||||||
| 2470 | QStateMachine::~QStateMachine() | - | ||||||||||||||||||
| 2471 | { | - | ||||||||||||||||||
| 2472 | } | - | ||||||||||||||||||
| 2473 | - | |||||||||||||||||||
| 2474 | /*! | - | ||||||||||||||||||
| 2475 | \enum QStateMachine::EventPriority | - | ||||||||||||||||||
| 2476 | - | |||||||||||||||||||
| 2477 | This enum type specifies the priority of an event posted to the state | - | ||||||||||||||||||
| 2478 | machine using postEvent(). | - | ||||||||||||||||||
| 2479 | - | |||||||||||||||||||
| 2480 | Events of high priority are processed before events of normal priority. | - | ||||||||||||||||||
| 2481 | - | |||||||||||||||||||
| 2482 | \value NormalPriority The event has normal priority. | - | ||||||||||||||||||
| 2483 | \value HighPriority The event has high priority. | - | ||||||||||||||||||
| 2484 | */ | - | ||||||||||||||||||
| 2485 | - | |||||||||||||||||||
| 2486 | /*! \enum QStateMachine::Error | - | ||||||||||||||||||
| 2487 | - | |||||||||||||||||||
| 2488 | This enum type defines errors that can occur in the state machine at run time. When the state | - | ||||||||||||||||||
| 2489 | machine encounters an unrecoverable error at run time, it will set the error code returned | - | ||||||||||||||||||
| 2490 | by error(), the error message returned by errorString(), and enter an error state based on | - | ||||||||||||||||||
| 2491 | the context of the error. | - | ||||||||||||||||||
| 2492 | - | |||||||||||||||||||
| 2493 | \value NoError No error has occurred. | - | ||||||||||||||||||
| 2494 | \value NoInitialStateError The machine has entered a QState with children which does not have an | - | ||||||||||||||||||
| 2495 | initial state set. The context of this error is the state which is missing an initial | - | ||||||||||||||||||
| 2496 | state. | - | ||||||||||||||||||
| 2497 | \value NoDefaultStateInHistoryStateError The machine has entered a QHistoryState which does not have | - | ||||||||||||||||||
| 2498 | a default state set. The context of this error is the QHistoryState which is missing a | - | ||||||||||||||||||
| 2499 | default state. | - | ||||||||||||||||||
| 2500 | \value NoCommonAncestorForTransitionError The machine has selected a transition whose source | - | ||||||||||||||||||
| 2501 | and targets are not part of the same tree of states, and thus are not part of the same | - | ||||||||||||||||||
| 2502 | state machine. Commonly, this could mean that one of the states has not been given | - | ||||||||||||||||||
| 2503 | any parent or added to any machine. The context of this error is the source state of | - | ||||||||||||||||||
| 2504 | the transition. | - | ||||||||||||||||||
| 2505 | - | |||||||||||||||||||
| 2506 | \sa setErrorState() | - | ||||||||||||||||||
| 2507 | */ | - | ||||||||||||||||||
| 2508 | - | |||||||||||||||||||
| 2509 | /*! | - | ||||||||||||||||||
| 2510 | Returns the error code of the last error that occurred in the state machine. | - | ||||||||||||||||||
| 2511 | */ | - | ||||||||||||||||||
| 2512 | QStateMachine::Error QStateMachine::error() const | - | ||||||||||||||||||
| 2513 | { | - | ||||||||||||||||||
| 2514 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2515 | return d->error; executed 13 times by 1 test: return d->error;Executed by:
| 13 | ||||||||||||||||||
| 2516 | } | - | ||||||||||||||||||
| 2517 | - | |||||||||||||||||||
| 2518 | /*! | - | ||||||||||||||||||
| 2519 | Returns the error string of the last error that occurred in the state machine. | - | ||||||||||||||||||
| 2520 | */ | - | ||||||||||||||||||
| 2521 | QString QStateMachine::errorString() const | - | ||||||||||||||||||
| 2522 | { | - | ||||||||||||||||||
| 2523 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2524 | return d->errorString; executed 11 times by 1 test: return d->errorString;Executed by:
| 11 | ||||||||||||||||||
| 2525 | } | - | ||||||||||||||||||
| 2526 | - | |||||||||||||||||||
| 2527 | /*! | - | ||||||||||||||||||
| 2528 | Clears the error string and error code of the state machine. | - | ||||||||||||||||||
| 2529 | */ | - | ||||||||||||||||||
| 2530 | void QStateMachine::clearError() | - | ||||||||||||||||||
| 2531 | { | - | ||||||||||||||||||
| 2532 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2533 | d->errorString.clear(); | - | ||||||||||||||||||
| 2534 | d->error = NoError; | - | ||||||||||||||||||
| 2535 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2536 | - | |||||||||||||||||||
| 2537 | /*! | - | ||||||||||||||||||
| 2538 | Returns the restore policy of the state machine. | - | ||||||||||||||||||
| 2539 | - | |||||||||||||||||||
| 2540 | \sa setGlobalRestorePolicy() | - | ||||||||||||||||||
| 2541 | */ | - | ||||||||||||||||||
| 2542 | QState::RestorePolicy QStateMachine::globalRestorePolicy() const | - | ||||||||||||||||||
| 2543 | { | - | ||||||||||||||||||
| 2544 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2545 | return d->globalRestorePolicy; executed 1 time by 1 test: return d->globalRestorePolicy;Executed by:
| 1 | ||||||||||||||||||
| 2546 | } | - | ||||||||||||||||||
| 2547 | - | |||||||||||||||||||
| 2548 | /*! | - | ||||||||||||||||||
| 2549 | Sets the restore policy of the state machine to \a restorePolicy. The default | - | ||||||||||||||||||
| 2550 | restore policy is QState::DontRestoreProperties. | - | ||||||||||||||||||
| 2551 | - | |||||||||||||||||||
| 2552 | \sa globalRestorePolicy() | - | ||||||||||||||||||
| 2553 | */ | - | ||||||||||||||||||
| 2554 | void QStateMachine::setGlobalRestorePolicy(QState::RestorePolicy restorePolicy) | - | ||||||||||||||||||
| 2555 | { | - | ||||||||||||||||||
| 2556 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2557 | d->globalRestorePolicy = restorePolicy; | - | ||||||||||||||||||
| 2558 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 2559 | - | |||||||||||||||||||
| 2560 | /*! | - | ||||||||||||||||||
| 2561 | Adds the given \a state to this state machine. The state becomes a top-level | - | ||||||||||||||||||
| 2562 | state. | - | ||||||||||||||||||
| 2563 | - | |||||||||||||||||||
| 2564 | If the state is already in a different machine, it will first be removed | - | ||||||||||||||||||
| 2565 | from its old machine, and then added to this machine. | - | ||||||||||||||||||
| 2566 | - | |||||||||||||||||||
| 2567 | \sa removeState(), setInitialState() | - | ||||||||||||||||||
| 2568 | */ | - | ||||||||||||||||||
| 2569 | void QStateMachine::addState(QAbstractState *state) | - | ||||||||||||||||||
| 2570 | { | - | ||||||||||||||||||
| 2571 | if (!state) {
| 1-47 | ||||||||||||||||||
| 2572 | qWarning("QStateMachine::addState: cannot add null state"); | - | ||||||||||||||||||
| 2573 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2574 | } | - | ||||||||||||||||||
| 2575 | if (QAbstractStatePrivate::get(state)->machine() == this) {
| 2-45 | ||||||||||||||||||
| 2576 | qWarning("QStateMachine::addState: state has already been added to this machine"); | - | ||||||||||||||||||
| 2577 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 2578 | } | - | ||||||||||||||||||
| 2579 | state->setParent(this); | - | ||||||||||||||||||
| 2580 | } executed 45 times by 1 test: end of blockExecuted by:
| 45 | ||||||||||||||||||
| 2581 | - | |||||||||||||||||||
| 2582 | /*! | - | ||||||||||||||||||
| 2583 | Removes the given \a state from this state machine. The state machine | - | ||||||||||||||||||
| 2584 | releases ownership of the state. | - | ||||||||||||||||||
| 2585 | - | |||||||||||||||||||
| 2586 | \sa addState() | - | ||||||||||||||||||
| 2587 | */ | - | ||||||||||||||||||
| 2588 | void QStateMachine::removeState(QAbstractState *state) | - | ||||||||||||||||||
| 2589 | { | - | ||||||||||||||||||
| 2590 | if (!state) {
| 1-3 | ||||||||||||||||||
| 2591 | qWarning("QStateMachine::removeState: cannot remove null state"); | - | ||||||||||||||||||
| 2592 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2593 | } | - | ||||||||||||||||||
| 2594 | if (QAbstractStatePrivate::get(state)->machine() != this) {
| 1-2 | ||||||||||||||||||
| 2595 | qWarning("QStateMachine::removeState: state %p's machine (%p)" | - | ||||||||||||||||||
| 2596 | " is different from this machine (%p)", | - | ||||||||||||||||||
| 2597 | state, QAbstractStatePrivate::get(state)->machine(), this); | - | ||||||||||||||||||
| 2598 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2599 | } | - | ||||||||||||||||||
| 2600 | state->setParent(0); | - | ||||||||||||||||||
| 2601 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2602 | - | |||||||||||||||||||
| 2603 | bool QStateMachine::isRunning() const | - | ||||||||||||||||||
| 2604 | { | - | ||||||||||||||||||
| 2605 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2606 | return (d->state == QStateMachinePrivate::Running); executed 174 times by 1 test: return (d->state == QStateMachinePrivate::Running);Executed by:
| 174 | ||||||||||||||||||
| 2607 | } | - | ||||||||||||||||||
| 2608 | - | |||||||||||||||||||
| 2609 | /*! | - | ||||||||||||||||||
| 2610 | Starts this state machine. The machine will reset its configuration and | - | ||||||||||||||||||
| 2611 | transition to the initial state. When a final top-level state (QFinalState) | - | ||||||||||||||||||
| 2612 | is entered, the machine will emit the finished() signal. | - | ||||||||||||||||||
| 2613 | - | |||||||||||||||||||
| 2614 | \note A state machine will not run without a running event loop, such as | - | ||||||||||||||||||
| 2615 | the main application event loop started with QCoreApplication::exec() or | - | ||||||||||||||||||
| 2616 | QApplication::exec(). | - | ||||||||||||||||||
| 2617 | - | |||||||||||||||||||
| 2618 | \sa started(), finished(), stop(), initialState(), setRunning() | - | ||||||||||||||||||
| 2619 | */ | - | ||||||||||||||||||
| 2620 | void QStateMachine::start() | - | ||||||||||||||||||
| 2621 | { | - | ||||||||||||||||||
| 2622 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2623 | - | |||||||||||||||||||
| 2624 | if ((childMode() == QState::ExclusiveStates) && (initialState() == 0)) {
| 1-157 | ||||||||||||||||||
| 2625 | qWarning("QStateMachine::start: No initial state set for machine. Refusing to start."); | - | ||||||||||||||||||
| 2626 | return; executed 3 times by 1 test: return;Executed by:
| 3 | ||||||||||||||||||
| 2627 | } | - | ||||||||||||||||||
| 2628 | - | |||||||||||||||||||
| 2629 | switch (d->state) { | - | ||||||||||||||||||
| 2630 | case QStateMachinePrivate::NotRunning: executed 153 times by 2 tests: case QStateMachinePrivate::NotRunning:Executed by:
| 153 | ||||||||||||||||||
| 2631 | d->state = QStateMachinePrivate::Starting; | - | ||||||||||||||||||
| 2632 | QMetaObject::invokeMethod(this, "_q_start", Qt::QueuedConnection); | - | ||||||||||||||||||
| 2633 | break; executed 153 times by 2 tests: break;Executed by:
| 153 | ||||||||||||||||||
| 2634 | case QStateMachinePrivate::Starting: never executed: case QStateMachinePrivate::Starting: | 0 | ||||||||||||||||||
| 2635 | break; never executed: break; | 0 | ||||||||||||||||||
| 2636 | case QStateMachinePrivate::Running: executed 2 times by 1 test: case QStateMachinePrivate::Running:Executed by:
| 2 | ||||||||||||||||||
| 2637 | qWarning("QStateMachine::start(): already running"); | - | ||||||||||||||||||
| 2638 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 2639 | } | - | ||||||||||||||||||
| 2640 | } executed 155 times by 2 tests: end of blockExecuted by:
| 155 | ||||||||||||||||||
| 2641 | - | |||||||||||||||||||
| 2642 | /*! | - | ||||||||||||||||||
| 2643 | Stops this state machine. The state machine will stop processing events and | - | ||||||||||||||||||
| 2644 | then emit the stopped() signal. | - | ||||||||||||||||||
| 2645 | - | |||||||||||||||||||
| 2646 | \sa stopped(), start(), setRunning() | - | ||||||||||||||||||
| 2647 | */ | - | ||||||||||||||||||
| 2648 | void QStateMachine::stop() | - | ||||||||||||||||||
| 2649 | { | - | ||||||||||||||||||
| 2650 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2651 | switch (d->state) { | - | ||||||||||||||||||
| 2652 | case QStateMachinePrivate::NotRunning: executed 7 times by 1 test: case QStateMachinePrivate::NotRunning:Executed by:
| 7 | ||||||||||||||||||
| 2653 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||
| 2654 | case QStateMachinePrivate::Starting: never executed: case QStateMachinePrivate::Starting: | 0 | ||||||||||||||||||
| 2655 | // the machine will exit as soon as it enters the event processing loop | - | ||||||||||||||||||
| 2656 | d->stop = true; | - | ||||||||||||||||||
| 2657 | break; never executed: break; | 0 | ||||||||||||||||||
| 2658 | case QStateMachinePrivate::Running: executed 22 times by 1 test: case QStateMachinePrivate::Running:Executed by:
| 22 | ||||||||||||||||||
| 2659 | d->stop = true; | - | ||||||||||||||||||
| 2660 | d->processEvents(QStateMachinePrivate::QueuedProcessing); | - | ||||||||||||||||||
| 2661 | break; executed 22 times by 1 test: break;Executed by:
| 22 | ||||||||||||||||||
| 2662 | } | - | ||||||||||||||||||
| 2663 | } executed 29 times by 1 test: end of blockExecuted by:
| 29 | ||||||||||||||||||
| 2664 | - | |||||||||||||||||||
| 2665 | void QStateMachine::setRunning(bool running) | - | ||||||||||||||||||
| 2666 | { | - | ||||||||||||||||||
| 2667 | if (running)
| 4-5 | ||||||||||||||||||
| 2668 | start(); executed 4 times by 1 test: start();Executed by:
| 4 | ||||||||||||||||||
| 2669 | else | - | ||||||||||||||||||
| 2670 | stop(); executed 5 times by 1 test: stop();Executed by:
| 5 | ||||||||||||||||||
| 2671 | } | - | ||||||||||||||||||
| 2672 | - | |||||||||||||||||||
| 2673 | /*! | - | ||||||||||||||||||
| 2674 | \threadsafe | - | ||||||||||||||||||
| 2675 | - | |||||||||||||||||||
| 2676 | Posts the given \a event of the given \a priority for processing by this | - | ||||||||||||||||||
| 2677 | state machine. | - | ||||||||||||||||||
| 2678 | - | |||||||||||||||||||
| 2679 | This function returns immediately. The event is added to the state machine's | - | ||||||||||||||||||
| 2680 | event queue. Events are processed in the order posted. The state machine | - | ||||||||||||||||||
| 2681 | takes ownership of the event and deletes it once it has been processed. | - | ||||||||||||||||||
| 2682 | - | |||||||||||||||||||
| 2683 | You can only post events when the state machine is running or when it is starting up. | - | ||||||||||||||||||
| 2684 | - | |||||||||||||||||||
| 2685 | \sa postDelayedEvent() | - | ||||||||||||||||||
| 2686 | */ | - | ||||||||||||||||||
| 2687 | void QStateMachine::postEvent(QEvent *event, EventPriority priority) | - | ||||||||||||||||||
| 2688 | { | - | ||||||||||||||||||
| 2689 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2690 | switch (d->state) { | - | ||||||||||||||||||
| 2691 | case QStateMachinePrivate::Running: executed 2123 times by 2 tests: case QStateMachinePrivate::Running:Executed by:
| 2123 | ||||||||||||||||||
| 2692 | case QStateMachinePrivate::Starting: never executed: case QStateMachinePrivate::Starting: | 0 | ||||||||||||||||||
| 2693 | break; executed 2123 times by 2 tests: break;Executed by:
| 2123 | ||||||||||||||||||
| 2694 | default: executed 2 times by 1 test: default:Executed by:
| 2 | ||||||||||||||||||
| 2695 | qWarning("QStateMachine::postEvent: cannot post event when the state machine is not running"); | - | ||||||||||||||||||
| 2696 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 2697 | } | - | ||||||||||||||||||
| 2698 | if (!event) {
| 0-2123 | ||||||||||||||||||
| 2699 | qWarning("QStateMachine::postEvent: cannot post null event"); | - | ||||||||||||||||||
| 2700 | return; never executed: return; | 0 | ||||||||||||||||||
| 2701 | } | - | ||||||||||||||||||
| 2702 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2703 | qDebug() << this << ": posting event" << event; | - | ||||||||||||||||||
| 2704 | #endif | - | ||||||||||||||||||
| 2705 | switch (priority) { | - | ||||||||||||||||||
| 2706 | case NormalPriority: executed 2119 times by 2 tests: case NormalPriority:Executed by:
| 2119 | ||||||||||||||||||
| 2707 | d->postExternalEvent(event); | - | ||||||||||||||||||
| 2708 | break; executed 2119 times by 2 tests: break;Executed by:
| 2119 | ||||||||||||||||||
| 2709 | case HighPriority: executed 4 times by 1 test: case HighPriority:Executed by:
| 4 | ||||||||||||||||||
| 2710 | d->postInternalEvent(event); | - | ||||||||||||||||||
| 2711 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 2712 | } | - | ||||||||||||||||||
| 2713 | d->processEvents(QStateMachinePrivate::QueuedProcessing); | - | ||||||||||||||||||
| 2714 | } executed 2123 times by 2 tests: end of blockExecuted by:
| 2123 | ||||||||||||||||||
| 2715 | - | |||||||||||||||||||
| 2716 | /*! | - | ||||||||||||||||||
| 2717 | \threadsafe | - | ||||||||||||||||||
| 2718 | - | |||||||||||||||||||
| 2719 | Posts the given \a event for processing by this state machine, with the | - | ||||||||||||||||||
| 2720 | given \a delay in milliseconds. Returns an identifier associated with the | - | ||||||||||||||||||
| 2721 | delayed event, or -1 if the event could not be posted. | - | ||||||||||||||||||
| 2722 | - | |||||||||||||||||||
| 2723 | This function returns immediately. When the delay has expired, the event | - | ||||||||||||||||||
| 2724 | will be added to the state machine's event queue for processing. The state | - | ||||||||||||||||||
| 2725 | machine takes ownership of the event and deletes it once it has been | - | ||||||||||||||||||
| 2726 | processed. | - | ||||||||||||||||||
| 2727 | - | |||||||||||||||||||
| 2728 | You can only post events when the state machine is running. | - | ||||||||||||||||||
| 2729 | - | |||||||||||||||||||
| 2730 | \sa cancelDelayedEvent(), postEvent() | - | ||||||||||||||||||
| 2731 | */ | - | ||||||||||||||||||
| 2732 | int QStateMachine::postDelayedEvent(QEvent *event, int delay) | - | ||||||||||||||||||
| 2733 | { | - | ||||||||||||||||||
| 2734 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2735 | if (d->state != QStateMachinePrivate::Running) {
| 0-9 | ||||||||||||||||||
| 2736 | qWarning("QStateMachine::postDelayedEvent: cannot post event when the state machine is not running"); | - | ||||||||||||||||||
| 2737 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2738 | } | - | ||||||||||||||||||
| 2739 | if (!event) {
| 0-9 | ||||||||||||||||||
| 2740 | qWarning("QStateMachine::postDelayedEvent: cannot post null event"); | - | ||||||||||||||||||
| 2741 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2742 | } | - | ||||||||||||||||||
| 2743 | if (delay < 0) {
| 0-9 | ||||||||||||||||||
| 2744 | qWarning("QStateMachine::postDelayedEvent: delay cannot be negative"); | - | ||||||||||||||||||
| 2745 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2746 | } | - | ||||||||||||||||||
| 2747 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2748 | qDebug() << this << ": posting event" << event << "with delay" << delay; | - | ||||||||||||||||||
| 2749 | #endif | - | ||||||||||||||||||
| 2750 | QMutexLocker locker(&d->delayedEventsMutex); | - | ||||||||||||||||||
| 2751 | int id = d->delayedEventIdFreeList.next(); | - | ||||||||||||||||||
| 2752 | bool inMachineThread = (QThread::currentThread() == thread()); | - | ||||||||||||||||||
| 2753 | int timerId = inMachineThread ? startTimer(delay) : 0;
| 2-7 | ||||||||||||||||||
| 2754 | if (inMachineThread && !timerId) {
| 0-7 | ||||||||||||||||||
| 2755 | qWarning("QStateMachine::postDelayedEvent: failed to start timer with interval %d", delay); | - | ||||||||||||||||||
| 2756 | d->delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 2757 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2758 | } | - | ||||||||||||||||||
| 2759 | QStateMachinePrivate::DelayedEvent delayedEvent(event, timerId); | - | ||||||||||||||||||
| 2760 | d->delayedEvents.insert(id, delayedEvent); | - | ||||||||||||||||||
| 2761 | if (timerId) {
| 2-7 | ||||||||||||||||||
| 2762 | d->timerIdToDelayedEventId.insert(timerId, id); | - | ||||||||||||||||||
| 2763 | } else { executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 2764 | Q_ASSERT(!inMachineThread); | - | ||||||||||||||||||
| 2765 | QMetaObject::invokeMethod(this, "_q_startDelayedEventTimer", | - | ||||||||||||||||||
| 2766 | Qt::QueuedConnection, | - | ||||||||||||||||||
| 2767 | Q_ARG(int, id), | - | ||||||||||||||||||
| 2768 | Q_ARG(int, delay)); | - | ||||||||||||||||||
| 2769 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2770 | return id; executed 9 times by 1 test: return id;Executed by:
| 9 | ||||||||||||||||||
| 2771 | } | - | ||||||||||||||||||
| 2772 | - | |||||||||||||||||||
| 2773 | /*! | - | ||||||||||||||||||
| 2774 | \threadsafe | - | ||||||||||||||||||
| 2775 | - | |||||||||||||||||||
| 2776 | Cancels the delayed event identified by the given \a id. The id should be a | - | ||||||||||||||||||
| 2777 | value returned by a call to postDelayedEvent(). Returns \c true if the event | - | ||||||||||||||||||
| 2778 | was successfully cancelled, otherwise returns \c false. | - | ||||||||||||||||||
| 2779 | - | |||||||||||||||||||
| 2780 | \sa postDelayedEvent() | - | ||||||||||||||||||
| 2781 | */ | - | ||||||||||||||||||
| 2782 | bool QStateMachine::cancelDelayedEvent(int id) | - | ||||||||||||||||||
| 2783 | { | - | ||||||||||||||||||
| 2784 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2785 | if (d->state != QStateMachinePrivate::Running) {
| 1-5 | ||||||||||||||||||
| 2786 | qWarning("QStateMachine::cancelDelayedEvent: the machine is not running"); | - | ||||||||||||||||||
| 2787 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 2788 | } | - | ||||||||||||||||||
| 2789 | QMutexLocker locker(&d->delayedEventsMutex); | - | ||||||||||||||||||
| 2790 | QStateMachinePrivate::DelayedEvent e = d->delayedEvents.take(id); | - | ||||||||||||||||||
| 2791 | if (!e.event)
| 2-3 | ||||||||||||||||||
| 2792 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 2793 | if (e.timerId) {
| 1-2 | ||||||||||||||||||
| 2794 | d->timerIdToDelayedEventId.remove(e.timerId); | - | ||||||||||||||||||
| 2795 | bool inMachineThread = (QThread::currentThread() == thread()); | - | ||||||||||||||||||
| 2796 | if (inMachineThread) {
| 0-2 | ||||||||||||||||||
| 2797 | killTimer(e.timerId); | - | ||||||||||||||||||
| 2798 | d->delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 2799 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2800 | QMetaObject::invokeMethod(this, "_q_killDelayedEventTimer", | - | ||||||||||||||||||
| 2801 | Qt::QueuedConnection, | - | ||||||||||||||||||
| 2802 | Q_ARG(int, id), | - | ||||||||||||||||||
| 2803 | Q_ARG(int, e.timerId)); | - | ||||||||||||||||||
| 2804 | } never executed: end of block | 0 | ||||||||||||||||||
| 2805 | } else { | - | ||||||||||||||||||
| 2806 | // Cancellation will be detected in pending _q_startDelayedEventTimer() call | - | ||||||||||||||||||
| 2807 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2808 | delete e.event; | - | ||||||||||||||||||
| 2809 | return true; executed 3 times by 1 test: return true;Executed by:
| 3 | ||||||||||||||||||
| 2810 | } | - | ||||||||||||||||||
| 2811 | - | |||||||||||||||||||
| 2812 | /*! | - | ||||||||||||||||||
| 2813 | Returns the maximal consistent set of states (including parallel and final | - | ||||||||||||||||||
| 2814 | states) that this state machine is currently in. If a state \c s is in the | - | ||||||||||||||||||
| 2815 | configuration, it is always the case that the parent of \c s is also in | - | ||||||||||||||||||
| 2816 | c. Note, however, that the machine itself is not an explicit member of the | - | ||||||||||||||||||
| 2817 | configuration. | - | ||||||||||||||||||
| 2818 | */ | - | ||||||||||||||||||
| 2819 | QSet<QAbstractState*> QStateMachine::configuration() const | - | ||||||||||||||||||
| 2820 | { | - | ||||||||||||||||||
| 2821 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2822 | return d->configuration; executed 938 times by 2 tests: return d->configuration;Executed by:
| 938 | ||||||||||||||||||
| 2823 | } | - | ||||||||||||||||||
| 2824 | - | |||||||||||||||||||
| 2825 | /*! | - | ||||||||||||||||||
| 2826 | \fn QStateMachine::started() | - | ||||||||||||||||||
| 2827 | - | |||||||||||||||||||
| 2828 | This signal is emitted when the state machine has entered its initial state | - | ||||||||||||||||||
| 2829 | (QStateMachine::initialState). | - | ||||||||||||||||||
| 2830 | - | |||||||||||||||||||
| 2831 | \sa QStateMachine::finished(), QStateMachine::start() | - | ||||||||||||||||||
| 2832 | */ | - | ||||||||||||||||||
| 2833 | - | |||||||||||||||||||
| 2834 | /*! | - | ||||||||||||||||||
| 2835 | \fn QStateMachine::stopped() | - | ||||||||||||||||||
| 2836 | - | |||||||||||||||||||
| 2837 | This signal is emitted when the state machine has stopped. | - | ||||||||||||||||||
| 2838 | - | |||||||||||||||||||
| 2839 | \sa QStateMachine::stop(), QStateMachine::finished() | - | ||||||||||||||||||
| 2840 | */ | - | ||||||||||||||||||
| 2841 | - | |||||||||||||||||||
| 2842 | /*! | - | ||||||||||||||||||
| 2843 | \reimp | - | ||||||||||||||||||
| 2844 | */ | - | ||||||||||||||||||
| 2845 | bool QStateMachine::event(QEvent *e) | - | ||||||||||||||||||
| 2846 | { | - | ||||||||||||||||||
| 2847 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2848 | if (e->type() == QEvent::Timer) {
| 4-685 | ||||||||||||||||||
| 2849 | QTimerEvent *te = static_cast<QTimerEvent*>(e); | - | ||||||||||||||||||
| 2850 | int tid = te->timerId(); | - | ||||||||||||||||||
| 2851 | if (d->state != QStateMachinePrivate::Running) {
| 0-4 | ||||||||||||||||||
| 2852 | // This event has been cancelled already | - | ||||||||||||||||||
| 2853 | QMutexLocker locker(&d->delayedEventsMutex); | - | ||||||||||||||||||
| 2854 | Q_ASSERT(!d->timerIdToDelayedEventId.contains(tid)); | - | ||||||||||||||||||
| 2855 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2856 | } | - | ||||||||||||||||||
| 2857 | d->delayedEventsMutex.lock(); | - | ||||||||||||||||||
| 2858 | int id = d->timerIdToDelayedEventId.take(tid); | - | ||||||||||||||||||
| 2859 | QStateMachinePrivate::DelayedEvent ee = d->delayedEvents.take(id); | - | ||||||||||||||||||
| 2860 | if (ee.event != 0) {
| 0-4 | ||||||||||||||||||
| 2861 | Q_ASSERT(ee.timerId == tid); | - | ||||||||||||||||||
| 2862 | killTimer(tid); | - | ||||||||||||||||||
| 2863 | d->delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 2864 | d->delayedEventsMutex.unlock(); | - | ||||||||||||||||||
| 2865 | d->postExternalEvent(ee.event); | - | ||||||||||||||||||
| 2866 | d->processEvents(QStateMachinePrivate::DirectProcessing); | - | ||||||||||||||||||
| 2867 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 2868 | } else { | - | ||||||||||||||||||
| 2869 | d->delayedEventsMutex.unlock(); | - | ||||||||||||||||||
| 2870 | } never executed: end of block | 0 | ||||||||||||||||||
| 2871 | } | - | ||||||||||||||||||
| 2872 | return QState::event(e); executed 685 times by 2 tests: return QState::event(e);Executed by:
| 685 | ||||||||||||||||||
| 2873 | } | - | ||||||||||||||||||
| 2874 | - | |||||||||||||||||||
| 2875 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2876 | /*! | - | ||||||||||||||||||
| 2877 | \reimp | - | ||||||||||||||||||
| 2878 | */ | - | ||||||||||||||||||
| 2879 | bool QStateMachine::eventFilter(QObject *watched, QEvent *event) | - | ||||||||||||||||||
| 2880 | { | - | ||||||||||||||||||
| 2881 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2882 | d->handleFilteredEvent(watched, event); | - | ||||||||||||||||||
| 2883 | return false; executed 27 times by 1 test: return false;Executed by:
| 27 | ||||||||||||||||||
| 2884 | } | - | ||||||||||||||||||
| 2885 | #endif | - | ||||||||||||||||||
| 2886 | - | |||||||||||||||||||
| 2887 | /*! | - | ||||||||||||||||||
| 2888 | \internal | - | ||||||||||||||||||
| 2889 | - | |||||||||||||||||||
| 2890 | This function is called when the state machine is about to select | - | ||||||||||||||||||
| 2891 | transitions based on the given \a event. | - | ||||||||||||||||||
| 2892 | - | |||||||||||||||||||
| 2893 | The default implementation does nothing. | - | ||||||||||||||||||
| 2894 | */ | - | ||||||||||||||||||
| 2895 | void QStateMachine::beginSelectTransitions(QEvent *event) | - | ||||||||||||||||||
| 2896 | { | - | ||||||||||||||||||
| 2897 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2898 | } executed 3744 times by 2 tests: end of blockExecuted by:
| 3744 | ||||||||||||||||||
| 2899 | - | |||||||||||||||||||
| 2900 | /*! | - | ||||||||||||||||||
| 2901 | \internal | - | ||||||||||||||||||
| 2902 | - | |||||||||||||||||||
| 2903 | This function is called when the state machine has finished selecting | - | ||||||||||||||||||
| 2904 | transitions based on the given \a event. | - | ||||||||||||||||||
| 2905 | - | |||||||||||||||||||
| 2906 | The default implementation does nothing. | - | ||||||||||||||||||
| 2907 | */ | - | ||||||||||||||||||
| 2908 | void QStateMachine::endSelectTransitions(QEvent *event) | - | ||||||||||||||||||
| 2909 | { | - | ||||||||||||||||||
| 2910 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2911 | } executed 3750 times by 2 tests: end of blockExecuted by:
| 3750 | ||||||||||||||||||
| 2912 | - | |||||||||||||||||||
| 2913 | /*! | - | ||||||||||||||||||
| 2914 | \internal | - | ||||||||||||||||||
| 2915 | - | |||||||||||||||||||
| 2916 | This function is called when the state machine is about to do a microstep. | - | ||||||||||||||||||
| 2917 | - | |||||||||||||||||||
| 2918 | The default implementation does nothing. | - | ||||||||||||||||||
| 2919 | */ | - | ||||||||||||||||||
| 2920 | void QStateMachine::beginMicrostep(QEvent *event) | - | ||||||||||||||||||
| 2921 | { | - | ||||||||||||||||||
| 2922 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2923 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 2924 | - | |||||||||||||||||||
| 2925 | /*! | - | ||||||||||||||||||
| 2926 | \internal | - | ||||||||||||||||||
| 2927 | - | |||||||||||||||||||
| 2928 | This function is called when the state machine has finished doing a | - | ||||||||||||||||||
| 2929 | microstep. | - | ||||||||||||||||||
| 2930 | - | |||||||||||||||||||
| 2931 | The default implementation does nothing. | - | ||||||||||||||||||
| 2932 | */ | - | ||||||||||||||||||
| 2933 | void QStateMachine::endMicrostep(QEvent *event) | - | ||||||||||||||||||
| 2934 | { | - | ||||||||||||||||||
| 2935 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2936 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 2937 | - | |||||||||||||||||||
| 2938 | /*! | - | ||||||||||||||||||
| 2939 | \reimp | - | ||||||||||||||||||
| 2940 | This function will call start() to start the state machine. | - | ||||||||||||||||||
| 2941 | */ | - | ||||||||||||||||||
| 2942 | void QStateMachine::onEntry(QEvent *event) | - | ||||||||||||||||||
| 2943 | { | - | ||||||||||||||||||
| 2944 | start(); | - | ||||||||||||||||||
| 2945 | QState::onEntry(event); | - | ||||||||||||||||||
| 2946 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 2947 | - | |||||||||||||||||||
| 2948 | /*! | - | ||||||||||||||||||
| 2949 | \reimp | - | ||||||||||||||||||
| 2950 | This function will call stop() to stop the state machine and | - | ||||||||||||||||||
| 2951 | subsequently emit the stopped() signal. | - | ||||||||||||||||||
| 2952 | */ | - | ||||||||||||||||||
| 2953 | void QStateMachine::onExit(QEvent *event) | - | ||||||||||||||||||
| 2954 | { | - | ||||||||||||||||||
| 2955 | stop(); | - | ||||||||||||||||||
| 2956 | QState::onExit(event); | - | ||||||||||||||||||
| 2957 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 2958 | - | |||||||||||||||||||
| 2959 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 2960 | - | |||||||||||||||||||
| 2961 | /*! | - | ||||||||||||||||||
| 2962 | Returns whether animations are enabled for this state machine. | - | ||||||||||||||||||
| 2963 | */ | - | ||||||||||||||||||
| 2964 | bool QStateMachine::isAnimated() const | - | ||||||||||||||||||
| 2965 | { | - | ||||||||||||||||||
| 2966 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2967 | return d->animated; executed 3 times by 1 test: return d->animated;Executed by:
| 3 | ||||||||||||||||||
| 2968 | } | - | ||||||||||||||||||
| 2969 | - | |||||||||||||||||||
| 2970 | /*! | - | ||||||||||||||||||
| 2971 | Sets whether animations are \a enabled for this state machine. | - | ||||||||||||||||||
| 2972 | */ | - | ||||||||||||||||||
| 2973 | void QStateMachine::setAnimated(bool enabled) | - | ||||||||||||||||||
| 2974 | { | - | ||||||||||||||||||
| 2975 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2976 | d->animated = enabled; | - | ||||||||||||||||||
| 2977 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2978 | - | |||||||||||||||||||
| 2979 | /*! | - | ||||||||||||||||||
| 2980 | Adds a default \a animation to be considered for any transition. | - | ||||||||||||||||||
| 2981 | */ | - | ||||||||||||||||||
| 2982 | void QStateMachine::addDefaultAnimation(QAbstractAnimation *animation) | - | ||||||||||||||||||
| 2983 | { | - | ||||||||||||||||||
| 2984 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2985 | d->defaultAnimations.append(animation); | - | ||||||||||||||||||
| 2986 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 2987 | - | |||||||||||||||||||
| 2988 | /*! | - | ||||||||||||||||||
| 2989 | Returns the list of default animations that will be considered for any transition. | - | ||||||||||||||||||
| 2990 | */ | - | ||||||||||||||||||
| 2991 | QList<QAbstractAnimation*> QStateMachine::defaultAnimations() const | - | ||||||||||||||||||
| 2992 | { | - | ||||||||||||||||||
| 2993 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2994 | return d->defaultAnimations; executed 10 times by 1 test: return d->defaultAnimations;Executed by:
| 10 | ||||||||||||||||||
| 2995 | } | - | ||||||||||||||||||
| 2996 | - | |||||||||||||||||||
| 2997 | /*! | - | ||||||||||||||||||
| 2998 | Removes \a animation from the list of default animations. | - | ||||||||||||||||||
| 2999 | */ | - | ||||||||||||||||||
| 3000 | void QStateMachine::removeDefaultAnimation(QAbstractAnimation *animation) | - | ||||||||||||||||||
| 3001 | { | - | ||||||||||||||||||
| 3002 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 3003 | d->defaultAnimations.removeAll(animation); | - | ||||||||||||||||||
| 3004 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 3005 | - | |||||||||||||||||||
| 3006 | #endif // QT_NO_ANIMATION | - | ||||||||||||||||||
| 3007 | - | |||||||||||||||||||
| 3008 | - | |||||||||||||||||||
| 3009 | // Begin moc-generated code -- modify carefully (check "HAND EDIT" parts)! | - | ||||||||||||||||||
| 3010 | struct qt_meta_stringdata_QSignalEventGenerator_t { | - | ||||||||||||||||||
| 3011 | QByteArrayData data[3]; | - | ||||||||||||||||||
| 3012 | char stringdata[32]; | - | ||||||||||||||||||
| 3013 | }; | - | ||||||||||||||||||
| 3014 | #define QT_MOC_LITERAL(idx, ofs, len) \ | - | ||||||||||||||||||
| 3015 | Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ | - | ||||||||||||||||||
| 3016 | offsetof(qt_meta_stringdata_QSignalEventGenerator_t, stringdata) + ofs \ | - | ||||||||||||||||||
| 3017 | - idx * sizeof(QByteArrayData) \ | - | ||||||||||||||||||
| 3018 | ) | - | ||||||||||||||||||
| 3019 | static const qt_meta_stringdata_QSignalEventGenerator_t qt_meta_stringdata_QSignalEventGenerator = { | - | ||||||||||||||||||
| 3020 | { | - | ||||||||||||||||||
| 3021 | QT_MOC_LITERAL(0, 0, 21), | - | ||||||||||||||||||
| 3022 | QT_MOC_LITERAL(1, 22, 7), | - | ||||||||||||||||||
| 3023 | QT_MOC_LITERAL(2, 30, 0) | - | ||||||||||||||||||
| 3024 | }, | - | ||||||||||||||||||
| 3025 | "QSignalEventGenerator\0execute\0\0" | - | ||||||||||||||||||
| 3026 | }; | - | ||||||||||||||||||
| 3027 | #undef QT_MOC_LITERAL | - | ||||||||||||||||||
| 3028 | - | |||||||||||||||||||
| 3029 | static const uint qt_meta_data_QSignalEventGenerator[] = { | - | ||||||||||||||||||
| 3030 | - | |||||||||||||||||||
| 3031 | // content: | - | ||||||||||||||||||
| 3032 | 7, // revision | - | ||||||||||||||||||
| 3033 | 0, // classname | - | ||||||||||||||||||
| 3034 | 0, 0, // classinfo | - | ||||||||||||||||||
| 3035 | 1, 14, // methods | - | ||||||||||||||||||
| 3036 | 0, 0, // properties | - | ||||||||||||||||||
| 3037 | 0, 0, // enums/sets | - | ||||||||||||||||||
| 3038 | 0, 0, // constructors | - | ||||||||||||||||||
| 3039 | 0, // flags | - | ||||||||||||||||||
| 3040 | 0, // signalCount | - | ||||||||||||||||||
| 3041 | - | |||||||||||||||||||
| 3042 | // slots: name, argc, parameters, tag, flags | - | ||||||||||||||||||
| 3043 | 1, 0, 19, 2, 0x0a, | - | ||||||||||||||||||
| 3044 | - | |||||||||||||||||||
| 3045 | // slots: parameters | - | ||||||||||||||||||
| 3046 | QMetaType::Void, | - | ||||||||||||||||||
| 3047 | - | |||||||||||||||||||
| 3048 | 0 // eod | - | ||||||||||||||||||
| 3049 | }; | - | ||||||||||||||||||
| 3050 | - | |||||||||||||||||||
| 3051 | void QSignalEventGenerator::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) | - | ||||||||||||||||||
| 3052 | { | - | ||||||||||||||||||
| 3053 | if (_c == QMetaObject::InvokeMetaMethod) { | - | ||||||||||||||||||
| 3054 | Q_ASSERT(staticMetaObject.cast(_o)); | - | ||||||||||||||||||
| 3055 | QSignalEventGenerator *_t = static_cast<QSignalEventGenerator *>(_o); | - | ||||||||||||||||||
| 3056 | switch (_id) { | - | ||||||||||||||||||
| 3057 | case 0: _t->execute(_a); break; // HAND EDIT: add the _a parameter | - | ||||||||||||||||||
| 3058 | default: ; | - | ||||||||||||||||||
| 3059 | } | - | ||||||||||||||||||
| 3060 | } | - | ||||||||||||||||||
| 3061 | Q_UNUSED(_a); | - | ||||||||||||||||||
| 3062 | } | - | ||||||||||||||||||
| 3063 | - | |||||||||||||||||||
| 3064 | const QMetaObject QSignalEventGenerator::staticMetaObject = { | - | ||||||||||||||||||
| 3065 | { &QObject::staticMetaObject, qt_meta_stringdata_QSignalEventGenerator.data, | - | ||||||||||||||||||
| 3066 | qt_meta_data_QSignalEventGenerator, qt_static_metacall, 0, 0 } | - | ||||||||||||||||||
| 3067 | }; | - | ||||||||||||||||||
| 3068 | - | |||||||||||||||||||
| 3069 | const QMetaObject *QSignalEventGenerator::metaObject() const | - | ||||||||||||||||||
| 3070 | { | - | ||||||||||||||||||
| 3071 | return &staticMetaObject; | - | ||||||||||||||||||
| 3072 | } | - | ||||||||||||||||||
| 3073 | - | |||||||||||||||||||
| 3074 | void *QSignalEventGenerator::qt_metacast(const char *_clname) | - | ||||||||||||||||||
| 3075 | { | - | ||||||||||||||||||
| 3076 | if (!_clname) return 0; | - | ||||||||||||||||||
| 3077 | if (!strcmp(_clname, qt_meta_stringdata_QSignalEventGenerator.stringdata)) | - | ||||||||||||||||||
| 3078 | return static_cast<void*>(const_cast< QSignalEventGenerator*>(this)); | - | ||||||||||||||||||
| 3079 | return QObject::qt_metacast(_clname); | - | ||||||||||||||||||
| 3080 | } | - | ||||||||||||||||||
| 3081 | - | |||||||||||||||||||
| 3082 | int QSignalEventGenerator::qt_metacall(QMetaObject::Call _c, int _id, void **_a) | - | ||||||||||||||||||
| 3083 | { | - | ||||||||||||||||||
| 3084 | _id = QObject::qt_metacall(_c, _id, _a); | - | ||||||||||||||||||
| 3085 | if (_id < 0) | - | ||||||||||||||||||
| 3086 | return _id; | - | ||||||||||||||||||
| 3087 | if (_c == QMetaObject::InvokeMetaMethod) { | - | ||||||||||||||||||
| 3088 | if (_id < 1) | - | ||||||||||||||||||
| 3089 | qt_static_metacall(this, _c, _id, _a); | - | ||||||||||||||||||
| 3090 | _id -= 1; | - | ||||||||||||||||||
| 3091 | } | - | ||||||||||||||||||
| 3092 | return _id; | - | ||||||||||||||||||
| 3093 | } | - | ||||||||||||||||||
| 3094 | // End moc-generated code | - | ||||||||||||||||||
| 3095 | - | |||||||||||||||||||
| 3096 | void QSignalEventGenerator::execute(void **_a) | - | ||||||||||||||||||
| 3097 | { | - | ||||||||||||||||||
| 3098 | int signalIndex = senderSignalIndex(); | - | ||||||||||||||||||
| 3099 | Q_ASSERT(signalIndex != -1); | - | ||||||||||||||||||
| 3100 | QStateMachine *machine = qobject_cast<QStateMachine*>(parent()); | - | ||||||||||||||||||
| 3101 | QStateMachinePrivate::get(machine)->handleTransitionSignal(sender(), signalIndex, _a); | - | ||||||||||||||||||
| 3102 | } executed 70 times by 2 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 3103 | - | |||||||||||||||||||
| 3104 | QSignalEventGenerator::QSignalEventGenerator(QStateMachine *parent) | - | ||||||||||||||||||
| 3105 | : QObject(parent) | - | ||||||||||||||||||
| 3106 | { | - | ||||||||||||||||||
| 3107 | } executed 43 times by 2 tests: end of blockExecuted by:
| 43 | ||||||||||||||||||
| 3108 | - | |||||||||||||||||||
| 3109 | /*! | - | ||||||||||||||||||
| 3110 | \class QStateMachine::SignalEvent | - | ||||||||||||||||||
| 3111 | \inmodule QtCore | - | ||||||||||||||||||
| 3112 | - | |||||||||||||||||||
| 3113 | \brief The SignalEvent class represents a Qt signal event. | - | ||||||||||||||||||
| 3114 | - | |||||||||||||||||||
| 3115 | \since 4.6 | - | ||||||||||||||||||
| 3116 | \ingroup statemachine | - | ||||||||||||||||||
| 3117 | - | |||||||||||||||||||
| 3118 | A signal event is generated by a QStateMachine in response to a Qt | - | ||||||||||||||||||
| 3119 | signal. The QSignalTransition class provides a transition associated with a | - | ||||||||||||||||||
| 3120 | signal event. QStateMachine::SignalEvent is part of \l{The State Machine Framework}. | - | ||||||||||||||||||
| 3121 | - | |||||||||||||||||||
| 3122 | The sender() function returns the object that generated the signal. The | - | ||||||||||||||||||
| 3123 | signalIndex() function returns the index of the signal. The arguments() | - | ||||||||||||||||||
| 3124 | function returns the arguments of the signal. | - | ||||||||||||||||||
| 3125 | - | |||||||||||||||||||
| 3126 | \sa QSignalTransition | - | ||||||||||||||||||
| 3127 | */ | - | ||||||||||||||||||
| 3128 | - | |||||||||||||||||||
| 3129 | /*! | - | ||||||||||||||||||
| 3130 | \internal | - | ||||||||||||||||||
| 3131 | - | |||||||||||||||||||
| 3132 | Constructs a new SignalEvent object with the given \a sender, \a | - | ||||||||||||||||||
| 3133 | signalIndex and \a arguments. | - | ||||||||||||||||||
| 3134 | */ | - | ||||||||||||||||||
| 3135 | QStateMachine::SignalEvent::SignalEvent(QObject *sender, int signalIndex, | - | ||||||||||||||||||
| 3136 | const QList<QVariant> &arguments) | - | ||||||||||||||||||
| 3137 | : QEvent(QEvent::StateMachineSignal), m_sender(sender), | - | ||||||||||||||||||
| 3138 | m_signalIndex(signalIndex), m_arguments(arguments) | - | ||||||||||||||||||
| 3139 | { | - | ||||||||||||||||||
| 3140 | } executed 71 times by 2 tests: end of blockExecuted by:
| 71 | ||||||||||||||||||
| 3141 | - | |||||||||||||||||||
| 3142 | /*! | - | ||||||||||||||||||
| 3143 | Destroys this SignalEvent. | - | ||||||||||||||||||
| 3144 | */ | - | ||||||||||||||||||
| 3145 | QStateMachine::SignalEvent::~SignalEvent() | - | ||||||||||||||||||
| 3146 | { | - | ||||||||||||||||||
| 3147 | } | - | ||||||||||||||||||
| 3148 | - | |||||||||||||||||||
| 3149 | /*! | - | ||||||||||||||||||
| 3150 | \fn QStateMachine::SignalEvent::sender() const | - | ||||||||||||||||||
| 3151 | - | |||||||||||||||||||
| 3152 | Returns the object that emitted the signal. | - | ||||||||||||||||||
| 3153 | - | |||||||||||||||||||
| 3154 | \sa QObject::sender() | - | ||||||||||||||||||
| 3155 | */ | - | ||||||||||||||||||
| 3156 | - | |||||||||||||||||||
| 3157 | /*! | - | ||||||||||||||||||
| 3158 | \fn QStateMachine::SignalEvent::signalIndex() const | - | ||||||||||||||||||
| 3159 | - | |||||||||||||||||||
| 3160 | Returns the index of the signal. | - | ||||||||||||||||||
| 3161 | - | |||||||||||||||||||
| 3162 | \sa QMetaObject::indexOfSignal(), QMetaObject::method() | - | ||||||||||||||||||
| 3163 | */ | - | ||||||||||||||||||
| 3164 | - | |||||||||||||||||||
| 3165 | /*! | - | ||||||||||||||||||
| 3166 | \fn QStateMachine::SignalEvent::arguments() const | - | ||||||||||||||||||
| 3167 | - | |||||||||||||||||||
| 3168 | Returns the arguments of the signal. | - | ||||||||||||||||||
| 3169 | */ | - | ||||||||||||||||||
| 3170 | - | |||||||||||||||||||
| 3171 | - | |||||||||||||||||||
| 3172 | /*! | - | ||||||||||||||||||
| 3173 | \class QStateMachine::WrappedEvent | - | ||||||||||||||||||
| 3174 | \inmodule QtCore | - | ||||||||||||||||||
| 3175 | - | |||||||||||||||||||
| 3176 | \brief The WrappedEvent class inherits QEvent and holds a clone of an event associated with a QObject. | - | ||||||||||||||||||
| 3177 | - | |||||||||||||||||||
| 3178 | \since 4.6 | - | ||||||||||||||||||
| 3179 | \ingroup statemachine | - | ||||||||||||||||||
| 3180 | - | |||||||||||||||||||
| 3181 | A wrapped event is generated by a QStateMachine in response to a Qt | - | ||||||||||||||||||
| 3182 | event. The QEventTransition class provides a transition associated with a | - | ||||||||||||||||||
| 3183 | such an event. QStateMachine::WrappedEvent is part of \l{The State Machine | - | ||||||||||||||||||
| 3184 | Framework}. | - | ||||||||||||||||||
| 3185 | - | |||||||||||||||||||
| 3186 | The object() function returns the object that generated the event. The | - | ||||||||||||||||||
| 3187 | event() function returns a clone of the original event. | - | ||||||||||||||||||
| 3188 | - | |||||||||||||||||||
| 3189 | \sa QEventTransition | - | ||||||||||||||||||
| 3190 | */ | - | ||||||||||||||||||
| 3191 | - | |||||||||||||||||||
| 3192 | /*! | - | ||||||||||||||||||
| 3193 | \internal | - | ||||||||||||||||||
| 3194 | - | |||||||||||||||||||
| 3195 | Constructs a new WrappedEvent object with the given \a object | - | ||||||||||||||||||
| 3196 | and \a event. | - | ||||||||||||||||||
| 3197 | - | |||||||||||||||||||
| 3198 | The WrappedEvent object takes ownership of \a event. | - | ||||||||||||||||||
| 3199 | */ | - | ||||||||||||||||||
| 3200 | QStateMachine::WrappedEvent::WrappedEvent(QObject *object, QEvent *event) | - | ||||||||||||||||||
| 3201 | : QEvent(QEvent::StateMachineWrapped), m_object(object), m_event(event) | - | ||||||||||||||||||
| 3202 | { | - | ||||||||||||||||||
| 3203 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 3204 | - | |||||||||||||||||||
| 3205 | /*! | - | ||||||||||||||||||
| 3206 | Destroys this WrappedEvent. | - | ||||||||||||||||||
| 3207 | */ | - | ||||||||||||||||||
| 3208 | QStateMachine::WrappedEvent::~WrappedEvent() | - | ||||||||||||||||||
| 3209 | { | - | ||||||||||||||||||
| 3210 | delete m_event; | - | ||||||||||||||||||
| 3211 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 3212 | - | |||||||||||||||||||
| 3213 | /*! | - | ||||||||||||||||||
| 3214 | \fn QStateMachine::WrappedEvent::object() const | - | ||||||||||||||||||
| 3215 | - | |||||||||||||||||||
| 3216 | Returns the object that the event is associated with. | - | ||||||||||||||||||
| 3217 | */ | - | ||||||||||||||||||
| 3218 | - | |||||||||||||||||||
| 3219 | /*! | - | ||||||||||||||||||
| 3220 | \fn QStateMachine::WrappedEvent::event() const | - | ||||||||||||||||||
| 3221 | - | |||||||||||||||||||
| 3222 | Returns a clone of the original event. | - | ||||||||||||||||||
| 3223 | */ | - | ||||||||||||||||||
| 3224 | - | |||||||||||||||||||
| 3225 | /*! | - | ||||||||||||||||||
| 3226 | \fn QStateMachine::runningChanged(bool running) | - | ||||||||||||||||||
| 3227 | \since 5.4 | - | ||||||||||||||||||
| 3228 | - | |||||||||||||||||||
| 3229 | This signal is emitted when the running property is changed with \a running as argument. | - | ||||||||||||||||||
| 3230 | - | |||||||||||||||||||
| 3231 | \sa QStateMachine::running | - | ||||||||||||||||||
| 3232 | */ | - | ||||||||||||||||||
| 3233 | - | |||||||||||||||||||
| 3234 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 3235 | - | |||||||||||||||||||
| 3236 | #include "qstatemachine.moc" | - | ||||||||||||||||||
| 3237 | #include "moc_qstatemachine.cpp" | - | ||||||||||||||||||
| 3238 | - | |||||||||||||||||||
| 3239 | #endif //QT_NO_STATEMACHINE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |