| 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) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qstatemachine.h" | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #ifndef QT_NO_STATEMACHINE | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | #include "qstate.h" | - | ||||||||||||||||||
| 39 | #include "qstate_p.h" | - | ||||||||||||||||||
| 40 | #include "qstatemachine_p.h" | - | ||||||||||||||||||
| 41 | #include "qabstracttransition.h" | - | ||||||||||||||||||
| 42 | #include "qabstracttransition_p.h" | - | ||||||||||||||||||
| 43 | #include "qsignaltransition.h" | - | ||||||||||||||||||
| 44 | #include "qsignaltransition_p.h" | - | ||||||||||||||||||
| 45 | #include "qsignaleventgenerator_p.h" | - | ||||||||||||||||||
| 46 | #include "qabstractstate.h" | - | ||||||||||||||||||
| 47 | #include "qabstractstate_p.h" | - | ||||||||||||||||||
| 48 | #include "qfinalstate.h" | - | ||||||||||||||||||
| 49 | #include "qhistorystate.h" | - | ||||||||||||||||||
| 50 | #include "qhistorystate_p.h" | - | ||||||||||||||||||
| 51 | #include "private/qobject_p.h" | - | ||||||||||||||||||
| 52 | #include "private/qthread_p.h" | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 55 | #include "qeventtransition.h" | - | ||||||||||||||||||
| 56 | #include "qeventtransition_p.h" | - | ||||||||||||||||||
| 57 | #endif | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 60 | #include "qpropertyanimation.h" | - | ||||||||||||||||||
| 61 | #include "qanimationgroup.h" | - | ||||||||||||||||||
| 62 | #include <private/qvariantanimation_p.h> | - | ||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | #include <QtCore/qmetaobject.h> | - | ||||||||||||||||||
| 66 | #include <qdebug.h> | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | #include <algorithm> | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | /*! | - | ||||||||||||||||||
| 73 | \class QStateMachine | - | ||||||||||||||||||
| 74 | \inmodule QtCore | - | ||||||||||||||||||
| 75 | \reentrant | - | ||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | \brief The QStateMachine class provides a hierarchical finite state machine. | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | \since 4.6 | - | ||||||||||||||||||
| 80 | \ingroup statemachine | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | QStateMachine is based on the concepts and notation of | - | ||||||||||||||||||
| 83 | \l{http://www.wisdom.weizmann.ac.il/~dharel/SCANNED.PAPERS/Statecharts.pdf}{Statecharts}. | - | ||||||||||||||||||
| 84 | QStateMachine is part of \l{The State Machine Framework}. | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | A state machine manages a set of states (classes that inherit from | - | ||||||||||||||||||
| 87 | QAbstractState) and transitions (descendants of | - | ||||||||||||||||||
| 88 | QAbstractTransition) between those states; these states and | - | ||||||||||||||||||
| 89 | transitions define a state graph. Once a state graph has been | - | ||||||||||||||||||
| 90 | built, the state machine can execute it. QStateMachine's | - | ||||||||||||||||||
| 91 | execution algorithm is based on the \l{http://www.w3.org/TR/scxml/}{State Chart XML (SCXML)} | - | ||||||||||||||||||
| 92 | algorithm. The framework's \l{The State Machine | - | ||||||||||||||||||
| 93 | Framework}{overview} gives several state graphs and the code to | - | ||||||||||||||||||
| 94 | build them. | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | Use the addState() function to add a top-level state to the state machine. | - | ||||||||||||||||||
| 97 | States are removed with the removeState() function. Removing states while | - | ||||||||||||||||||
| 98 | the machine is running is discouraged. | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | Before the machine can be started, the \l{initialState}{initial | - | ||||||||||||||||||
| 101 | state} must be set. The initial state is the state that the | - | ||||||||||||||||||
| 102 | machine enters when started. You can then start() the state | - | ||||||||||||||||||
| 103 | machine. The started() signal is emitted when the initial state is | - | ||||||||||||||||||
| 104 | entered. | - | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | The machine is event driven and keeps its own event loop. Events | - | ||||||||||||||||||
| 107 | are posted to the machine through postEvent(). Note that this | - | ||||||||||||||||||
| 108 | means that it executes asynchronously, and that it will not | - | ||||||||||||||||||
| 109 | progress without a running event loop. You will normally not have | - | ||||||||||||||||||
| 110 | to post events to the machine directly as Qt's transitions, e.g., | - | ||||||||||||||||||
| 111 | QEventTransition and its subclasses, handle this. But for custom | - | ||||||||||||||||||
| 112 | transitions triggered by events, postEvent() is useful. | - | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | The state machine processes events and takes transitions until a | - | ||||||||||||||||||
| 115 | top-level final state is entered; the state machine then emits the | - | ||||||||||||||||||
| 116 | finished() signal. You can also stop() the state machine | - | ||||||||||||||||||
| 117 | explicitly. The stopped() signal is emitted in this case. | - | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | The following snippet shows a state machine that will finish when a button | - | ||||||||||||||||||
| 120 | is clicked: | - | ||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | \snippet code/src_corelib_statemachine_qstatemachine.cpp simple state machine | - | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | This code example uses QState, which inherits QAbstractState. The | - | ||||||||||||||||||
| 125 | QState class provides a state that you can use to set properties | - | ||||||||||||||||||
| 126 | and invoke methods on \l{QObject}s when the state is entered or | - | ||||||||||||||||||
| 127 | exited. It also contains convenience functions for adding | - | ||||||||||||||||||
| 128 | transitions, e.g., \l{QSignalTransition}s as in this example. See | - | ||||||||||||||||||
| 129 | the QState class description for further details. | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | If an error is encountered, the machine will look for an | - | ||||||||||||||||||
| 132 | \l{errorState}{error state}, and if one is available, it will | - | ||||||||||||||||||
| 133 | enter this state. The types of errors possible are described by the | - | ||||||||||||||||||
| 134 | \l{QStateMachine::}{Error} enum. After the error state is entered, | - | ||||||||||||||||||
| 135 | the type of the error can be retrieved with error(). The execution | - | ||||||||||||||||||
| 136 | of the state graph will not stop when the error state is entered. If | - | ||||||||||||||||||
| 137 | no error state applies to the erroneous state, the machine will stop | - | ||||||||||||||||||
| 138 | executing and an error message will be printed to the console. | - | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | \sa QAbstractState, QAbstractTransition, QState, {The State Machine Framework} | - | ||||||||||||||||||
| 141 | */ | - | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | /*! | - | ||||||||||||||||||
| 144 | \property QStateMachine::errorString | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | \brief the error string of this state machine | - | ||||||||||||||||||
| 147 | */ | - | ||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | /*! | - | ||||||||||||||||||
| 150 | \property QStateMachine::globalRestorePolicy | - | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | \brief the restore policy for states of this state machine. | - | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | The default value of this property is | - | ||||||||||||||||||
| 155 | QState::DontRestoreProperties. | - | ||||||||||||||||||
| 156 | */ | - | ||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | /*! | - | ||||||||||||||||||
| 159 | \property QStateMachine::running | - | ||||||||||||||||||
| 160 | \since 5.4 | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | \brief the running state of this state machine | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | \sa start(), stop(), started(), stopped(), runningChanged() | - | ||||||||||||||||||
| 165 | */ | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 168 | /*! | - | ||||||||||||||||||
| 169 | \property QStateMachine::animated | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | \brief whether animations are enabled | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | The default value of this property is \c true. | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | \sa QAbstractTransition::addAnimation() | - | ||||||||||||||||||
| 176 | */ | - | ||||||||||||||||||
| 177 | #endif | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | // #define QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 180 | // #define QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | struct CalculationCache { | - | ||||||||||||||||||
| 183 | struct TransitionInfo { | - | ||||||||||||||||||
| 184 | QList<QAbstractState*> effectiveTargetStates; | - | ||||||||||||||||||
| 185 | QSet<QAbstractState*> exitSet; | - | ||||||||||||||||||
| 186 | QAbstractState *transitionDomain; | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | bool effectiveTargetStatesIsKnown: 1; | - | ||||||||||||||||||
| 189 | bool exitSetIsKnown : 1; | - | ||||||||||||||||||
| 190 | bool transitionDomainIsKnown : 1; | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | TransitionInfo() | - | ||||||||||||||||||
| 193 | : transitionDomain(0) | - | ||||||||||||||||||
| 194 | , effectiveTargetStatesIsKnown(false) | - | ||||||||||||||||||
| 195 | , exitSetIsKnown(false) | - | ||||||||||||||||||
| 196 | , transitionDomainIsKnown(false) | - | ||||||||||||||||||
| 197 | {} executed 1394 times by 2 tests: end of blockExecuted by:
| 1394 | ||||||||||||||||||
| 198 | }; | - | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | typedef QHash<QAbstractTransition *, TransitionInfo> TransitionInfoCache; | - | ||||||||||||||||||
| 201 | TransitionInfoCache cache; | - | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | bool effectiveTargetStates(QAbstractTransition *t, QList<QAbstractState *> *targets) const | - | ||||||||||||||||||
| 204 | { | - | ||||||||||||||||||
| 205 | Q_ASSERT(targets); | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | TransitionInfoCache::const_iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 208 | if (cacheIt == cache.end() || !cacheIt->effectiveTargetStatesIsKnown)
| 0-1394 | ||||||||||||||||||
| 209 | return false; executed 1394 times by 2 tests: return false;Executed by:
| 1394 | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | *targets = cacheIt->effectiveTargetStates; | - | ||||||||||||||||||
| 212 | return true; executed 1237 times by 2 tests: return true;Executed by:
| 1237 | ||||||||||||||||||
| 213 | } | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | void insert(QAbstractTransition *t, const QList<QAbstractState *> &targets) | - | ||||||||||||||||||
| 216 | { | - | ||||||||||||||||||
| 217 | TransitionInfoCache::iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 218 | TransitionInfo &ti = cacheIt == cache.end()
| 0-1394 | ||||||||||||||||||
| 219 | ? *cache.insert(t, TransitionInfo()) | - | ||||||||||||||||||
| 220 | : *cacheIt; | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | Q_ASSERT(!ti.effectiveTargetStatesIsKnown); | - | ||||||||||||||||||
| 223 | ti.effectiveTargetStates = targets; | - | ||||||||||||||||||
| 224 | ti.effectiveTargetStatesIsKnown = true; | - | ||||||||||||||||||
| 225 | } executed 1394 times by 2 tests: end of blockExecuted by:
| 1394 | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | bool exitSet(QAbstractTransition *t, QSet<QAbstractState *> *exits) const | - | ||||||||||||||||||
| 228 | { | - | ||||||||||||||||||
| 229 | Q_ASSERT(exits); | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | TransitionInfoCache::const_iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 232 | if (cacheIt == cache.end() || !cacheIt->exitSetIsKnown)
| 0-1241 | ||||||||||||||||||
| 233 | return false; executed 1241 times by 2 tests: return false;Executed by:
| 1241 | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | *exits = cacheIt->exitSet; | - | ||||||||||||||||||
| 236 | return true; executed 19 times by 1 test: return true;Executed by:
| 19 | ||||||||||||||||||
| 237 | } | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | void insert(QAbstractTransition *t, const QSet<QAbstractState *> &exits) | - | ||||||||||||||||||
| 240 | { | - | ||||||||||||||||||
| 241 | TransitionInfoCache::iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 242 | TransitionInfo &ti = cacheIt == cache.end()
| 0-1241 | ||||||||||||||||||
| 243 | ? *cache.insert(t, TransitionInfo()) | - | ||||||||||||||||||
| 244 | : *cacheIt; | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | Q_ASSERT(!ti.exitSetIsKnown); | - | ||||||||||||||||||
| 247 | ti.exitSet = exits; | - | ||||||||||||||||||
| 248 | ti.exitSetIsKnown = true; | - | ||||||||||||||||||
| 249 | } executed 1241 times by 2 tests: end of blockExecuted by:
| 1241 | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | bool transitionDomain(QAbstractTransition *t, QAbstractState **domain) const | - | ||||||||||||||||||
| 252 | { | - | ||||||||||||||||||
| 253 | Q_ASSERT(domain); | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | TransitionInfoCache::const_iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 256 | if (cacheIt == cache.end() || !cacheIt->transitionDomainIsKnown)
| 0-2620 | ||||||||||||||||||
| 257 | return false; executed 1389 times by 2 tests: return false;Executed by:
| 1389 | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | *domain = cacheIt->transitionDomain; | - | ||||||||||||||||||
| 260 | return true; executed 1231 times by 2 tests: return true;Executed by:
| 1231 | ||||||||||||||||||
| 261 | } | - | ||||||||||||||||||
| 262 | - | |||||||||||||||||||
| 263 | void insert(QAbstractTransition *t, QAbstractState *domain) | - | ||||||||||||||||||
| 264 | { | - | ||||||||||||||||||
| 265 | TransitionInfoCache::iterator cacheIt = cache.find(t); | - | ||||||||||||||||||
| 266 | TransitionInfo &ti = cacheIt == cache.end()
| 0-1387 | ||||||||||||||||||
| 267 | ? *cache.insert(t, TransitionInfo()) | - | ||||||||||||||||||
| 268 | : *cacheIt; | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | Q_ASSERT(!ti.transitionDomainIsKnown); | - | ||||||||||||||||||
| 271 | ti.transitionDomain = domain; | - | ||||||||||||||||||
| 272 | ti.transitionDomainIsKnown = true; | - | ||||||||||||||||||
| 273 | } executed 1387 times by 2 tests: end of blockExecuted by:
| 1387 | ||||||||||||||||||
| 274 | }; | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | function isDescendant(state1, state2) | - | ||||||||||||||||||
| 279 | - | |||||||||||||||||||
| 280 | Returns 'true' if state1 is a descendant of state2 (a child, or a child of a child, or a child of a | - | ||||||||||||||||||
| 281 | child of a child, etc.) Otherwise returns 'false'. | - | ||||||||||||||||||
| 282 | */ | - | ||||||||||||||||||
| 283 | static inline bool isDescendant(const QAbstractState *state1, const QAbstractState *state2) | - | ||||||||||||||||||
| 284 | { | - | ||||||||||||||||||
| 285 | Q_ASSERT(state1 != 0); | - | ||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | for (QAbstractState *it = state1->parentState(); it != 0; it = it->parentState()) {
| 1548-9215 | ||||||||||||||||||
| 288 | if (it == state2)
| 3427-5788 | ||||||||||||||||||
| 289 | return true; executed 3427 times by 2 tests: return true;Executed by:
| 3427 | ||||||||||||||||||
| 290 | } executed 5788 times by 2 tests: end of blockExecuted by:
| 5788 | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | return false; executed 1548 times by 2 tests: return false;Executed by:
| 1548 | ||||||||||||||||||
| 293 | } | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | static bool containsDecendantOf(const QSet<QAbstractState *> &states, const QAbstractState *node) | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | foreach (QAbstractState *s, states) | - | ||||||||||||||||||
| 298 | if (isDescendant(s, node))
| 36-401 | ||||||||||||||||||
| 299 | return true; executed 36 times by 1 test: return true;Executed by:
| 36 | ||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | return false; executed 56 times by 1 test: return false;Executed by:
| 56 | ||||||||||||||||||
| 302 | } | - | ||||||||||||||||||
| 303 | - | |||||||||||||||||||
| 304 | static int descendantDepth(const QAbstractState *state, const QAbstractState *ancestor) | - | ||||||||||||||||||
| 305 | { | - | ||||||||||||||||||
| 306 | int depth = 0; | - | ||||||||||||||||||
| 307 | for (const QAbstractState *it = state; it != 0; it = it->parentState()) {
| 0-62 | ||||||||||||||||||
| 308 | if (it == ancestor)
| 24-38 | ||||||||||||||||||
| 309 | break; executed 24 times by 1 test: break;Executed by:
| 24 | ||||||||||||||||||
| 310 | ++depth; | - | ||||||||||||||||||
| 311 | } executed 38 times by 1 test: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 312 | return depth; executed 24 times by 1 test: return depth;Executed by:
| 24 | ||||||||||||||||||
| 313 | } | - | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | function getProperAncestors(state1, state2) | - | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | If state2 is null, returns the set of all ancestors of state1 in ancestry order (state1's parent | - | ||||||||||||||||||
| 320 | followed by the parent's parent, etc. up to an including the <scxml> element). If state2 is | - | ||||||||||||||||||
| 321 | non-null, returns in ancestry order the set of all ancestors of state1, up to but not including | - | ||||||||||||||||||
| 322 | state2. (A "proper ancestor" of a state is its parent, or the parent's parent, or the parent's | - | ||||||||||||||||||
| 323 | parent's parent, etc.))If state2 is state1's parent, or equal to state1, or a descendant of state1, | - | ||||||||||||||||||
| 324 | this returns the empty set. | - | ||||||||||||||||||
| 325 | */ | - | ||||||||||||||||||
| 326 | static QVector<QState*> getProperAncestors(const QAbstractState *state, const QAbstractState *upperBound) | - | ||||||||||||||||||
| 327 | { | - | ||||||||||||||||||
| 328 | Q_ASSERT(state != 0); | - | ||||||||||||||||||
| 329 | QVector<QState*> result; | - | ||||||||||||||||||
| 330 | result.reserve(16); | - | ||||||||||||||||||
| 331 | for (QState *it = state->parentState(); it && it != upperBound; it = it->parentState()) {
| 1468-8246 | ||||||||||||||||||
| 332 | result.append(it); | - | ||||||||||||||||||
| 333 | } executed 6778 times by 2 tests: end of blockExecuted by:
| 6778 | ||||||||||||||||||
| 334 | return result; executed 6913 times by 2 tests: return result;Executed by:
| 6913 | ||||||||||||||||||
| 335 | } | - | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | function getEffectiveTargetStates(transition) | - | ||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | Returns the states that will be the target when 'transition' is taken, dereferencing any history states. | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | function getEffectiveTargetStates(transition) | - | ||||||||||||||||||
| 344 | targets = new OrderedSet() | - | ||||||||||||||||||
| 345 | for s in transition.target | - | ||||||||||||||||||
| 346 | if isHistoryState(s): | - | ||||||||||||||||||
| 347 | if historyValue[s.id]: | - | ||||||||||||||||||
| 348 | targets.union(historyValue[s.id]) | - | ||||||||||||||||||
| 349 | else: | - | ||||||||||||||||||
| 350 | targets.union(getEffectiveTargetStates(s.transition)) | - | ||||||||||||||||||
| 351 | else: | - | ||||||||||||||||||
| 352 | targets.add(s) | - | ||||||||||||||||||
| 353 | return targets | - | ||||||||||||||||||
| 354 | */ | - | ||||||||||||||||||
| 355 | static QList<QAbstractState *> getEffectiveTargetStates(QAbstractTransition *transition, CalculationCache *cache) | - | ||||||||||||||||||
| 356 | { | - | ||||||||||||||||||
| 357 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | QList<QAbstractState *> targetsList; | - | ||||||||||||||||||
| 360 | if (cache->effectiveTargetStates(transition, &targetsList))
| 1237-1394 | ||||||||||||||||||
| 361 | return targetsList; executed 1237 times by 2 tests: return targetsList;Executed by:
| 1237 | ||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | QSet<QAbstractState *> targets; | - | ||||||||||||||||||
| 364 | foreach (QAbstractState *s, transition->targetStates()) { | - | ||||||||||||||||||
| 365 | if (QHistoryState *historyState = QStateMachinePrivate::toHistoryState(s)) {
| 9-1381 | ||||||||||||||||||
| 366 | QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(historyState)->configuration; | - | ||||||||||||||||||
| 367 | if (!historyConfiguration.isEmpty()) {
| 4-5 | ||||||||||||||||||
| 368 | // There is a saved history, so apply that. | - | ||||||||||||||||||
| 369 | targets.unite(historyConfiguration.toSet()); | - | ||||||||||||||||||
| 370 | } else if (QAbstractTransition *defaultTransition = historyState->defaultTransition()) { executed 5 times by 1 test: end of blockExecuted by:
| 1-5 | ||||||||||||||||||
| 371 | // No saved history, take all default transition targets. | - | ||||||||||||||||||
| 372 | targets.unite(defaultTransition->targetStates().toSet()); | - | ||||||||||||||||||
| 373 | } else { executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 374 | // Woops, we found a history state without a default state. That's not valid! | - | ||||||||||||||||||
| 375 | QStateMachinePrivate *m = QStateMachinePrivate::get(historyState->machine()); | - | ||||||||||||||||||
| 376 | m->setError(QStateMachine::NoDefaultStateInHistoryStateError, historyState); | - | ||||||||||||||||||
| 377 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 378 | } else { | - | ||||||||||||||||||
| 379 | targets.insert(s); | - | ||||||||||||||||||
| 380 | } executed 1381 times by 2 tests: end of blockExecuted by:
| 1381 | ||||||||||||||||||
| 381 | } | - | ||||||||||||||||||
| 382 | - | |||||||||||||||||||
| 383 | targetsList = targets.toList(); | - | ||||||||||||||||||
| 384 | cache->insert(transition, targetsList); | - | ||||||||||||||||||
| 385 | return targetsList; executed 1394 times by 2 tests: return targetsList;Executed by:
| 1394 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | QStateMachinePrivate::QStateMachinePrivate() | - | ||||||||||||||||||
| 389 | { | - | ||||||||||||||||||
| 390 | isMachine = true; | - | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | state = NotRunning; | - | ||||||||||||||||||
| 393 | processing = false; | - | ||||||||||||||||||
| 394 | processingScheduled = false; | - | ||||||||||||||||||
| 395 | stop = false; | - | ||||||||||||||||||
| 396 | stopProcessingReason = EventQueueEmpty; | - | ||||||||||||||||||
| 397 | error = QStateMachine::NoError; | - | ||||||||||||||||||
| 398 | globalRestorePolicy = QState::DontRestoreProperties; | - | ||||||||||||||||||
| 399 | signalEventGenerator = 0; | - | ||||||||||||||||||
| 400 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 401 | animated = true; | - | ||||||||||||||||||
| 402 | #endif | - | ||||||||||||||||||
| 403 | } executed 145 times by 2 tests: end of blockExecuted by:
| 145 | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | QStateMachinePrivate::~QStateMachinePrivate() | - | ||||||||||||||||||
| 406 | { | - | ||||||||||||||||||
| 407 | qDeleteAll(internalEventQueue); | - | ||||||||||||||||||
| 408 | qDeleteAll(externalEventQueue); | - | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | for (QHash<int, DelayedEvent>::const_iterator it = delayedEvents.begin(), eit = delayedEvents.end(); it != eit; ++it) {
| 0-145 | ||||||||||||||||||
| 411 | delete it.value().event; | - | ||||||||||||||||||
| 412 | } never executed: end of block | 0 | ||||||||||||||||||
| 413 | } executed 145 times by 2 tests: end of blockExecuted by:
| 145 | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | QState *QStateMachinePrivate::rootState() const | - | ||||||||||||||||||
| 416 | { | - | ||||||||||||||||||
| 417 | return const_cast<QStateMachine*>(q_func()); executed 5217 times by 2 tests: return const_cast<QStateMachine*>(q_func());Executed by:
| 5217 | ||||||||||||||||||
| 418 | } | - | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | static QEvent *cloneEvent(QEvent *e) | - | ||||||||||||||||||
| 421 | { | - | ||||||||||||||||||
| 422 | switch (e->type()) { | - | ||||||||||||||||||
| 423 | case QEvent::None: never executed: case QEvent::None: | 0 | ||||||||||||||||||
| 424 | return new QEvent(*e); never executed: return new QEvent(*e); | 0 | ||||||||||||||||||
| 425 | case QEvent::Timer: executed 7 times by 1 test: case QEvent::Timer:Executed by:
| 7 | ||||||||||||||||||
| 426 | return new QTimerEvent(*static_cast<QTimerEvent*>(e)); executed 7 times by 1 test: return new QTimerEvent(*static_cast<QTimerEvent*>(e));Executed by:
| 7 | ||||||||||||||||||
| 427 | default: never executed: default: | 0 | ||||||||||||||||||
| 428 | Q_ASSERT_X(false, "cloneEvent()", "not implemented"); | - | ||||||||||||||||||
| 429 | break; never executed: break; | 0 | ||||||||||||||||||
| 430 | } | - | ||||||||||||||||||
| 431 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 432 | } | - | ||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | const QStateMachinePrivate::Handler qt_kernel_statemachine_handler = { | - | ||||||||||||||||||
| 435 | cloneEvent | - | ||||||||||||||||||
| 436 | }; | - | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | const QStateMachinePrivate::Handler *QStateMachinePrivate::handler = &qt_kernel_statemachine_handler; | - | ||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler() | - | ||||||||||||||||||
| 441 | { | - | ||||||||||||||||||
| 442 | return &qt_kernel_statemachine_handler; executed 7 times by 1 test: return &qt_kernel_statemachine_handler;Executed by:
| 7 | ||||||||||||||||||
| 443 | } | - | ||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | static int indexOfDescendant(QState *s, QAbstractState *desc) | - | ||||||||||||||||||
| 446 | { | - | ||||||||||||||||||
| 447 | QList<QAbstractState*> childStates = QStatePrivate::get(s)->childStates(); | - | ||||||||||||||||||
| 448 | for (int i = 0; i < childStates.size(); ++i) {
| 0-680 | ||||||||||||||||||
| 449 | QAbstractState *c = childStates.at(i); | - | ||||||||||||||||||
| 450 | if ((c == desc) || isDescendant(desc, c)) {
| 130-550 | ||||||||||||||||||
| 451 | return i; executed 426 times by 1 test: return i;Executed by:
| 426 | ||||||||||||||||||
| 452 | } | - | ||||||||||||||||||
| 453 | } executed 254 times by 1 test: end of blockExecuted by:
| 254 | ||||||||||||||||||
| 454 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 455 | } | - | ||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | bool QStateMachinePrivate::transitionStateEntryLessThan(QAbstractTransition *t1, QAbstractTransition *t2) | - | ||||||||||||||||||
| 458 | { | - | ||||||||||||||||||
| 459 | QState *s1 = t1->sourceState(), *s2 = t2->sourceState(); | - | ||||||||||||||||||
| 460 | if (s1 == s2) {
| 6-12 | ||||||||||||||||||
| 461 | QList<QAbstractTransition*> transitions = QStatePrivate::get(s1)->transitions(); | - | ||||||||||||||||||
| 462 | return transitions.indexOf(t1) < transitions.indexOf(t2); executed 6 times by 1 test: return transitions.indexOf(t1) < transitions.indexOf(t2);Executed by:
| 6 | ||||||||||||||||||
| 463 | } else if (isDescendant(s1, s2)) {
| 0-12 | ||||||||||||||||||
| 464 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 465 | } else if (isDescendant(s2, s1)) {
| 0-12 | ||||||||||||||||||
| 466 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 467 | } else { | - | ||||||||||||||||||
| 468 | Q_ASSERT(s1->machine() != 0); | - | ||||||||||||||||||
| 469 | QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); | - | ||||||||||||||||||
| 470 | QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); | - | ||||||||||||||||||
| 471 | Q_ASSERT(lca != 0); | - | ||||||||||||||||||
| 472 | int s1Depth = descendantDepth(s1, lca); | - | ||||||||||||||||||
| 473 | int s2Depth = descendantDepth(s2, lca); | - | ||||||||||||||||||
| 474 | if (s1Depth == s2Depth)
| 4-8 | ||||||||||||||||||
| 475 | return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2)); executed 8 times by 1 test: return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));Executed by:
| 8 | ||||||||||||||||||
| 476 | else | - | ||||||||||||||||||
| 477 | return s1Depth > s2Depth; executed 4 times by 1 test: return s1Depth > s2Depth;Executed by:
| 4 | ||||||||||||||||||
| 478 | } | - | ||||||||||||||||||
| 479 | } | - | ||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState *s2) | - | ||||||||||||||||||
| 482 | { | - | ||||||||||||||||||
| 483 | if (s1->parent() == s2->parent()) {
| 41-403 | ||||||||||||||||||
| 484 | return s1->parent()->children().indexOf(s1) executed 41 times by 1 test: return s1->parent()->children().indexOf(s1) < s2->parent()->children().indexOf(s2);Executed by:
| 41 | ||||||||||||||||||
| 485 | < s2->parent()->children().indexOf(s2); executed 41 times by 1 test: return s1->parent()->children().indexOf(s1) < s2->parent()->children().indexOf(s2);Executed by:
| 41 | ||||||||||||||||||
| 486 | } else if (isDescendant(s1, s2)) {
| 128-275 | ||||||||||||||||||
| 487 | return false; executed 128 times by 2 tests: return false;Executed by:
| 128 | ||||||||||||||||||
| 488 | } else if (isDescendant(s2, s1)) {
| 94-181 | ||||||||||||||||||
| 489 | return true; executed 94 times by 1 test: return true;Executed by:
| 94 | ||||||||||||||||||
| 490 | } else { | - | ||||||||||||||||||
| 491 | Q_ASSERT(s1->machine() != 0); | - | ||||||||||||||||||
| 492 | QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); | - | ||||||||||||||||||
| 493 | QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); | - | ||||||||||||||||||
| 494 | Q_ASSERT(lca != 0); | - | ||||||||||||||||||
| 495 | return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2)); executed 181 times by 1 test: return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));Executed by:
| 181 | ||||||||||||||||||
| 496 | } | - | ||||||||||||||||||
| 497 | } | - | ||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState *s2) | - | ||||||||||||||||||
| 500 | { | - | ||||||||||||||||||
| 501 | if (s1->parent() == s2->parent()) {
| 9-122 | ||||||||||||||||||
| 502 | return s2->parent()->children().indexOf(s2) executed 9 times by 1 test: return s2->parent()->children().indexOf(s2) < s1->parent()->children().indexOf(s1);Executed by:
| 9 | ||||||||||||||||||
| 503 | < s1->parent()->children().indexOf(s1); executed 9 times by 1 test: return s2->parent()->children().indexOf(s2) < s1->parent()->children().indexOf(s1);Executed by:
| 9 | ||||||||||||||||||
| 504 | } else if (isDescendant(s1, s2)) {
| 43-79 | ||||||||||||||||||
| 505 | return true; executed 43 times by 2 tests: return true;Executed by:
| 43 | ||||||||||||||||||
| 506 | } else if (isDescendant(s2, s1)) {
| 24-55 | ||||||||||||||||||
| 507 | return false; executed 55 times by 2 tests: return false;Executed by:
| 55 | ||||||||||||||||||
| 508 | } else { | - | ||||||||||||||||||
| 509 | Q_ASSERT(s1->machine() != 0); | - | ||||||||||||||||||
| 510 | QStateMachinePrivate *mach = QStateMachinePrivate::get(s1->machine()); | - | ||||||||||||||||||
| 511 | QState *lca = mach->findLCA(QList<QAbstractState*>() << s1 << s2); | - | ||||||||||||||||||
| 512 | Q_ASSERT(lca != 0); | - | ||||||||||||||||||
| 513 | return (indexOfDescendant(lca, s2) < indexOfDescendant(lca, s1)); executed 24 times by 1 test: return (indexOfDescendant(lca, s2) < indexOfDescendant(lca, s1));Executed by:
| 24 | ||||||||||||||||||
| 514 | } | - | ||||||||||||||||||
| 515 | } | - | ||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | QState *QStateMachinePrivate::findLCA(const QList<QAbstractState*> &states, bool onlyCompound) const | - | ||||||||||||||||||
| 518 | { | - | ||||||||||||||||||
| 519 | if (states.isEmpty())
| 0-1608 | ||||||||||||||||||
| 520 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 521 | QVector<QState*> ancestors = getProperAncestors(states.at(0), rootState()->parentState()); | - | ||||||||||||||||||
| 522 | for (int i = 0; i < ancestors.size(); ++i) {
| 4-1819 | ||||||||||||||||||
| 523 | QState *anc = ancestors.at(i); | - | ||||||||||||||||||
| 524 | if (onlyCompound && !isCompound(anc))
| 12-1415 | ||||||||||||||||||
| 525 | continue; executed 12 times by 1 test: continue;Executed by:
| 12 | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | bool ok = true; | - | ||||||||||||||||||
| 528 | for (int j = states.size() - 1; (j > 0) && ok; --j) {
| 0-1807 | ||||||||||||||||||
| 529 | const QAbstractState *s = states.at(j); | - | ||||||||||||||||||
| 530 | if (!isDescendant(s, anc))
| 203-1453 | ||||||||||||||||||
| 531 | ok = false; executed 203 times by 1 test: ok = false;Executed by:
| 203 | ||||||||||||||||||
| 532 | } executed 1656 times by 2 tests: end of blockExecuted by:
| 1656 | ||||||||||||||||||
| 533 | if (ok)
| 203-1604 | ||||||||||||||||||
| 534 | return anc; executed 1604 times by 2 tests: return anc;Executed by:
| 1604 | ||||||||||||||||||
| 535 | } executed 203 times by 1 test: end of blockExecuted by:
| 203 | ||||||||||||||||||
| 536 | return 0; executed 4 times by 1 test: return 0;Executed by:
| 4 | ||||||||||||||||||
| 537 | } | - | ||||||||||||||||||
| 538 | - | |||||||||||||||||||
| 539 | QState *QStateMachinePrivate::findLCCA(const QList<QAbstractState*> &states) const | - | ||||||||||||||||||
| 540 | { | - | ||||||||||||||||||
| 541 | return findLCA(states, true); executed 1391 times by 2 tests: return findLCA(states, true);Executed by:
| 1391 | ||||||||||||||||||
| 542 | } | - | ||||||||||||||||||
| 543 | - | |||||||||||||||||||
| 544 | QList<QAbstractTransition*> QStateMachinePrivate::selectTransitions(QEvent *event, CalculationCache *cache) | - | ||||||||||||||||||
| 545 | { | - | ||||||||||||||||||
| 546 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 547 | Q_Q(const QStateMachine); | - | ||||||||||||||||||
| 548 | - | |||||||||||||||||||
| 549 | QVarLengthArray<QAbstractState *> configuration_sorted; | - | ||||||||||||||||||
| 550 | foreach (QAbstractState *s, configuration) { | - | ||||||||||||||||||
| 551 | if (isAtomic(s))
| 386-3838 | ||||||||||||||||||
| 552 | configuration_sorted.append(s); executed 3838 times by 2 tests: configuration_sorted.append(s);Executed by:
| 3838 | ||||||||||||||||||
| 553 | } executed 4224 times by 2 tests: end of blockExecuted by:
| 4224 | ||||||||||||||||||
| 554 | std::sort(configuration_sorted.begin(), configuration_sorted.end(), stateEntryLessThan); | - | ||||||||||||||||||
| 555 | - | |||||||||||||||||||
| 556 | QList<QAbstractTransition*> enabledTransitions; | - | ||||||||||||||||||
| 557 | const_cast<QStateMachine*>(q)->beginSelectTransitions(event); | - | ||||||||||||||||||
| 558 | foreach (QAbstractState *state, configuration_sorted) { | - | ||||||||||||||||||
| 559 | QVector<QState*> lst = getProperAncestors(state, Q_NULLPTR); | - | ||||||||||||||||||
| 560 | if (QState *grp = toStandardState(state))
| 23-3815 | ||||||||||||||||||
| 561 | lst.prepend(grp); executed 3815 times by 2 tests: lst.prepend(grp);Executed by:
| 3815 | ||||||||||||||||||
| 562 | bool found = false; | - | ||||||||||||||||||
| 563 | for (int j = 0; (j < lst.size()) && !found; ++j) {
| 1244-8136 | ||||||||||||||||||
| 564 | QState *s = lst.at(j); | - | ||||||||||||||||||
| 565 | QList<QAbstractTransition*> transitions = QStatePrivate::get(s)->transitions(); | - | ||||||||||||||||||
| 566 | for (int k = 0; k < transitions.size(); ++k) {
| 5648-5945 | ||||||||||||||||||
| 567 | QAbstractTransition *t = transitions.at(k); | - | ||||||||||||||||||
| 568 | if (QAbstractTransitionPrivate::get(t)->callEventTest(event)) {
| 1244-4701 | ||||||||||||||||||
| 569 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 570 | qDebug() << q << ": selecting transition" << t; | - | ||||||||||||||||||
| 571 | #endif | - | ||||||||||||||||||
| 572 | enabledTransitions.append(t); | - | ||||||||||||||||||
| 573 | found = true; | - | ||||||||||||||||||
| 574 | break; executed 1244 times by 2 tests: break;Executed by:
| 1244 | ||||||||||||||||||
| 575 | } | - | ||||||||||||||||||
| 576 | } executed 4701 times by 2 tests: end of blockExecuted by:
| 4701 | ||||||||||||||||||
| 577 | } executed 6892 times by 2 tests: end of blockExecuted by:
| 6892 | ||||||||||||||||||
| 578 | } executed 3838 times by 2 tests: end of blockExecuted by:
| 3838 | ||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | if (!enabledTransitions.isEmpty()) {
| 1235-2515 | ||||||||||||||||||
| 581 | removeConflictingTransitions(enabledTransitions, cache); | - | ||||||||||||||||||
| 582 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 583 | qDebug() << q << ": enabled transitions after removing conflicts:" << enabledTransitions; | - | ||||||||||||||||||
| 584 | #endif | - | ||||||||||||||||||
| 585 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 586 | const_cast<QStateMachine*>(q)->endSelectTransitions(event); | - | ||||||||||||||||||
| 587 | return enabledTransitions; executed 3750 times by 2 tests: return enabledTransitions;Executed by:
| 3750 | ||||||||||||||||||
| 588 | } | - | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | function removeConflictingTransitions(enabledTransitions): | - | ||||||||||||||||||
| 593 | filteredTransitions = new OrderedSet() | - | ||||||||||||||||||
| 594 | // toList sorts the transitions in the order of the states that selected them | - | ||||||||||||||||||
| 595 | for t1 in enabledTransitions.toList(): | - | ||||||||||||||||||
| 596 | t1Preempted = false; | - | ||||||||||||||||||
| 597 | transitionsToRemove = new OrderedSet() | - | ||||||||||||||||||
| 598 | for t2 in filteredTransitions.toList(): | - | ||||||||||||||||||
| 599 | if computeExitSet([t1]).hasIntersection(computeExitSet([t2])): | - | ||||||||||||||||||
| 600 | if isDescendant(t1.source, t2.source): | - | ||||||||||||||||||
| 601 | transitionsToRemove.add(t2) | - | ||||||||||||||||||
| 602 | else: | - | ||||||||||||||||||
| 603 | t1Preempted = true | - | ||||||||||||||||||
| 604 | break | - | ||||||||||||||||||
| 605 | if not t1Preempted: | - | ||||||||||||||||||
| 606 | for t3 in transitionsToRemove.toList(): | - | ||||||||||||||||||
| 607 | filteredTransitions.delete(t3) | - | ||||||||||||||||||
| 608 | filteredTransitions.add(t1) | - | ||||||||||||||||||
| 609 | - | |||||||||||||||||||
| 610 | return filteredTransitions | - | ||||||||||||||||||
| 611 | - | |||||||||||||||||||
| 612 | Note: the implementation below does not build the transitionsToRemove, but removes them in-place. | - | ||||||||||||||||||
| 613 | */ | - | ||||||||||||||||||
| 614 | void QStateMachinePrivate::removeConflictingTransitions(QList<QAbstractTransition*> &enabledTransitions, CalculationCache *cache) | - | ||||||||||||||||||
| 615 | { | - | ||||||||||||||||||
| 616 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 617 | - | |||||||||||||||||||
| 618 | if (enabledTransitions.size() < 2)
| 6-1229 | ||||||||||||||||||
| 619 | return; // There is no transition to conflict with. executed 1229 times by 2 tests: return;Executed by:
| 1229 | ||||||||||||||||||
| 620 | - | |||||||||||||||||||
| 621 | QList<QAbstractTransition*> filteredTransitions; | - | ||||||||||||||||||
| 622 | filteredTransitions.reserve(enabledTransitions.size()); | - | ||||||||||||||||||
| 623 | std::sort(enabledTransitions.begin(), enabledTransitions.end(), transitionStateEntryLessThan); | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | foreach (QAbstractTransition *t1, enabledTransitions) { | - | ||||||||||||||||||
| 626 | bool t1Preempted = false; | - | ||||||||||||||||||
| 627 | const QSet<QAbstractState*> exitSetT1 = computeExitSet_Unordered(t1, cache); | - | ||||||||||||||||||
| 628 | QList<QAbstractTransition*>::iterator t2It = filteredTransitions.begin(); | - | ||||||||||||||||||
| 629 | while (t2It != filteredTransitions.end()) {
| 9-10 | ||||||||||||||||||
| 630 | QAbstractTransition *t2 = *t2It; | - | ||||||||||||||||||
| 631 | if (t1 == t2) {
| 3-7 | ||||||||||||||||||
| 632 | // Special case: someone added the same transition object to a state twice. In this | - | ||||||||||||||||||
| 633 | // case, t2 (which is already in the list) "preempts" t1. | - | ||||||||||||||||||
| 634 | t1Preempted = true; | - | ||||||||||||||||||
| 635 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 636 | } | - | ||||||||||||||||||
| 637 | - | |||||||||||||||||||
| 638 | QSet<QAbstractState*> exitSetT2 = computeExitSet_Unordered(t2, cache); | - | ||||||||||||||||||
| 639 | if (!exitSetT1.intersects(exitSetT2)) {
| 3-4 | ||||||||||||||||||
| 640 | // No conflict, no cry. Next patient please. | - | ||||||||||||||||||
| 641 | ++t2It; | - | ||||||||||||||||||
| 642 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 643 | // Houston, we have a conflict. Check which transition can be removed. | - | ||||||||||||||||||
| 644 | if (isDescendant(t1->sourceState(), t2->sourceState())) {
| 0-3 | ||||||||||||||||||
| 645 | // t1 preempts t2, so we can remove t2 | - | ||||||||||||||||||
| 646 | t2It = filteredTransitions.erase(t2It); | - | ||||||||||||||||||
| 647 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 648 | // t2 preempts t1, so there's no use in looking further and we don't need to add | - | ||||||||||||||||||
| 649 | // t1 to the list. | - | ||||||||||||||||||
| 650 | t1Preempted = true; | - | ||||||||||||||||||
| 651 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 652 | } | - | ||||||||||||||||||
| 653 | } | - | ||||||||||||||||||
| 654 | } | - | ||||||||||||||||||
| 655 | if (!t1Preempted)
| 6-9 | ||||||||||||||||||
| 656 | filteredTransitions.append(t1); executed 9 times by 1 test: filteredTransitions.append(t1);Executed by:
| 9 | ||||||||||||||||||
| 657 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | enabledTransitions = filteredTransitions; | - | ||||||||||||||||||
| 660 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 661 | - | |||||||||||||||||||
| 662 | void QStateMachinePrivate::microstep(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions, | - | ||||||||||||||||||
| 663 | CalculationCache *cache) | - | ||||||||||||||||||
| 664 | { | - | ||||||||||||||||||
| 665 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 668 | qDebug() << q_func() << ": begin microstep( enabledTransitions:" << enabledTransitions << ')'; | - | ||||||||||||||||||
| 669 | qDebug() << q_func() << ": configuration before exiting states:" << configuration; | - | ||||||||||||||||||
| 670 | #endif | - | ||||||||||||||||||
| 671 | QList<QAbstractState*> exitedStates = computeExitSet(enabledTransitions, cache); | - | ||||||||||||||||||
| 672 | QHash<RestorableId, QVariant> pendingRestorables = computePendingRestorables(exitedStates); | - | ||||||||||||||||||
| 673 | - | |||||||||||||||||||
| 674 | QSet<QAbstractState*> statesForDefaultEntry; | - | ||||||||||||||||||
| 675 | QList<QAbstractState*> enteredStates = computeEntrySet(enabledTransitions, statesForDefaultEntry, cache); | - | ||||||||||||||||||
| 676 | - | |||||||||||||||||||
| 677 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 678 | qDebug() << q_func() << ": computed exit set:" << exitedStates; | - | ||||||||||||||||||
| 679 | qDebug() << q_func() << ": computed entry set:" << enteredStates; | - | ||||||||||||||||||
| 680 | #endif | - | ||||||||||||||||||
| 681 | - | |||||||||||||||||||
| 682 | QHash<QAbstractState*, QVector<QPropertyAssignment> > assignmentsForEnteredStates = | - | ||||||||||||||||||
| 683 | computePropertyAssignments(enteredStates, pendingRestorables); | - | ||||||||||||||||||
| 684 | if (!pendingRestorables.isEmpty()) {
| 23-1212 | ||||||||||||||||||
| 685 | // Add "implicit" assignments for restored properties to the first | - | ||||||||||||||||||
| 686 | // (outermost) entered state | - | ||||||||||||||||||
| 687 | Q_ASSERT(!enteredStates.isEmpty()); | - | ||||||||||||||||||
| 688 | QAbstractState *s = enteredStates.first(); | - | ||||||||||||||||||
| 689 | assignmentsForEnteredStates[s] << restorablesToPropertyList(pendingRestorables); | - | ||||||||||||||||||
| 690 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | exitStates(event, exitedStates, assignmentsForEnteredStates); | - | ||||||||||||||||||
| 693 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 694 | qDebug() << q_func() << ": configuration after exiting states:" << configuration; | - | ||||||||||||||||||
| 695 | #endif | - | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | executeTransitionContent(event, enabledTransitions); | - | ||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 700 | QList<QAbstractAnimation *> selectedAnimations = selectAnimations(enabledTransitions); | - | ||||||||||||||||||
| 701 | #endif | - | ||||||||||||||||||
| 702 | - | |||||||||||||||||||
| 703 | enterStates(event, exitedStates, enteredStates, statesForDefaultEntry, assignmentsForEnteredStates | - | ||||||||||||||||||
| 704 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 705 | , selectedAnimations | - | ||||||||||||||||||
| 706 | #endif | - | ||||||||||||||||||
| 707 | ); | - | ||||||||||||||||||
| 708 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 709 | qDebug() << q_func() << ": configuration after entering states:" << configuration; | - | ||||||||||||||||||
| 710 | qDebug() << q_func() << ": end microstep"; | - | ||||||||||||||||||
| 711 | #endif | - | ||||||||||||||||||
| 712 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | /* The function as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 715 | - | |||||||||||||||||||
| 716 | procedure computeExitSet(enabledTransitions) | - | ||||||||||||||||||
| 717 | - | |||||||||||||||||||
| 718 | For each transition t in enabledTransitions, if t is targetless then do nothing, else compute the | - | ||||||||||||||||||
| 719 | transition's domain. (This will be the source state in the case of internal transitions) or the | - | ||||||||||||||||||
| 720 | least common compound ancestor state of the source state and target states of t (in the case of | - | ||||||||||||||||||
| 721 | external transitions. Add to the statesToExit set all states in the configuration that are | - | ||||||||||||||||||
| 722 | descendants of the domain. | - | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | function computeExitSet(transitions) | - | ||||||||||||||||||
| 725 | statesToExit = new OrderedSet | - | ||||||||||||||||||
| 726 | for t in transitions: | - | ||||||||||||||||||
| 727 | if (t.target): | - | ||||||||||||||||||
| 728 | domain = getTransitionDomain(t) | - | ||||||||||||||||||
| 729 | for s in configuration: | - | ||||||||||||||||||
| 730 | if isDescendant(s,domain): | - | ||||||||||||||||||
| 731 | statesToExit.add(s) | - | ||||||||||||||||||
| 732 | return statesToExit | - | ||||||||||||||||||
| 733 | */ | - | ||||||||||||||||||
| 734 | QList<QAbstractState*> QStateMachinePrivate::computeExitSet(const QList<QAbstractTransition*> &enabledTransitions, | - | ||||||||||||||||||
| 735 | CalculationCache *cache) | - | ||||||||||||||||||
| 736 | { | - | ||||||||||||||||||
| 737 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | QList<QAbstractState*> statesToExit_sorted = computeExitSet_Unordered(enabledTransitions, cache).toList(); | - | ||||||||||||||||||
| 740 | std::sort(statesToExit_sorted.begin(), statesToExit_sorted.end(), stateExitLessThan); | - | ||||||||||||||||||
| 741 | return statesToExit_sorted; executed 1235 times by 2 tests: return statesToExit_sorted;Executed by:
| 1235 | ||||||||||||||||||
| 742 | } | - | ||||||||||||||||||
| 743 | - | |||||||||||||||||||
| 744 | QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(const QList<QAbstractTransition*> &enabledTransitions, | - | ||||||||||||||||||
| 745 | CalculationCache *cache) | - | ||||||||||||||||||
| 746 | { | - | ||||||||||||||||||
| 747 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 748 | - | |||||||||||||||||||
| 749 | QSet<QAbstractState*> statesToExit; | - | ||||||||||||||||||
| 750 | foreach (QAbstractTransition *t, enabledTransitions) | - | ||||||||||||||||||
| 751 | statesToExit.unite(computeExitSet_Unordered(t, cache)); executed 1238 times by 2 tests: statesToExit.unite(computeExitSet_Unordered(t, cache));Executed by:
| 1238 | ||||||||||||||||||
| 752 | return statesToExit; executed 1235 times by 2 tests: return statesToExit;Executed by:
| 1235 | ||||||||||||||||||
| 753 | } | - | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | QSet<QAbstractState*> QStateMachinePrivate::computeExitSet_Unordered(QAbstractTransition *t, | - | ||||||||||||||||||
| 756 | CalculationCache *cache) | - | ||||||||||||||||||
| 757 | { | - | ||||||||||||||||||
| 758 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | QSet<QAbstractState*> statesToExit; | - | ||||||||||||||||||
| 761 | if (cache->exitSet(t, &statesToExit))
| 19-1241 | ||||||||||||||||||
| 762 | return statesToExit; executed 19 times by 1 test: return statesToExit;Executed by:
| 19 | ||||||||||||||||||
| 763 | - | |||||||||||||||||||
| 764 | QList<QAbstractState *> effectiveTargetStates = getEffectiveTargetStates(t, cache); | - | ||||||||||||||||||
| 765 | QAbstractState *domain = getTransitionDomain(t, effectiveTargetStates, cache); | - | ||||||||||||||||||
| 766 | if (domain == Q_NULLPTR && !t->targetStates().isEmpty()) {
| 4-1232 | ||||||||||||||||||
| 767 | // So we didn't find the least common ancestor for the source and target states of the | - | ||||||||||||||||||
| 768 | // transition. If there were not target states, that would be fine: then the transition | - | ||||||||||||||||||
| 769 | // will fire any events or signals, but not exit the state. | - | ||||||||||||||||||
| 770 | // | - | ||||||||||||||||||
| 771 | // However, there are target states, so it's either a node without a parent (or parent's | - | ||||||||||||||||||
| 772 | // parent, etc), or the state belongs to a different state machine. Either way, this | - | ||||||||||||||||||
| 773 | // makes the state machine invalid. | - | ||||||||||||||||||
| 774 | if (error == QStateMachine::NoError)
| 1-3 | ||||||||||||||||||
| 775 | setError(QStateMachine::NoCommonAncestorForTransitionError, t->sourceState()); executed 3 times by 1 test: setError(QStateMachine::NoCommonAncestorForTransitionError, t->sourceState());Executed by:
| 3 | ||||||||||||||||||
| 776 | QList<QAbstractState *> lst = pendingErrorStates.toList(); | - | ||||||||||||||||||
| 777 | lst.prepend(t->sourceState()); | - | ||||||||||||||||||
| 778 | - | |||||||||||||||||||
| 779 | domain = findLCCA(lst); | - | ||||||||||||||||||
| 780 | Q_ASSERT(domain != 0); | - | ||||||||||||||||||
| 781 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | foreach (QAbstractState* s, configuration) { | - | ||||||||||||||||||
| 784 | if (isDescendant(s, domain))
| 104-1315 | ||||||||||||||||||
| 785 | statesToExit.insert(s); executed 1315 times by 2 tests: statesToExit.insert(s);Executed by:
| 1315 | ||||||||||||||||||
| 786 | } executed 1419 times by 2 tests: end of blockExecuted by:
| 1419 | ||||||||||||||||||
| 787 | - | |||||||||||||||||||
| 788 | cache->insert(t, statesToExit); | - | ||||||||||||||||||
| 789 | return statesToExit; executed 1241 times by 2 tests: return statesToExit;Executed by:
| 1241 | ||||||||||||||||||
| 790 | } | - | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | void QStateMachinePrivate::exitStates(QEvent *event, const QList<QAbstractState*> &statesToExit_sorted, | - | ||||||||||||||||||
| 793 | const QHash<QAbstractState*, QVector<QPropertyAssignment> > &assignmentsForEnteredStates) | - | ||||||||||||||||||
| 794 | { | - | ||||||||||||||||||
| 795 | for (int i = 0; i < statesToExit_sorted.size(); ++i) {
| 1235-1298 | ||||||||||||||||||
| 796 | QAbstractState *s = statesToExit_sorted.at(i); | - | ||||||||||||||||||
| 797 | if (QState *grp = toStandardState(s)) {
| 7-1291 | ||||||||||||||||||
| 798 | QList<QHistoryState*> hlst = QStatePrivate::get(grp)->historyStates(); | - | ||||||||||||||||||
| 799 | for (int j = 0; j < hlst.size(); ++j) {
| 9-1291 | ||||||||||||||||||
| 800 | QHistoryState *h = hlst.at(j); | - | ||||||||||||||||||
| 801 | QHistoryStatePrivate::get(h)->configuration.clear(); | - | ||||||||||||||||||
| 802 | QSet<QAbstractState*>::const_iterator it; | - | ||||||||||||||||||
| 803 | for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
| 9-27 | ||||||||||||||||||
| 804 | QAbstractState *s0 = *it; | - | ||||||||||||||||||
| 805 | if (QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) {
| 11-16 | ||||||||||||||||||
| 806 | if (isAtomic(s0) && isDescendant(s0, s))
| 0-6 | ||||||||||||||||||
| 807 | QHistoryStatePrivate::get(h)->configuration.append(s0); executed 5 times by 1 test: QHistoryStatePrivate::get(h)->configuration.append(s0);Executed by:
| 5 | ||||||||||||||||||
| 808 | } else if (s0->parentState() == s) { executed 11 times by 1 test: end of blockExecuted by:
| 8-11 | ||||||||||||||||||
| 809 | QHistoryStatePrivate::get(h)->configuration.append(s0); | - | ||||||||||||||||||
| 810 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 811 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 812 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 813 | qDebug() << q_func() << ": recorded" << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow") | - | ||||||||||||||||||
| 814 | << "history for" << s << "in" << h << ':' << QHistoryStatePrivate::get(h)->configuration; | - | ||||||||||||||||||
| 815 | #endif | - | ||||||||||||||||||
| 816 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 817 | } executed 1291 times by 2 tests: end of blockExecuted by:
| 1291 | ||||||||||||||||||
| 818 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 819 | for (int i = 0; i < statesToExit_sorted.size(); ++i) {
| 1235-1298 | ||||||||||||||||||
| 820 | QAbstractState *s = statesToExit_sorted.at(i); | - | ||||||||||||||||||
| 821 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 822 | qDebug() << q_func() << ": exiting" << s; | - | ||||||||||||||||||
| 823 | #endif | - | ||||||||||||||||||
| 824 | QAbstractStatePrivate::get(s)->callOnExit(event); | - | ||||||||||||||||||
| 825 | - | |||||||||||||||||||
| 826 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 827 | terminateActiveAnimations(s, assignmentsForEnteredStates); | - | ||||||||||||||||||
| 828 | #else | - | ||||||||||||||||||
| 829 | Q_UNUSED(assignmentsForEnteredStates); | - | ||||||||||||||||||
| 830 | #endif | - | ||||||||||||||||||
| 831 | - | |||||||||||||||||||
| 832 | configuration.remove(s); | - | ||||||||||||||||||
| 833 | QAbstractStatePrivate::get(s)->emitExited(); | - | ||||||||||||||||||
| 834 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 835 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | void QStateMachinePrivate::executeTransitionContent(QEvent *event, const QList<QAbstractTransition*> &enabledTransitions) | - | ||||||||||||||||||
| 838 | { | - | ||||||||||||||||||
| 839 | for (int i = 0; i < enabledTransitions.size(); ++i) {
| 1388-1391 | ||||||||||||||||||
| 840 | QAbstractTransition *t = enabledTransitions.at(i); | - | ||||||||||||||||||
| 841 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 842 | qDebug() << q_func() << ": triggering" << t; | - | ||||||||||||||||||
| 843 | #endif | - | ||||||||||||||||||
| 844 | QAbstractTransitionPrivate::get(t)->callOnTransition(event); | - | ||||||||||||||||||
| 845 | QAbstractTransitionPrivate::get(t)->emitTriggered(); | - | ||||||||||||||||||
| 846 | } executed 1391 times by 2 tests: end of blockExecuted by:
| 1391 | ||||||||||||||||||
| 847 | } executed 1388 times by 2 tests: end of blockExecuted by:
| 1388 | ||||||||||||||||||
| 848 | - | |||||||||||||||||||
| 849 | QList<QAbstractState*> QStateMachinePrivate::computeEntrySet(const QList<QAbstractTransition *> &enabledTransitions, | - | ||||||||||||||||||
| 850 | QSet<QAbstractState *> &statesForDefaultEntry, | - | ||||||||||||||||||
| 851 | CalculationCache *cache) | - | ||||||||||||||||||
| 852 | { | - | ||||||||||||||||||
| 853 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | QSet<QAbstractState*> statesToEnter; | - | ||||||||||||||||||
| 856 | if (pendingErrorStates.isEmpty()) {
| 1-1387 | ||||||||||||||||||
| 857 | foreach (QAbstractTransition *t, enabledTransitions) { | - | ||||||||||||||||||
| 858 | foreach (QAbstractState *s, t->targetStates()) { | - | ||||||||||||||||||
| 859 | addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); | - | ||||||||||||||||||
| 860 | } executed 1386 times by 2 tests: end of blockExecuted by:
| 1386 | ||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | QList<QAbstractState *> effectiveTargetStates = getEffectiveTargetStates(t, cache); | - | ||||||||||||||||||
| 863 | QAbstractState *ancestor = getTransitionDomain(t, effectiveTargetStates, cache); | - | ||||||||||||||||||
| 864 | foreach (QAbstractState *s, effectiveTargetStates) { | - | ||||||||||||||||||
| 865 | addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry); | - | ||||||||||||||||||
| 866 | } executed 1390 times by 2 tests: end of blockExecuted by:
| 1390 | ||||||||||||||||||
| 867 | } executed 1390 times by 2 tests: end of blockExecuted by:
| 1390 | ||||||||||||||||||
| 868 | } executed 1387 times by 2 tests: end of blockExecuted by:
| 1387 | ||||||||||||||||||
| 869 | - | |||||||||||||||||||
| 870 | // Did an error occur while selecting transitions? Then we enter the error state. | - | ||||||||||||||||||
| 871 | if (!pendingErrorStates.isEmpty()) {
| 9-1379 | ||||||||||||||||||
| 872 | statesToEnter.clear(); | - | ||||||||||||||||||
| 873 | statesToEnter = pendingErrorStates; | - | ||||||||||||||||||
| 874 | statesForDefaultEntry = pendingErrorStatesForDefaultEntry; | - | ||||||||||||||||||
| 875 | pendingErrorStates.clear(); | - | ||||||||||||||||||
| 876 | pendingErrorStatesForDefaultEntry.clear(); | - | ||||||||||||||||||
| 877 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 878 | - | |||||||||||||||||||
| 879 | QList<QAbstractState*> statesToEnter_sorted = statesToEnter.toList(); | - | ||||||||||||||||||
| 880 | std::sort(statesToEnter_sorted.begin(), statesToEnter_sorted.end(), stateEntryLessThan); | - | ||||||||||||||||||
| 881 | return statesToEnter_sorted; executed 1388 times by 2 tests: return statesToEnter_sorted;Executed by:
| 1388 | ||||||||||||||||||
| 882 | } | - | ||||||||||||||||||
| 883 | - | |||||||||||||||||||
| 884 | /* The algorithm as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 885 | - | |||||||||||||||||||
| 886 | function getTransitionDomain(transition) | - | ||||||||||||||||||
| 887 | - | |||||||||||||||||||
| 888 | Return the compound state such that 1) all states that are exited or entered as a result of taking | - | ||||||||||||||||||
| 889 | 'transition' are descendants of it 2) no descendant of it has this property. | - | ||||||||||||||||||
| 890 | - | |||||||||||||||||||
| 891 | function getTransitionDomain(t) | - | ||||||||||||||||||
| 892 | tstates = getEffectiveTargetStates(t) | - | ||||||||||||||||||
| 893 | if not tstates: | - | ||||||||||||||||||
| 894 | return null | - | ||||||||||||||||||
| 895 | elif t.type == "internal" and isCompoundState(t.source) and tstates.every(lambda s: isDescendant(s,t.source)): | - | ||||||||||||||||||
| 896 | return t.source | - | ||||||||||||||||||
| 897 | else: | - | ||||||||||||||||||
| 898 | return findLCCA([t.source].append(tstates)) | - | ||||||||||||||||||
| 899 | */ | - | ||||||||||||||||||
| 900 | QAbstractState *QStateMachinePrivate::getTransitionDomain(QAbstractTransition *t, | - | ||||||||||||||||||
| 901 | const QList<QAbstractState *> &effectiveTargetStates, | - | ||||||||||||||||||
| 902 | CalculationCache *cache) const | - | ||||||||||||||||||
| 903 | { | - | ||||||||||||||||||
| 904 | Q_ASSERT(cache); | - | ||||||||||||||||||
| 905 | - | |||||||||||||||||||
| 906 | if (effectiveTargetStates.isEmpty())
| 11-2620 | ||||||||||||||||||
| 907 | return 0; executed 11 times by 1 test: return 0;Executed by:
| 11 | ||||||||||||||||||
| 908 | - | |||||||||||||||||||
| 909 | QAbstractState *domain = Q_NULLPTR; | - | ||||||||||||||||||
| 910 | if (cache->transitionDomain(t, &domain))
| 1231-1389 | ||||||||||||||||||
| 911 | return domain; executed 1231 times by 2 tests: return domain;Executed by:
| 1231 | ||||||||||||||||||
| 912 | - | |||||||||||||||||||
| 913 | if (t->transitionType() == QAbstractTransition::InternalTransition) {
| 2-1387 | ||||||||||||||||||
| 914 | if (QState *tSource = t->sourceState()) {
| 0-2 | ||||||||||||||||||
| 915 | if (isCompound(tSource)) {
| 0-2 | ||||||||||||||||||
| 916 | bool allDescendants = true; | - | ||||||||||||||||||
| 917 | foreach (QAbstractState *s, effectiveTargetStates) { | - | ||||||||||||||||||
| 918 | if (!isDescendant(s, tSource)) {
| 0-2 | ||||||||||||||||||
| 919 | allDescendants = false; | - | ||||||||||||||||||
| 920 | break; never executed: break; | 0 | ||||||||||||||||||
| 921 | } | - | ||||||||||||||||||
| 922 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 923 | - | |||||||||||||||||||
| 924 | if (allDescendants)
| 0-2 | ||||||||||||||||||
| 925 | return tSource; executed 2 times by 1 test: return tSource;Executed by:
| 2 | ||||||||||||||||||
| 926 | } never executed: end of block | 0 | ||||||||||||||||||
| 927 | } never executed: end of block | 0 | ||||||||||||||||||
| 928 | } never executed: end of block | 0 | ||||||||||||||||||
| 929 | - | |||||||||||||||||||
| 930 | QList<QAbstractState *> states(effectiveTargetStates); | - | ||||||||||||||||||
| 931 | if (QAbstractState *src = t->sourceState())
| 153-1234 | ||||||||||||||||||
| 932 | states.prepend(src); executed 1234 times by 2 tests: states.prepend(src);Executed by:
| 1234 | ||||||||||||||||||
| 933 | domain = findLCCA(states); | - | ||||||||||||||||||
| 934 | cache->insert(t, domain); | - | ||||||||||||||||||
| 935 | return domain; executed 1387 times by 2 tests: return domain;Executed by:
| 1387 | ||||||||||||||||||
| 936 | } | - | ||||||||||||||||||
| 937 | - | |||||||||||||||||||
| 938 | void QStateMachinePrivate::enterStates(QEvent *event, const QList<QAbstractState*> &exitedStates_sorted, | - | ||||||||||||||||||
| 939 | const QList<QAbstractState*> &statesToEnter_sorted, | - | ||||||||||||||||||
| 940 | const QSet<QAbstractState*> &statesForDefaultEntry, | - | ||||||||||||||||||
| 941 | QHash<QAbstractState*, QVector<QPropertyAssignment> > &propertyAssignmentsForState | - | ||||||||||||||||||
| 942 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 943 | , const QList<QAbstractAnimation *> &selectedAnimations | - | ||||||||||||||||||
| 944 | #endif | - | ||||||||||||||||||
| 945 | ) | - | ||||||||||||||||||
| 946 | { | - | ||||||||||||||||||
| 947 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 948 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 949 | #endif | - | ||||||||||||||||||
| 950 | for (int i = 0; i < statesToEnter_sorted.size(); ++i) {
| 1388-1507 | ||||||||||||||||||
| 951 | QAbstractState *s = statesToEnter_sorted.at(i); | - | ||||||||||||||||||
| 952 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 953 | qDebug() << q << ": entering" << s; | - | ||||||||||||||||||
| 954 | #endif | - | ||||||||||||||||||
| 955 | configuration.insert(s); | - | ||||||||||||||||||
| 956 | registerTransitions(s); | - | ||||||||||||||||||
| 957 | - | |||||||||||||||||||
| 958 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 959 | initializeAnimations(s, selectedAnimations, exitedStates_sorted, propertyAssignmentsForState); | - | ||||||||||||||||||
| 960 | #endif | - | ||||||||||||||||||
| 961 | - | |||||||||||||||||||
| 962 | // Immediately set the properties that are not animated. | - | ||||||||||||||||||
| 963 | { | - | ||||||||||||||||||
| 964 | QVector<QPropertyAssignment> assignments = propertyAssignmentsForState.value(s); | - | ||||||||||||||||||
| 965 | for (int i = 0; i < assignments.size(); ++i) {
| 97-1507 | ||||||||||||||||||
| 966 | const QPropertyAssignment &assn = assignments.at(i); | - | ||||||||||||||||||
| 967 | if (globalRestorePolicy == QState::RestoreProperties) {
| 43-54 | ||||||||||||||||||
| 968 | if (assn.explicitlySet) {
| 18-36 | ||||||||||||||||||
| 969 | if (!hasRestorable(s, assn.object, assn.propertyName)) {
| 2-34 | ||||||||||||||||||
| 970 | QVariant value = savedValueForRestorable(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 971 | unregisterRestorables(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 972 | registerRestorable(s, assn.object, assn.propertyName, value); | - | ||||||||||||||||||
| 973 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 974 | } else { executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 975 | // The property is being restored, hence no need to | - | ||||||||||||||||||
| 976 | // save the current value. Discard any saved values in | - | ||||||||||||||||||
| 977 | // exited states, since those are now stale. | - | ||||||||||||||||||
| 978 | unregisterRestorables(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 979 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 980 | } | - | ||||||||||||||||||
| 981 | assn.write(); | - | ||||||||||||||||||
| 982 | } executed 97 times by 2 tests: end of blockExecuted by:
| 97 | ||||||||||||||||||
| 983 | } | - | ||||||||||||||||||
| 984 | - | |||||||||||||||||||
| 985 | QAbstractStatePrivate::get(s)->callOnEntry(event); | - | ||||||||||||||||||
| 986 | QAbstractStatePrivate::get(s)->emitEntered(); | - | ||||||||||||||||||
| 987 | - | |||||||||||||||||||
| 988 | // FIXME: | - | ||||||||||||||||||
| 989 | // See the "initial transitions" comment in addDescendantStatesToEnter first, then implement: | - | ||||||||||||||||||
| 990 | // if (statesForDefaultEntry.contains(s)) { | - | ||||||||||||||||||
| 991 | // // ### executeContent(s.initial.transition.children()) | - | ||||||||||||||||||
| 992 | // } | - | ||||||||||||||||||
| 993 | Q_UNUSED(statesForDefaultEntry); | - | ||||||||||||||||||
| 994 | - | |||||||||||||||||||
| 995 | if (QHistoryState *h = toHistoryState(s))
| 0-1507 | ||||||||||||||||||
| 996 | QAbstractTransitionPrivate::get(h->defaultTransition())->callOnTransition(event); never executed: QAbstractTransitionPrivate::get(h->defaultTransition())->callOnTransition(event); | 0 | ||||||||||||||||||
| 997 | - | |||||||||||||||||||
| 998 | // Emit propertiesAssigned signal if the state has no animated properties. | - | ||||||||||||||||||
| 999 | { | - | ||||||||||||||||||
| 1000 | QState *ss = toStandardState(s); | - | ||||||||||||||||||
| 1001 | if (ss
| 72-1435 | ||||||||||||||||||
| 1002 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1003 | && !animationsForState.contains(s)
| 32-1403 | ||||||||||||||||||
| 1004 | #endif | - | ||||||||||||||||||
| 1005 | ) | - | ||||||||||||||||||
| 1006 | QStatePrivate::get(ss)->emitPropertiesAssigned(); executed 1403 times by 2 tests: QStatePrivate::get(ss)->emitPropertiesAssigned();Executed by:
| 1403 | ||||||||||||||||||
| 1007 | } | - | ||||||||||||||||||
| 1008 | - | |||||||||||||||||||
| 1009 | if (isFinal(s)) {
| 72-1435 | ||||||||||||||||||
| 1010 | QState *parent = s->parentState(); | - | ||||||||||||||||||
| 1011 | if (parent) {
| 0-72 | ||||||||||||||||||
| 1012 | if (parent != rootState()) {
| 9-63 | ||||||||||||||||||
| 1013 | QFinalState *finalState = qobject_cast<QFinalState *>(s); | - | ||||||||||||||||||
| 1014 | Q_ASSERT(finalState); | - | ||||||||||||||||||
| 1015 | emitStateFinished(parent, finalState); | - | ||||||||||||||||||
| 1016 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 1017 | QState *grandparent = parent->parentState(); | - | ||||||||||||||||||
| 1018 | if (grandparent && isParallel(grandparent)) {
| 5-60 | ||||||||||||||||||
| 1019 | bool allChildStatesFinal = true; | - | ||||||||||||||||||
| 1020 | QList<QAbstractState*> childStates = QStatePrivate::get(grandparent)->childStates(); | - | ||||||||||||||||||
| 1021 | for (int j = 0; j < childStates.size(); ++j) {
| 3-16 | ||||||||||||||||||
| 1022 | QAbstractState *cs = childStates.at(j); | - | ||||||||||||||||||
| 1023 | if (!isInFinalState(cs)) {
| 4-12 | ||||||||||||||||||
| 1024 | allChildStatesFinal = false; | - | ||||||||||||||||||
| 1025 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 1026 | } | - | ||||||||||||||||||
| 1027 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1028 | if (allChildStatesFinal && (grandparent != rootState())) {
| 1-4 | ||||||||||||||||||
| 1029 | QFinalState *finalState = qobject_cast<QFinalState *>(s); | - | ||||||||||||||||||
| 1030 | Q_ASSERT(finalState); | - | ||||||||||||||||||
| 1031 | emitStateFinished(grandparent, finalState); | - | ||||||||||||||||||
| 1032 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1033 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 1034 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 1035 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||
| 1036 | } executed 1507 times by 2 tests: end of blockExecuted by:
| 1507 | ||||||||||||||||||
| 1037 | { | - | ||||||||||||||||||
| 1038 | QSet<QAbstractState*>::const_iterator it; | - | ||||||||||||||||||
| 1039 | for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
| 1324-1591 | ||||||||||||||||||
| 1040 | if (isFinal(*it)) {
| 74-1517 | ||||||||||||||||||
| 1041 | QState *parent = (*it)->parentState(); | - | ||||||||||||||||||
| 1042 | if (((parent == rootState())
| 11-63 | ||||||||||||||||||
| 1043 | && (rootState()->childMode() == QState::ExclusiveStates))
| 0-63 | ||||||||||||||||||
| 1044 | || ((parent->parentState() == rootState())
| 3-8 | ||||||||||||||||||
| 1045 | && (rootState()->childMode() == QState::ParallelStates)
| 1-2 | ||||||||||||||||||
| 1046 | && isInFinalState(rootState()))) {
| 0-1 | ||||||||||||||||||
| 1047 | processing = false; | - | ||||||||||||||||||
| 1048 | stopProcessingReason = Finished; | - | ||||||||||||||||||
| 1049 | break; executed 64 times by 1 test: break;Executed by:
| 64 | ||||||||||||||||||
| 1050 | } | - | ||||||||||||||||||
| 1051 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1052 | } executed 1527 times by 2 tests: end of blockExecuted by:
| 1527 | ||||||||||||||||||
| 1053 | } | - | ||||||||||||||||||
| 1054 | // qDebug() << "configuration:" << configuration.toList(); | - | ||||||||||||||||||
| 1055 | } executed 1388 times by 2 tests: end of blockExecuted by:
| 1388 | ||||||||||||||||||
| 1056 | - | |||||||||||||||||||
| 1057 | /* The algorithm as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ has a bug. See | - | ||||||||||||||||||
| 1058 | * QTBUG-44963 for details. The algorithm here is as described in | - | ||||||||||||||||||
| 1059 | * http://www.w3.org/Voice/2013/scxml-irp/SCXML.htm as of Friday March 13, 2015. | - | ||||||||||||||||||
| 1060 | - | |||||||||||||||||||
| 1061 | procedure addDescendantStatesToEnter(state,statesToEnter,statesForDefaultEntry, defaultHistoryContent): | - | ||||||||||||||||||
| 1062 | if isHistoryState(state): | - | ||||||||||||||||||
| 1063 | if historyValue[state.id]: | - | ||||||||||||||||||
| 1064 | for s in historyValue[state.id]: | - | ||||||||||||||||||
| 1065 | addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1066 | for s in historyValue[state.id]: | - | ||||||||||||||||||
| 1067 | addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1068 | else: | - | ||||||||||||||||||
| 1069 | defaultHistoryContent[state.parent.id] = state.transition.content | - | ||||||||||||||||||
| 1070 | for s in state.transition.target: | - | ||||||||||||||||||
| 1071 | addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1072 | for s in state.transition.target: | - | ||||||||||||||||||
| 1073 | addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1074 | else: | - | ||||||||||||||||||
| 1075 | statesToEnter.add(state) | - | ||||||||||||||||||
| 1076 | if isCompoundState(state): | - | ||||||||||||||||||
| 1077 | statesForDefaultEntry.add(state) | - | ||||||||||||||||||
| 1078 | for s in state.initial.transition.target: | - | ||||||||||||||||||
| 1079 | addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1080 | for s in state.initial.transition.target: | - | ||||||||||||||||||
| 1081 | addAncestorStatesToEnter(s, state, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1082 | else: | - | ||||||||||||||||||
| 1083 | if isParallelState(state): | - | ||||||||||||||||||
| 1084 | for child in getChildStates(state): | - | ||||||||||||||||||
| 1085 | if not statesToEnter.some(lambda s: isDescendant(s,child)): | - | ||||||||||||||||||
| 1086 | addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1087 | */ | - | ||||||||||||||||||
| 1088 | void QStateMachinePrivate::addDescendantStatesToEnter(QAbstractState *state, | - | ||||||||||||||||||
| 1089 | QSet<QAbstractState*> &statesToEnter, | - | ||||||||||||||||||
| 1090 | QSet<QAbstractState*> &statesForDefaultEntry) | - | ||||||||||||||||||
| 1091 | { | - | ||||||||||||||||||
| 1092 | if (QHistoryState *h = toHistoryState(state)) {
| 13-1506 | ||||||||||||||||||
| 1093 | QList<QAbstractState*> historyConfiguration = QHistoryStatePrivate::get(h)->configuration; | - | ||||||||||||||||||
| 1094 | if (!historyConfiguration.isEmpty()) {
| 6-7 | ||||||||||||||||||
| 1095 | foreach (QAbstractState *s, historyConfiguration) | - | ||||||||||||||||||
| 1096 | addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); executed 11 times by 2 tests: addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);Executed by:
| 11 | ||||||||||||||||||
| 1097 | foreach (QAbstractState *s, historyConfiguration) | - | ||||||||||||||||||
| 1098 | addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry); executed 11 times by 2 tests: addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry);Executed by:
| 11 | ||||||||||||||||||
| 1099 | - | |||||||||||||||||||
| 1100 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1101 | qDebug() << q_func() << ": restoring" | - | ||||||||||||||||||
| 1102 | << ((QHistoryStatePrivate::get(h)->historyType == QHistoryState::DeepHistory) ? "deep" : "shallow") | - | ||||||||||||||||||
| 1103 | << "history from" << state << ':' << historyConfiguration; | - | ||||||||||||||||||
| 1104 | #endif | - | ||||||||||||||||||
| 1105 | } else { executed 7 times by 2 tests: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 1106 | QList<QAbstractState*> defaultHistoryContent; | - | ||||||||||||||||||
| 1107 | if (QAbstractTransition *t = QHistoryStatePrivate::get(h)->defaultTransition)
| 0-6 | ||||||||||||||||||
| 1108 | defaultHistoryContent = t->targetStates(); executed 6 times by 2 tests: defaultHistoryContent = t->targetStates();Executed by:
| 6 | ||||||||||||||||||
| 1109 | - | |||||||||||||||||||
| 1110 | if (defaultHistoryContent.isEmpty()) {
| 0-6 | ||||||||||||||||||
| 1111 | setError(QStateMachine::NoDefaultStateInHistoryStateError, h); | - | ||||||||||||||||||
| 1112 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1113 | foreach (QAbstractState *s, defaultHistoryContent) | - | ||||||||||||||||||
| 1114 | addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry); executed 7 times by 2 tests: addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry);Executed by:
| 7 | ||||||||||||||||||
| 1115 | foreach (QAbstractState *s, defaultHistoryContent) | - | ||||||||||||||||||
| 1116 | addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry); executed 7 times by 2 tests: addAncestorStatesToEnter(s, state->parentState(), statesToEnter, statesForDefaultEntry);Executed by:
| 7 | ||||||||||||||||||
| 1117 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1118 | qDebug() << q_func() << ": initial history targets for" << state << ':' << defaultHistoryContent; | - | ||||||||||||||||||
| 1119 | #endif | - | ||||||||||||||||||
| 1120 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 1121 | } | - | ||||||||||||||||||
| 1122 | } else { | - | ||||||||||||||||||
| 1123 | if (state == rootState()) {
| 1-1505 | ||||||||||||||||||
| 1124 | // Error has already been set by exitStates(). | - | ||||||||||||||||||
| 1125 | Q_ASSERT(error != QStateMachine::NoError); | - | ||||||||||||||||||
| 1126 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 1127 | } | - | ||||||||||||||||||
| 1128 | statesToEnter.insert(state); | - | ||||||||||||||||||
| 1129 | if (isCompound(state)) {
| 65-1440 | ||||||||||||||||||
| 1130 | statesForDefaultEntry.insert(state); | - | ||||||||||||||||||
| 1131 | if (QAbstractState *initial = toStandardState(state)->initialState()) {
| 16-49 | ||||||||||||||||||
| 1132 | Q_ASSERT(initial->machine() == q_func()); | - | ||||||||||||||||||
| 1133 | - | |||||||||||||||||||
| 1134 | // FIXME: | - | ||||||||||||||||||
| 1135 | // Qt does not support initial transitions (which is a problem for parallel states). | - | ||||||||||||||||||
| 1136 | // The way it simulates this for other states, is by having a single initial state. | - | ||||||||||||||||||
| 1137 | // See also the FIXME in enterStates. | - | ||||||||||||||||||
| 1138 | statesForDefaultEntry.insert(initial); | - | ||||||||||||||||||
| 1139 | - | |||||||||||||||||||
| 1140 | addDescendantStatesToEnter(initial, statesToEnter, statesForDefaultEntry); | - | ||||||||||||||||||
| 1141 | addAncestorStatesToEnter(initial, state, statesToEnter, statesForDefaultEntry); | - | ||||||||||||||||||
| 1142 | } else { executed 49 times by 2 tests: end of blockExecuted by:
| 49 | ||||||||||||||||||
| 1143 | setError(QStateMachine::NoInitialStateError, state); | - | ||||||||||||||||||
| 1144 | return; executed 16 times by 1 test: return;Executed by:
| 16 | ||||||||||||||||||
| 1145 | } | - | ||||||||||||||||||
| 1146 | } else if (isParallel(state)) {
| 15-1425 | ||||||||||||||||||
| 1147 | QState *grp = toStandardState(state); | - | ||||||||||||||||||
| 1148 | foreach (QAbstractState *child, QStatePrivate::get(grp)->childStates()) { | - | ||||||||||||||||||
| 1149 | if (!containsDecendantOf(statesToEnter, child))
| 0-29 | ||||||||||||||||||
| 1150 | addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry); executed 29 times by 1 test: addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry);Executed by:
| 29 | ||||||||||||||||||
| 1151 | } executed 29 times by 1 test: end of blockExecuted by:
| 29 | ||||||||||||||||||
| 1152 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 1153 | } executed 1489 times by 2 tests: end of blockExecuted by:
| 1489 | ||||||||||||||||||
| 1154 | } | - | ||||||||||||||||||
| 1155 | - | |||||||||||||||||||
| 1156 | - | |||||||||||||||||||
| 1157 | /* The algorithm as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ : | - | ||||||||||||||||||
| 1158 | - | |||||||||||||||||||
| 1159 | procedure addAncestorStatesToEnter(state, ancestor, statesToEnter, statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1160 | for anc in getProperAncestors(state,ancestor): | - | ||||||||||||||||||
| 1161 | statesToEnter.add(anc) | - | ||||||||||||||||||
| 1162 | if isParallelState(anc): | - | ||||||||||||||||||
| 1163 | for child in getChildStates(anc): | - | ||||||||||||||||||
| 1164 | if not statesToEnter.some(lambda s: isDescendant(s,child)): | - | ||||||||||||||||||
| 1165 | addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent) | - | ||||||||||||||||||
| 1166 | */ | - | ||||||||||||||||||
| 1167 | void QStateMachinePrivate::addAncestorStatesToEnter(QAbstractState *s, QAbstractState *ancestor, | - | ||||||||||||||||||
| 1168 | QSet<QAbstractState*> &statesToEnter, | - | ||||||||||||||||||
| 1169 | QSet<QAbstractState*> &statesForDefaultEntry) | - | ||||||||||||||||||
| 1170 | { | - | ||||||||||||||||||
| 1171 | foreach (QState *anc, getProperAncestors(s, ancestor)) { | - | ||||||||||||||||||
| 1172 | if (!anc->parentState())
| 2-66 | ||||||||||||||||||
| 1173 | continue; executed 2 times by 1 test: continue;Executed by:
| 2 | ||||||||||||||||||
| 1174 | statesToEnter.insert(anc); | - | ||||||||||||||||||
| 1175 | if (isParallel(anc)) {
| 31-35 | ||||||||||||||||||
| 1176 | foreach (QAbstractState *child, QStatePrivate::get(anc)->childStates()) { | - | ||||||||||||||||||
| 1177 | if (!containsDecendantOf(statesToEnter, child))
| 27-36 | ||||||||||||||||||
| 1178 | addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry); executed 27 times by 1 test: addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry);Executed by:
| 27 | ||||||||||||||||||
| 1179 | } executed 63 times by 1 test: end of blockExecuted by:
| 63 | ||||||||||||||||||
| 1180 | } executed 35 times by 1 test: end of blockExecuted by:
| 35 | ||||||||||||||||||
| 1181 | } executed 66 times by 1 test: end of blockExecuted by:
| 66 | ||||||||||||||||||
| 1182 | } executed 1467 times by 2 tests: end of blockExecuted by:
| 1467 | ||||||||||||||||||
| 1183 | - | |||||||||||||||||||
| 1184 | bool QStateMachinePrivate::isFinal(const QAbstractState *s) | - | ||||||||||||||||||
| 1185 | { | - | ||||||||||||||||||
| 1186 | return s && (QAbstractStatePrivate::get(s)->stateType == QAbstractStatePrivate::FinalState); executed 3561 times by 2 tests: return s && (QAbstractStatePrivate::get(s)->stateType == QAbstractStatePrivate::FinalState);Executed by:
| 0-3561 | ||||||||||||||||||
| 1187 | } | - | ||||||||||||||||||
| 1188 | - | |||||||||||||||||||
| 1189 | bool QStateMachinePrivate::isParallel(const QAbstractState *s) | - | ||||||||||||||||||
| 1190 | { | - | ||||||||||||||||||
| 1191 | const QState *ss = toStandardState(s); | - | ||||||||||||||||||
| 1192 | return ss && (QStatePrivate::get(ss)->childMode == QState::ParallelStates); executed 4385 times by 2 tests: return ss && (QStatePrivate::get(ss)->childMode == QState::ParallelStates);Executed by:
| 72-4385 | ||||||||||||||||||
| 1193 | } | - | ||||||||||||||||||
| 1194 | - | |||||||||||||||||||
| 1195 | bool QStateMachinePrivate::isCompound(const QAbstractState *s) const | - | ||||||||||||||||||
| 1196 | { | - | ||||||||||||||||||
| 1197 | const QState *group = toStandardState(s); | - | ||||||||||||||||||
| 1198 | if (!group)
| 72-2869 | ||||||||||||||||||
| 1199 | return false; executed 72 times by 1 test: return false;Executed by:
| 72 | ||||||||||||||||||
| 1200 | bool isMachine = QStatePrivate::get(group)->isMachine; | - | ||||||||||||||||||
| 1201 | // Don't treat the machine as compound if it's a sub-state of this machine | - | ||||||||||||||||||
| 1202 | if (isMachine && (group != rootState()))
| 3-1517 | ||||||||||||||||||
| 1203 | return false; executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||
| 1204 | return (!isParallel(group) && !QStatePrivate::get(group)->childStates().isEmpty()); executed 2866 times by 2 tests: return (!isParallel(group) && !QStatePrivate::get(group)->childStates().isEmpty());Executed by:
| 28-2866 | ||||||||||||||||||
| 1205 | } | - | ||||||||||||||||||
| 1206 | - | |||||||||||||||||||
| 1207 | bool QStateMachinePrivate::isAtomic(const QAbstractState *s) const | - | ||||||||||||||||||
| 1208 | { | - | ||||||||||||||||||
| 1209 | const QState *ss = toStandardState(s); | - | ||||||||||||||||||
| 1210 | 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:
| 23-4235 | ||||||||||||||||||
| 1211 | || 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:
| 23-4235 | ||||||||||||||||||
| 1212 | // 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 | ||||||||||||||||||
| 1213 | || (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:
| 0-4235 | ||||||||||||||||||
| 1214 | } | - | ||||||||||||||||||
| 1215 | - | |||||||||||||||||||
| 1216 | QState *QStateMachinePrivate::toStandardState(QAbstractState *state) | - | ||||||||||||||||||
| 1217 | { | - | ||||||||||||||||||
| 1218 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::StandardState))
| 0-9813 | ||||||||||||||||||
| 1219 | return static_cast<QState*>(state); executed 9566 times by 2 tests: return static_cast<QState*>(state);Executed by:
| 9566 | ||||||||||||||||||
| 1220 | return 0; executed 247 times by 1 test: return 0;Executed by:
| 247 | ||||||||||||||||||
| 1221 | } | - | ||||||||||||||||||
| 1222 | - | |||||||||||||||||||
| 1223 | const QState *QStateMachinePrivate::toStandardState(const QAbstractState *state) | - | ||||||||||||||||||
| 1224 | { | - | ||||||||||||||||||
| 1225 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::StandardState))
| 0-11561 | ||||||||||||||||||
| 1226 | return static_cast<const QState*>(state); executed 11394 times by 2 tests: return static_cast<const QState*>(state);Executed by:
| 11394 | ||||||||||||||||||
| 1227 | return 0; executed 167 times by 1 test: return 0;Executed by:
| 167 | ||||||||||||||||||
| 1228 | } | - | ||||||||||||||||||
| 1229 | - | |||||||||||||||||||
| 1230 | QFinalState *QStateMachinePrivate::toFinalState(QAbstractState *state) | - | ||||||||||||||||||
| 1231 | { | - | ||||||||||||||||||
| 1232 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::FinalState))
| 0 | ||||||||||||||||||
| 1233 | return static_cast<QFinalState*>(state); never executed: return static_cast<QFinalState*>(state); | 0 | ||||||||||||||||||
| 1234 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1235 | } | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | QHistoryState *QStateMachinePrivate::toHistoryState(QAbstractState *state) | - | ||||||||||||||||||
| 1238 | { | - | ||||||||||||||||||
| 1239 | if (state && (QAbstractStatePrivate::get(state)->stateType == QAbstractStatePrivate::HistoryState))
| 0-4416 | ||||||||||||||||||
| 1240 | return static_cast<QHistoryState*>(state); executed 22 times by 2 tests: return static_cast<QHistoryState*>(state);Executed by:
| 22 | ||||||||||||||||||
| 1241 | return 0; executed 4394 times by 2 tests: return 0;Executed by:
| 4394 | ||||||||||||||||||
| 1242 | } | - | ||||||||||||||||||
| 1243 | - | |||||||||||||||||||
| 1244 | bool QStateMachinePrivate::isInFinalState(QAbstractState* s) const | - | ||||||||||||||||||
| 1245 | { | - | ||||||||||||||||||
| 1246 | if (isCompound(s)) {
| 1-18 | ||||||||||||||||||
| 1247 | QState *grp = toStandardState(s); | - | ||||||||||||||||||
| 1248 | QList<QAbstractState*> lst = QStatePrivate::get(grp)->childStates(); | - | ||||||||||||||||||
| 1249 | for (int i = 0; i < lst.size(); ++i) {
| 4-30 | ||||||||||||||||||
| 1250 | QAbstractState *cs = lst.at(i); | - | ||||||||||||||||||
| 1251 | if (isFinal(cs) && configuration.contains(cs))
| 4-18 | ||||||||||||||||||
| 1252 | return true; executed 14 times by 1 test: return true;Executed by:
| 14 | ||||||||||||||||||
| 1253 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 1254 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||
| 1255 | } else if (isParallel(s)) {
| 0-1 | ||||||||||||||||||
| 1256 | QState *grp = toStandardState(s); | - | ||||||||||||||||||
| 1257 | QList<QAbstractState*> lst = QStatePrivate::get(grp)->childStates(); | - | ||||||||||||||||||
| 1258 | for (int i = 0; i < lst.size(); ++i) {
| 1-2 | ||||||||||||||||||
| 1259 | QAbstractState *cs = lst.at(i); | - | ||||||||||||||||||
| 1260 | if (!isInFinalState(cs))
| 0-2 | ||||||||||||||||||
| 1261 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1262 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1263 | return true; executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||||||||
| 1264 | } | - | ||||||||||||||||||
| 1265 | else | - | ||||||||||||||||||
| 1266 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1267 | } | - | ||||||||||||||||||
| 1268 | - | |||||||||||||||||||
| 1269 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||
| 1270 | - | |||||||||||||||||||
| 1271 | /*! | - | ||||||||||||||||||
| 1272 | \internal | - | ||||||||||||||||||
| 1273 | Returns \c true if the given state has saved the value of the given property, | - | ||||||||||||||||||
| 1274 | otherwise returns \c false. | - | ||||||||||||||||||
| 1275 | */ | - | ||||||||||||||||||
| 1276 | bool QStateMachinePrivate::hasRestorable(QAbstractState *state, QObject *object, | - | ||||||||||||||||||
| 1277 | const QByteArray &propertyName) const | - | ||||||||||||||||||
| 1278 | { | - | ||||||||||||||||||
| 1279 | RestorableId id(object, propertyName); | - | ||||||||||||||||||
| 1280 | return registeredRestorablesForState.value(state).contains(id); executed 48 times by 1 test: return registeredRestorablesForState.value(state).contains(id);Executed by:
| 48 | ||||||||||||||||||
| 1281 | } | - | ||||||||||||||||||
| 1282 | - | |||||||||||||||||||
| 1283 | /*! | - | ||||||||||||||||||
| 1284 | \internal | - | ||||||||||||||||||
| 1285 | Returns the value to save for the property identified by \a id. | - | ||||||||||||||||||
| 1286 | If an exited state (member of \a exitedStates_sorted) has saved a value for | - | ||||||||||||||||||
| 1287 | the property, the saved value from the last (outermost) state that will be | - | ||||||||||||||||||
| 1288 | exited is returned (in practice carrying the saved value on to the next | - | ||||||||||||||||||
| 1289 | state). Otherwise, the current value of the property is returned. | - | ||||||||||||||||||
| 1290 | */ | - | ||||||||||||||||||
| 1291 | QVariant QStateMachinePrivate::savedValueForRestorable(const QList<QAbstractState*> &exitedStates_sorted, | - | ||||||||||||||||||
| 1292 | QObject *object, const QByteArray &propertyName) const | - | ||||||||||||||||||
| 1293 | { | - | ||||||||||||||||||
| 1294 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1295 | qDebug() << q_func() << ": savedValueForRestorable(" << exitedStates_sorted << object << propertyName << ')'; | - | ||||||||||||||||||
| 1296 | #endif | - | ||||||||||||||||||
| 1297 | for (int i = exitedStates_sorted.size() - 1; i >= 0; --i) {
| 29-38 | ||||||||||||||||||
| 1298 | QAbstractState *s = exitedStates_sorted.at(i); | - | ||||||||||||||||||
| 1299 | QHash<RestorableId, QVariant> restorables = registeredRestorablesForState.value(s); | - | ||||||||||||||||||
| 1300 | QHash<RestorableId, QVariant>::const_iterator it = restorables.constFind(RestorableId(object, propertyName)); | - | ||||||||||||||||||
| 1301 | if (it != restorables.constEnd()) {
| 17-21 | ||||||||||||||||||
| 1302 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1303 | qDebug() << q_func() << ": using" << it.value() << "from" << s; | - | ||||||||||||||||||
| 1304 | #endif | - | ||||||||||||||||||
| 1305 | return it.value(); executed 17 times by 1 test: return it.value();Executed by:
| 17 | ||||||||||||||||||
| 1306 | } | - | ||||||||||||||||||
| 1307 | } executed 21 times by 1 test: end of blockExecuted by:
| 21 | ||||||||||||||||||
| 1308 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1309 | qDebug() << q_func() << ": falling back to current value"; | - | ||||||||||||||||||
| 1310 | #endif | - | ||||||||||||||||||
| 1311 | return object->property(propertyName); executed 29 times by 1 test: return object->property(propertyName);Executed by:
| 29 | ||||||||||||||||||
| 1312 | } | - | ||||||||||||||||||
| 1313 | - | |||||||||||||||||||
| 1314 | void QStateMachinePrivate::registerRestorable(QAbstractState *state, QObject *object, const QByteArray &propertyName, | - | ||||||||||||||||||
| 1315 | const QVariant &value) | - | ||||||||||||||||||
| 1316 | { | - | ||||||||||||||||||
| 1317 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1318 | qDebug() << q_func() << ": registerRestorable(" << state << object << propertyName << value << ')'; | - | ||||||||||||||||||
| 1319 | #endif | - | ||||||||||||||||||
| 1320 | RestorableId id(object, propertyName); | - | ||||||||||||||||||
| 1321 | QHash<RestorableId, QVariant> &restorables = registeredRestorablesForState[state]; | - | ||||||||||||||||||
| 1322 | if (!restorables.contains(id))
| 0-46 | ||||||||||||||||||
| 1323 | restorables.insert(id, value); executed 46 times by 1 test: restorables.insert(id, value);Executed by:
| 46 | ||||||||||||||||||
| 1324 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1325 | else | - | ||||||||||||||||||
| 1326 | qDebug() << q_func() << ": (already registered)"; | - | ||||||||||||||||||
| 1327 | #endif | - | ||||||||||||||||||
| 1328 | } executed 46 times by 1 test: end of blockExecuted by:
| 46 | ||||||||||||||||||
| 1329 | - | |||||||||||||||||||
| 1330 | void QStateMachinePrivate::unregisterRestorables(const QList<QAbstractState *> &states, QObject *object, | - | ||||||||||||||||||
| 1331 | const QByteArray &propertyName) | - | ||||||||||||||||||
| 1332 | { | - | ||||||||||||||||||
| 1333 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1334 | qDebug() << q_func() << ": unregisterRestorables(" << states << object << propertyName << ')'; | - | ||||||||||||||||||
| 1335 | #endif | - | ||||||||||||||||||
| 1336 | RestorableId id(object, propertyName); | - | ||||||||||||||||||
| 1337 | for (int i = 0; i < states.size(); ++i) {
| 65-70 | ||||||||||||||||||
| 1338 | QAbstractState *s = states.at(i); | - | ||||||||||||||||||
| 1339 | QHash<QAbstractState*, QHash<RestorableId, QVariant> >::iterator it; | - | ||||||||||||||||||
| 1340 | it = registeredRestorablesForState.find(s); | - | ||||||||||||||||||
| 1341 | if (it == registeredRestorablesForState.end())
| 24-46 | ||||||||||||||||||
| 1342 | continue; executed 24 times by 1 test: continue;Executed by:
| 24 | ||||||||||||||||||
| 1343 | QHash<RestorableId, QVariant> &restorables = it.value(); | - | ||||||||||||||||||
| 1344 | QHash<RestorableId, QVariant>::iterator it2; | - | ||||||||||||||||||
| 1345 | it2 = restorables.find(id); | - | ||||||||||||||||||
| 1346 | if (it2 == restorables.end())
| 9-37 | ||||||||||||||||||
| 1347 | continue; executed 9 times by 1 test: continue;Executed by:
| 9 | ||||||||||||||||||
| 1348 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1349 | qDebug() << q_func() << ": unregistered for" << s; | - | ||||||||||||||||||
| 1350 | #endif | - | ||||||||||||||||||
| 1351 | restorables.erase(it2); | - | ||||||||||||||||||
| 1352 | if (restorables.isEmpty())
| 5-32 | ||||||||||||||||||
| 1353 | registeredRestorablesForState.erase(it); executed 32 times by 1 test: registeredRestorablesForState.erase(it);Executed by:
| 32 | ||||||||||||||||||
| 1354 | } executed 37 times by 1 test: end of blockExecuted by:
| 37 | ||||||||||||||||||
| 1355 | } executed 65 times by 1 test: end of blockExecuted by:
| 65 | ||||||||||||||||||
| 1356 | - | |||||||||||||||||||
| 1357 | QVector<QPropertyAssignment> QStateMachinePrivate::restorablesToPropertyList(const QHash<RestorableId, QVariant> &restorables) const | - | ||||||||||||||||||
| 1358 | { | - | ||||||||||||||||||
| 1359 | QVector<QPropertyAssignment> result; | - | ||||||||||||||||||
| 1360 | QHash<RestorableId, QVariant>::const_iterator it; | - | ||||||||||||||||||
| 1361 | for (it = restorables.constBegin(); it != restorables.constEnd(); ++it) {
| 23-25 | ||||||||||||||||||
| 1362 | const RestorableId &id = it.key(); | - | ||||||||||||||||||
| 1363 | if (!id.object()) {
| 1-24 | ||||||||||||||||||
| 1364 | // Property object was deleted | - | ||||||||||||||||||
| 1365 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||||||||
| 1366 | } | - | ||||||||||||||||||
| 1367 | #ifdef QSTATEMACHINE_RESTORE_PROPERTIES_DEBUG | - | ||||||||||||||||||
| 1368 | qDebug() << q_func() << ": restoring" << id.object() << id.proertyName() << "to" << it.value(); | - | ||||||||||||||||||
| 1369 | #endif | - | ||||||||||||||||||
| 1370 | result.append(QPropertyAssignment(id.object(), id.propertyName(), it.value(), /*explicitlySet=*/false)); | - | ||||||||||||||||||
| 1371 | } executed 24 times by 1 test: end of blockExecuted by:
| 24 | ||||||||||||||||||
| 1372 | return result; executed 23 times by 1 test: return result;Executed by:
| 23 | ||||||||||||||||||
| 1373 | } | - | ||||||||||||||||||
| 1374 | - | |||||||||||||||||||
| 1375 | /*! | - | ||||||||||||||||||
| 1376 | \internal | - | ||||||||||||||||||
| 1377 | Computes the set of properties whose values should be restored given that | - | ||||||||||||||||||
| 1378 | the states \a statesToExit_sorted will be exited. | - | ||||||||||||||||||
| 1379 | - | |||||||||||||||||||
| 1380 | If a particular (object, propertyName) pair occurs more than once (i.e., | - | ||||||||||||||||||
| 1381 | because nested states are being exited), the value from the last (outermost) | - | ||||||||||||||||||
| 1382 | exited state takes precedence. | - | ||||||||||||||||||
| 1383 | - | |||||||||||||||||||
| 1384 | The result of this function must be filtered according to the explicit | - | ||||||||||||||||||
| 1385 | property assignments (QState::assignProperty()) of the entered states | - | ||||||||||||||||||
| 1386 | before the property restoration is actually performed; i.e., if an entered | - | ||||||||||||||||||
| 1387 | state assigns to a property that would otherwise be restored, that property | - | ||||||||||||||||||
| 1388 | should not be restored after all, but the saved value from the exited state | - | ||||||||||||||||||
| 1389 | should be remembered by the entered state (see registerRestorable()). | - | ||||||||||||||||||
| 1390 | */ | - | ||||||||||||||||||
| 1391 | QHash<QStateMachinePrivate::RestorableId, QVariant> QStateMachinePrivate::computePendingRestorables( | - | ||||||||||||||||||
| 1392 | const QList<QAbstractState*> &statesToExit_sorted) const | - | ||||||||||||||||||
| 1393 | { | - | ||||||||||||||||||
| 1394 | QHash<QStateMachinePrivate::RestorableId, QVariant> restorables; | - | ||||||||||||||||||
| 1395 | for (int i = statesToExit_sorted.size() - 1; i >= 0; --i) {
| 1235-1298 | ||||||||||||||||||
| 1396 | QAbstractState *s = statesToExit_sorted.at(i); | - | ||||||||||||||||||
| 1397 | QHash<QStateMachinePrivate::RestorableId, QVariant> rs = registeredRestorablesForState.value(s); | - | ||||||||||||||||||
| 1398 | QHash<QStateMachinePrivate::RestorableId, QVariant>::const_iterator it; | - | ||||||||||||||||||
| 1399 | for (it = rs.constBegin(); it != rs.constEnd(); ++it) {
| 39-1298 | ||||||||||||||||||
| 1400 | if (!restorables.contains(it.key()))
| 1-38 | ||||||||||||||||||
| 1401 | restorables.insert(it.key(), it.value()); executed 38 times by 1 test: restorables.insert(it.key(), it.value());Executed by:
| 38 | ||||||||||||||||||
| 1402 | } executed 39 times by 1 test: end of blockExecuted by:
| 39 | ||||||||||||||||||
| 1403 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 1404 | return restorables; executed 1235 times by 2 tests: return restorables;Executed by:
| 1235 | ||||||||||||||||||
| 1405 | } | - | ||||||||||||||||||
| 1406 | - | |||||||||||||||||||
| 1407 | /*! | - | ||||||||||||||||||
| 1408 | \internal | - | ||||||||||||||||||
| 1409 | Computes the ordered sets of property assignments for the states to be | - | ||||||||||||||||||
| 1410 | entered, \a statesToEnter_sorted. Also filters \a pendingRestorables (removes | - | ||||||||||||||||||
| 1411 | properties that should not be restored because they are assigned by an | - | ||||||||||||||||||
| 1412 | entered state). | - | ||||||||||||||||||
| 1413 | */ | - | ||||||||||||||||||
| 1414 | QHash<QAbstractState*, QVector<QPropertyAssignment> > QStateMachinePrivate::computePropertyAssignments( | - | ||||||||||||||||||
| 1415 | const QList<QAbstractState*> &statesToEnter_sorted, QHash<RestorableId, QVariant> &pendingRestorables) const | - | ||||||||||||||||||
| 1416 | { | - | ||||||||||||||||||
| 1417 | QHash<QAbstractState*, QVector<QPropertyAssignment> > assignmentsForState; | - | ||||||||||||||||||
| 1418 | for (int i = 0; i < statesToEnter_sorted.size(); ++i) {
| 1388-1507 | ||||||||||||||||||
| 1419 | QState *s = toStandardState(statesToEnter_sorted.at(i)); | - | ||||||||||||||||||
| 1420 | if (!s)
| 72-1435 | ||||||||||||||||||
| 1421 | continue; executed 72 times by 1 test: continue;Executed by:
| 72 | ||||||||||||||||||
| 1422 | - | |||||||||||||||||||
| 1423 | QVector<QPropertyAssignment> &assignments = QStatePrivate::get(s)->propertyAssignments; | - | ||||||||||||||||||
| 1424 | for (int j = 0; j < assignments.size(); ++j) {
| 110-1435 | ||||||||||||||||||
| 1425 | const QPropertyAssignment &assn = assignments.at(j); | - | ||||||||||||||||||
| 1426 | if (assn.objectDeleted()) {
| 1-109 | ||||||||||||||||||
| 1427 | assignments.removeAt(j--); | - | ||||||||||||||||||
| 1428 | } else { executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 1429 | pendingRestorables.remove(RestorableId(assn.object, assn.propertyName)); | - | ||||||||||||||||||
| 1430 | assignmentsForState[s].append(assn); | - | ||||||||||||||||||
| 1431 | } executed 109 times by 2 tests: end of blockExecuted by:
| 109 | ||||||||||||||||||
| 1432 | } | - | ||||||||||||||||||
| 1433 | } executed 1435 times by 2 tests: end of blockExecuted by:
| 1435 | ||||||||||||||||||
| 1434 | return assignmentsForState; executed 1388 times by 2 tests: return assignmentsForState;Executed by:
| 1388 | ||||||||||||||||||
| 1435 | } | - | ||||||||||||||||||
| 1436 | - | |||||||||||||||||||
| 1437 | #endif // QT_NO_PROPERTIES | - | ||||||||||||||||||
| 1438 | - | |||||||||||||||||||
| 1439 | QAbstractState *QStateMachinePrivate::findErrorState(QAbstractState *context) | - | ||||||||||||||||||
| 1440 | { | - | ||||||||||||||||||
| 1441 | // Find error state recursively in parent hierarchy if not set explicitly for context state | - | ||||||||||||||||||
| 1442 | QAbstractState *errorState = 0; | - | ||||||||||||||||||
| 1443 | if (context != 0) {
| 9-40 | ||||||||||||||||||
| 1444 | QState *s = toStandardState(context); | - | ||||||||||||||||||
| 1445 | if (s != 0)
| 1-39 | ||||||||||||||||||
| 1446 | errorState = s->errorState(); executed 39 times by 1 test: errorState = s->errorState();Executed by:
| 39 | ||||||||||||||||||
| 1447 | - | |||||||||||||||||||
| 1448 | if (errorState == 0)
| 11-29 | ||||||||||||||||||
| 1449 | errorState = findErrorState(context->parentState()); executed 29 times by 1 test: errorState = findErrorState(context->parentState());Executed by:
| 29 | ||||||||||||||||||
| 1450 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 1451 | - | |||||||||||||||||||
| 1452 | return errorState; executed 49 times by 1 test: return errorState;Executed by:
| 49 | ||||||||||||||||||
| 1453 | } | - | ||||||||||||||||||
| 1454 | - | |||||||||||||||||||
| 1455 | void QStateMachinePrivate::setError(QStateMachine::Error errorCode, QAbstractState *currentContext) | - | ||||||||||||||||||
| 1456 | { | - | ||||||||||||||||||
| 1457 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1458 | - | |||||||||||||||||||
| 1459 | error = errorCode; | - | ||||||||||||||||||
| 1460 | switch (errorCode) { | - | ||||||||||||||||||
| 1461 | case QStateMachine::NoInitialStateError: executed 16 times by 1 test: case QStateMachine::NoInitialStateError:Executed by:
| 16 | ||||||||||||||||||
| 1462 | Q_ASSERT(currentContext != 0); | - | ||||||||||||||||||
| 1463 | - | |||||||||||||||||||
| 1464 | errorString = QStateMachine::tr("Missing initial state in compound state '%1'") | - | ||||||||||||||||||
| 1465 | .arg(currentContext->objectName()); | - | ||||||||||||||||||
| 1466 | - | |||||||||||||||||||
| 1467 | break; executed 16 times by 1 test: break;Executed by:
| 16 | ||||||||||||||||||
| 1468 | case QStateMachine::NoDefaultStateInHistoryStateError: executed 1 time by 1 test: case QStateMachine::NoDefaultStateInHistoryStateError:Executed by:
| 1 | ||||||||||||||||||
| 1469 | Q_ASSERT(currentContext != 0); | - | ||||||||||||||||||
| 1470 | - | |||||||||||||||||||
| 1471 | errorString = QStateMachine::tr("Missing default state in history state '%1'") | - | ||||||||||||||||||
| 1472 | .arg(currentContext->objectName()); | - | ||||||||||||||||||
| 1473 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 1474 | - | |||||||||||||||||||
| 1475 | case QStateMachine::NoCommonAncestorForTransitionError: executed 3 times by 1 test: case QStateMachine::NoCommonAncestorForTransitionError:Executed by:
| 3 | ||||||||||||||||||
| 1476 | Q_ASSERT(currentContext != 0); | - | ||||||||||||||||||
| 1477 | - | |||||||||||||||||||
| 1478 | errorString = QStateMachine::tr("No common ancestor for targets and source of transition from state '%1'") | - | ||||||||||||||||||
| 1479 | .arg(currentContext->objectName()); | - | ||||||||||||||||||
| 1480 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 1481 | default: never executed: default: | 0 | ||||||||||||||||||
| 1482 | errorString = QStateMachine::tr("Unknown error"); | - | ||||||||||||||||||
| 1483 | }; never executed: end of block | 0 | ||||||||||||||||||
| 1484 | - | |||||||||||||||||||
| 1485 | pendingErrorStates.clear(); | - | ||||||||||||||||||
| 1486 | pendingErrorStatesForDefaultEntry.clear(); | - | ||||||||||||||||||
| 1487 | - | |||||||||||||||||||
| 1488 | QAbstractState *currentErrorState = findErrorState(currentContext); | - | ||||||||||||||||||
| 1489 | - | |||||||||||||||||||
| 1490 | // Avoid infinite loop if the error state itself has an error | - | ||||||||||||||||||
| 1491 | if (currentContext == currentErrorState)
| 1-19 | ||||||||||||||||||
| 1492 | currentErrorState = 0; executed 1 time by 1 test: currentErrorState = 0;Executed by:
| 1 | ||||||||||||||||||
| 1493 | - | |||||||||||||||||||
| 1494 | Q_ASSERT(currentErrorState != rootState()); | - | ||||||||||||||||||
| 1495 | - | |||||||||||||||||||
| 1496 | if (currentErrorState != 0) {
| 10 | ||||||||||||||||||
| 1497 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1498 | qDebug() << q << ": entering error state" << currentErrorState << "from" << currentContext; | - | ||||||||||||||||||
| 1499 | #endif | - | ||||||||||||||||||
| 1500 | pendingErrorStates.insert(currentErrorState); | - | ||||||||||||||||||
| 1501 | addDescendantStatesToEnter(currentErrorState, pendingErrorStates, pendingErrorStatesForDefaultEntry); | - | ||||||||||||||||||
| 1502 | addAncestorStatesToEnter(currentErrorState, rootState(), pendingErrorStates, pendingErrorStatesForDefaultEntry); | - | ||||||||||||||||||
| 1503 | foreach (QAbstractState *s, configuration) | - | ||||||||||||||||||
| 1504 | pendingErrorStates.remove(s); executed 10 times by 1 test: pendingErrorStates.remove(s);Executed by:
| 10 | ||||||||||||||||||
| 1505 | } else { executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1506 | qWarning("Unrecoverable error detected in running state machine: %s", | - | ||||||||||||||||||
| 1507 | qPrintable(errorString)); | - | ||||||||||||||||||
| 1508 | q->stop(); | - | ||||||||||||||||||
| 1509 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1510 | } | - | ||||||||||||||||||
| 1511 | - | |||||||||||||||||||
| 1512 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1513 | - | |||||||||||||||||||
| 1514 | QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> > | - | ||||||||||||||||||
| 1515 | QStateMachinePrivate::initializeAnimation(QAbstractAnimation *abstractAnimation, | - | ||||||||||||||||||
| 1516 | const QPropertyAssignment &prop) | - | ||||||||||||||||||
| 1517 | { | - | ||||||||||||||||||
| 1518 | QList<QAbstractAnimation*> handledAnimations; | - | ||||||||||||||||||
| 1519 | QList<QAbstractAnimation*> localResetEndValues; | - | ||||||||||||||||||
| 1520 | QAnimationGroup *group = qobject_cast<QAnimationGroup*>(abstractAnimation); | - | ||||||||||||||||||
| 1521 | if (group) {
| 5-50 | ||||||||||||||||||
| 1522 | for (int i = 0; i < group->animationCount(); ++i) {
| 5-8 | ||||||||||||||||||
| 1523 | QAbstractAnimation *animationChild = group->animationAt(i); | - | ||||||||||||||||||
| 1524 | QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> > ret; | - | ||||||||||||||||||
| 1525 | ret = initializeAnimation(animationChild, prop); | - | ||||||||||||||||||
| 1526 | handledAnimations << ret.first; | - | ||||||||||||||||||
| 1527 | localResetEndValues << ret.second; | - | ||||||||||||||||||
| 1528 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 1529 | } else { executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 1530 | QPropertyAnimation *animation = qobject_cast<QPropertyAnimation *>(abstractAnimation); | - | ||||||||||||||||||
| 1531 | if (animation != 0
| 0-50 | ||||||||||||||||||
| 1532 | && prop.object == animation->targetObject()
| 4-46 | ||||||||||||||||||
| 1533 | && prop.propertyName == animation->propertyName()) {
| 10-36 | ||||||||||||||||||
| 1534 | - | |||||||||||||||||||
| 1535 | // Only change end value if it is undefined | - | ||||||||||||||||||
| 1536 | if (!animation->endValue().isValid()) {
| 1-35 | ||||||||||||||||||
| 1537 | animation->setEndValue(prop.value); | - | ||||||||||||||||||
| 1538 | localResetEndValues.append(animation); | - | ||||||||||||||||||
| 1539 | } executed 35 times by 1 test: end of blockExecuted by:
| 35 | ||||||||||||||||||
| 1540 | handledAnimations.append(animation); | - | ||||||||||||||||||
| 1541 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 1542 | } executed 50 times by 1 test: end of blockExecuted by:
| 50 | ||||||||||||||||||
| 1543 | return qMakePair(handledAnimations, localResetEndValues); executed 55 times by 1 test: return qMakePair(handledAnimations, localResetEndValues);Executed by:
| 55 | ||||||||||||||||||
| 1544 | } | - | ||||||||||||||||||
| 1545 | - | |||||||||||||||||||
| 1546 | void QStateMachinePrivate::_q_animationFinished() | - | ||||||||||||||||||
| 1547 | { | - | ||||||||||||||||||
| 1548 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1549 | QAbstractAnimation *anim = qobject_cast<QAbstractAnimation*>(q->sender()); | - | ||||||||||||||||||
| 1550 | Q_ASSERT(anim != 0); | - | ||||||||||||||||||
| 1551 | QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished())); | - | ||||||||||||||||||
| 1552 | if (resetAnimationEndValues.contains(anim)) {
| 0-15 | ||||||||||||||||||
| 1553 | qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize | - | ||||||||||||||||||
| 1554 | resetAnimationEndValues.remove(anim); | - | ||||||||||||||||||
| 1555 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 1556 | - | |||||||||||||||||||
| 1557 | QAbstractState *state = stateForAnimation.take(anim); | - | ||||||||||||||||||
| 1558 | Q_ASSERT(state != 0); | - | ||||||||||||||||||
| 1559 | - | |||||||||||||||||||
| 1560 | #ifndef QT_NO_PROPERTIES | - | ||||||||||||||||||
| 1561 | // Set the final property value. | - | ||||||||||||||||||
| 1562 | QPropertyAssignment assn = propertyForAnimation.take(anim); | - | ||||||||||||||||||
| 1563 | assn.write(); | - | ||||||||||||||||||
| 1564 | if (!assn.explicitlySet)
| 1-14 | ||||||||||||||||||
| 1565 | 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 | ||||||||||||||||||
| 1566 | #endif | - | ||||||||||||||||||
| 1567 | - | |||||||||||||||||||
| 1568 | QHash<QAbstractState*, QList<QAbstractAnimation*> >::iterator it; | - | ||||||||||||||||||
| 1569 | it = animationsForState.find(state); | - | ||||||||||||||||||
| 1570 | Q_ASSERT(it != animationsForState.end()); | - | ||||||||||||||||||
| 1571 | QList<QAbstractAnimation*> &animations = it.value(); | - | ||||||||||||||||||
| 1572 | animations.removeOne(anim); | - | ||||||||||||||||||
| 1573 | if (animations.isEmpty()) {
| 3-12 | ||||||||||||||||||
| 1574 | animationsForState.erase(it); | - | ||||||||||||||||||
| 1575 | QStatePrivate::get(toStandardState(state))->emitPropertiesAssigned(); | - | ||||||||||||||||||
| 1576 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1577 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 1578 | - | |||||||||||||||||||
| 1579 | QList<QAbstractAnimation *> QStateMachinePrivate::selectAnimations(const QList<QAbstractTransition *> &transitionList) const | - | ||||||||||||||||||
| 1580 | { | - | ||||||||||||||||||
| 1581 | QList<QAbstractAnimation *> selectedAnimations; | - | ||||||||||||||||||
| 1582 | if (animated) {
| 0-1388 | ||||||||||||||||||
| 1583 | for (int i = 0; i < transitionList.size(); ++i) {
| 1388-1391 | ||||||||||||||||||
| 1584 | QAbstractTransition *transition = transitionList.at(i); | - | ||||||||||||||||||
| 1585 | - | |||||||||||||||||||
| 1586 | selectedAnimations << transition->animations(); | - | ||||||||||||||||||
| 1587 | selectedAnimations << defaultAnimationsForSource.values(transition->sourceState()); | - | ||||||||||||||||||
| 1588 | - | |||||||||||||||||||
| 1589 | QList<QAbstractState *> targetStates = transition->targetStates(); | - | ||||||||||||||||||
| 1590 | for (int j=0; j<targetStates.size(); ++j)
| 1387-1391 | ||||||||||||||||||
| 1591 | selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j)); executed 1387 times by 2 tests: selectedAnimations << defaultAnimationsForTarget.values(targetStates.at(j));Executed by:
| 1387 | ||||||||||||||||||
| 1592 | } executed 1391 times by 2 tests: end of blockExecuted by:
| 1391 | ||||||||||||||||||
| 1593 | selectedAnimations << defaultAnimations; | - | ||||||||||||||||||
| 1594 | } executed 1388 times by 2 tests: end of blockExecuted by:
| 1388 | ||||||||||||||||||
| 1595 | return selectedAnimations; executed 1388 times by 2 tests: return selectedAnimations;Executed by:
| 1388 | ||||||||||||||||||
| 1596 | } | - | ||||||||||||||||||
| 1597 | - | |||||||||||||||||||
| 1598 | void QStateMachinePrivate::terminateActiveAnimations(QAbstractState *state, | - | ||||||||||||||||||
| 1599 | const QHash<QAbstractState*, QVector<QPropertyAssignment> > &assignmentsForEnteredStates) | - | ||||||||||||||||||
| 1600 | { | - | ||||||||||||||||||
| 1601 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1602 | QList<QAbstractAnimation*> animations = animationsForState.take(state); | - | ||||||||||||||||||
| 1603 | for (int i = 0; i < animations.size(); ++i) {
| 20-1298 | ||||||||||||||||||
| 1604 | QAbstractAnimation *anim = animations.at(i); | - | ||||||||||||||||||
| 1605 | QObject::disconnect(anim, SIGNAL(finished()), q, SLOT(_q_animationFinished())); | - | ||||||||||||||||||
| 1606 | stateForAnimation.remove(anim); | - | ||||||||||||||||||
| 1607 | - | |||||||||||||||||||
| 1608 | // Stop the (top-level) animation. | - | ||||||||||||||||||
| 1609 | // ### Stopping nested animation has weird behavior. | - | ||||||||||||||||||
| 1610 | QAbstractAnimation *topLevelAnim = anim; | - | ||||||||||||||||||
| 1611 | while (QAnimationGroup *group = topLevelAnim->group())
| 0-20 | ||||||||||||||||||
| 1612 | topLevelAnim = group; never executed: topLevelAnim = group; | 0 | ||||||||||||||||||
| 1613 | topLevelAnim->stop(); | - | ||||||||||||||||||
| 1614 | - | |||||||||||||||||||
| 1615 | if (resetAnimationEndValues.contains(anim)) {
| 1-19 | ||||||||||||||||||
| 1616 | qobject_cast<QVariantAnimation*>(anim)->setEndValue(QVariant()); // ### generalize | - | ||||||||||||||||||
| 1617 | resetAnimationEndValues.remove(anim); | - | ||||||||||||||||||
| 1618 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||
| 1619 | QPropertyAssignment assn = propertyForAnimation.take(anim); | - | ||||||||||||||||||
| 1620 | Q_ASSERT(assn.object != 0); | - | ||||||||||||||||||
| 1621 | // If there is no property assignment that sets this property, | - | ||||||||||||||||||
| 1622 | // set the property to its target value. | - | ||||||||||||||||||
| 1623 | bool found = false; | - | ||||||||||||||||||
| 1624 | QHash<QAbstractState*, QVector<QPropertyAssignment> >::const_iterator it; | - | ||||||||||||||||||
| 1625 | for (it = assignmentsForEnteredStates.constBegin(); it != assignmentsForEnteredStates.constEnd(); ++it) {
| 18-20 | ||||||||||||||||||
| 1626 | const QVector<QPropertyAssignment> &assignments = it.value(); | - | ||||||||||||||||||
| 1627 | for (int j = 0; j < assignments.size(); ++j) {
| 8-18 | ||||||||||||||||||
| 1628 | if (assignments.at(j).hasTarget(assn.object, assn.propertyName)) {
| 8-10 | ||||||||||||||||||
| 1629 | found = true; | - | ||||||||||||||||||
| 1630 | break; executed 10 times by 1 test: break;Executed by:
| 10 | ||||||||||||||||||
| 1631 | } | - | ||||||||||||||||||
| 1632 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 1633 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 1634 | if (!found) {
| 10 | ||||||||||||||||||
| 1635 | assn.write(); | - | ||||||||||||||||||
| 1636 | if (!assn.explicitlySet)
| 0-10 | ||||||||||||||||||
| 1637 | unregisterRestorables(QList<QAbstractState*>() << state, assn.object, assn.propertyName); never executed: unregisterRestorables(QList<QAbstractState*>() << state, assn.object, assn.propertyName); | 0 | ||||||||||||||||||
| 1638 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1639 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 1640 | } executed 1298 times by 2 tests: end of blockExecuted by:
| 1298 | ||||||||||||||||||
| 1641 | - | |||||||||||||||||||
| 1642 | void QStateMachinePrivate::initializeAnimations(QAbstractState *state, const QList<QAbstractAnimation *> &selectedAnimations, | - | ||||||||||||||||||
| 1643 | const QList<QAbstractState*> &exitedStates_sorted, | - | ||||||||||||||||||
| 1644 | QHash<QAbstractState*, QVector<QPropertyAssignment> > &assignmentsForEnteredStates) | - | ||||||||||||||||||
| 1645 | { | - | ||||||||||||||||||
| 1646 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1647 | if (!assignmentsForEnteredStates.contains(state))
| 115-1392 | ||||||||||||||||||
| 1648 | return; executed 1392 times by 2 tests: return;Executed by:
| 1392 | ||||||||||||||||||
| 1649 | QVector<QPropertyAssignment> &assignments = assignmentsForEnteredStates[state]; | - | ||||||||||||||||||
| 1650 | for (int i = 0; i < selectedAnimations.size(); ++i) {
| 41-85 | ||||||||||||||||||
| 1651 | QAbstractAnimation *anim = selectedAnimations.at(i); | - | ||||||||||||||||||
| 1652 | QVector<QPropertyAssignment>::iterator it; | - | ||||||||||||||||||
| 1653 | for (it = assignments.begin(); it != assignments.end(); ) {
| 41-47 | ||||||||||||||||||
| 1654 | QPair<QList<QAbstractAnimation*>, QList<QAbstractAnimation*> > ret; | - | ||||||||||||||||||
| 1655 | const QPropertyAssignment &assn = *it; | - | ||||||||||||||||||
| 1656 | ret = initializeAnimation(anim, assn); | - | ||||||||||||||||||
| 1657 | QList<QAbstractAnimation*> handlers = ret.first; | - | ||||||||||||||||||
| 1658 | if (!handlers.isEmpty()) {
| 11-36 | ||||||||||||||||||
| 1659 | for (int j = 0; j < handlers.size(); ++j) {
| 36 | ||||||||||||||||||
| 1660 | QAbstractAnimation *a = handlers.at(j); | - | ||||||||||||||||||
| 1661 | propertyForAnimation.insert(a, assn); | - | ||||||||||||||||||
| 1662 | stateForAnimation.insert(a, state); | - | ||||||||||||||||||
| 1663 | animationsForState[state].append(a); | - | ||||||||||||||||||
| 1664 | // ### connect to just the top-level animation? | - | ||||||||||||||||||
| 1665 | QObject::connect(a, SIGNAL(finished()), q, SLOT(_q_animationFinished()), Qt::UniqueConnection); | - | ||||||||||||||||||
| 1666 | } executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 1667 | if ((globalRestorePolicy == QState::RestoreProperties)
| 12-24 | ||||||||||||||||||
| 1668 | && !hasRestorable(state, assn.object, assn.propertyName)) {
| 0-12 | ||||||||||||||||||
| 1669 | QVariant value = savedValueForRestorable(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 1670 | unregisterRestorables(exitedStates_sorted, assn.object, assn.propertyName); | - | ||||||||||||||||||
| 1671 | registerRestorable(state, assn.object, assn.propertyName, value); | - | ||||||||||||||||||
| 1672 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 1673 | it = assignments.erase(it); | - | ||||||||||||||||||
| 1674 | } else { executed 36 times by 1 test: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 1675 | ++it; | - | ||||||||||||||||||
| 1676 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 1677 | for (int j = 0; j < ret.second.size(); ++j)
| 35-47 | ||||||||||||||||||
| 1678 | resetAnimationEndValues.insert(ret.second.at(j)); executed 35 times by 1 test: resetAnimationEndValues.insert(ret.second.at(j));Executed by:
| 35 | ||||||||||||||||||
| 1679 | } executed 47 times by 1 test: end of blockExecuted by:
| 47 | ||||||||||||||||||
| 1680 | // We require that at least one animation is valid. | - | ||||||||||||||||||
| 1681 | // ### generalize | - | ||||||||||||||||||
| 1682 | QList<QVariantAnimation*> variantAnims = anim->findChildren<QVariantAnimation*>(); | - | ||||||||||||||||||
| 1683 | if (QVariantAnimation *va = qobject_cast<QVariantAnimation*>(anim))
| 3-38 | ||||||||||||||||||
| 1684 | variantAnims.append(va); executed 38 times by 1 test: variantAnims.append(va);Executed by:
| 38 | ||||||||||||||||||
| 1685 | - | |||||||||||||||||||
| 1686 | bool hasValidEndValue = false; | - | ||||||||||||||||||
| 1687 | for (int j = 0; j < variantAnims.size(); ++j) {
| 2-41 | ||||||||||||||||||
| 1688 | if (variantAnims.at(j)->endValue().isValid()) {
| 2-39 | ||||||||||||||||||
| 1689 | hasValidEndValue = true; | - | ||||||||||||||||||
| 1690 | break; executed 39 times by 1 test: break;Executed by:
| 39 | ||||||||||||||||||
| 1691 | } | - | ||||||||||||||||||
| 1692 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1693 | - | |||||||||||||||||||
| 1694 | if (hasValidEndValue) {
| 2-39 | ||||||||||||||||||
| 1695 | if (anim->state() == QAbstractAnimation::Running) {
| 5-34 | ||||||||||||||||||
| 1696 | // The animation is still running. This can happen if the | - | ||||||||||||||||||
| 1697 | // animation is a group, and one of its children just finished, | - | ||||||||||||||||||
| 1698 | // and that caused a state to emit its propertiesAssigned() signal, and | - | ||||||||||||||||||
| 1699 | // that triggered a transition in the machine. | - | ||||||||||||||||||
| 1700 | // Just stop the animation so it is correctly restarted again. | - | ||||||||||||||||||
| 1701 | anim->stop(); | - | ||||||||||||||||||
| 1702 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 1703 | anim->start(); | - | ||||||||||||||||||
| 1704 | } executed 39 times by 1 test: end of blockExecuted by:
| 39 | ||||||||||||||||||
| 1705 | - | |||||||||||||||||||
| 1706 | if (assignments.isEmpty()) {
| 11-30 | ||||||||||||||||||
| 1707 | assignmentsForEnteredStates.remove(state); | - | ||||||||||||||||||
| 1708 | break; executed 30 times by 1 test: break;Executed by:
| 30 | ||||||||||||||||||
| 1709 | } | - | ||||||||||||||||||
| 1710 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 1711 | } executed 115 times by 2 tests: end of blockExecuted by:
| 115 | ||||||||||||||||||
| 1712 | - | |||||||||||||||||||
| 1713 | #endif // !QT_NO_ANIMATION | - | ||||||||||||||||||
| 1714 | - | |||||||||||||||||||
| 1715 | QAbstractTransition *QStateMachinePrivate::createInitialTransition() const | - | ||||||||||||||||||
| 1716 | { | - | ||||||||||||||||||
| 1717 | class InitialTransition : public QAbstractTransition | - | ||||||||||||||||||
| 1718 | { | - | ||||||||||||||||||
| 1719 | public: | - | ||||||||||||||||||
| 1720 | InitialTransition(const QList<QAbstractState *> &targets) | - | ||||||||||||||||||
| 1721 | : QAbstractTransition() | - | ||||||||||||||||||
| 1722 | { setTargetStates(targets); } executed 153 times by 2 tests: end of blockExecuted by:
| 153 | ||||||||||||||||||
| 1723 | protected: | - | ||||||||||||||||||
| 1724 | virtual bool eventTest(QEvent *) Q_DECL_OVERRIDE { return true; } never executed: return true; | 0 | ||||||||||||||||||
| 1725 | virtual void onTransition(QEvent *) Q_DECL_OVERRIDE {} | - | ||||||||||||||||||
| 1726 | }; | - | ||||||||||||||||||
| 1727 | - | |||||||||||||||||||
| 1728 | QState *root = rootState(); | - | ||||||||||||||||||
| 1729 | Q_ASSERT(root != 0); | - | ||||||||||||||||||
| 1730 | QList<QAbstractState *> targets; | - | ||||||||||||||||||
| 1731 | switch (root->childMode()) { | - | ||||||||||||||||||
| 1732 | case QState::ExclusiveStates: executed 152 times by 2 tests: case QState::ExclusiveStates:Executed by:
| 152 | ||||||||||||||||||
| 1733 | targets.append(root->initialState()); | - | ||||||||||||||||||
| 1734 | break; executed 152 times by 2 tests: break;Executed by:
| 152 | ||||||||||||||||||
| 1735 | case QState::ParallelStates: executed 1 time by 1 test: case QState::ParallelStates:Executed by:
| 1 | ||||||||||||||||||
| 1736 | targets = QStatePrivate::get(root)->childStates(); | - | ||||||||||||||||||
| 1737 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||
| 1738 | } | - | ||||||||||||||||||
| 1739 | return new InitialTransition(targets); executed 153 times by 2 tests: return new InitialTransition(targets);Executed by:
| 153 | ||||||||||||||||||
| 1740 | } | - | ||||||||||||||||||
| 1741 | - | |||||||||||||||||||
| 1742 | void QStateMachinePrivate::clearHistory() | - | ||||||||||||||||||
| 1743 | { | - | ||||||||||||||||||
| 1744 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1745 | QList<QHistoryState*> historyStates = q->findChildren<QHistoryState*>(); | - | ||||||||||||||||||
| 1746 | for (int i = 0; i < historyStates.size(); ++i) {
| 10-153 | ||||||||||||||||||
| 1747 | QHistoryState *h = historyStates.at(i); | - | ||||||||||||||||||
| 1748 | QHistoryStatePrivate::get(h)->configuration.clear(); | - | ||||||||||||||||||
| 1749 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 1750 | } executed 153 times by 2 tests: end of blockExecuted by:
| 153 | ||||||||||||||||||
| 1751 | - | |||||||||||||||||||
| 1752 | /*! | - | ||||||||||||||||||
| 1753 | \internal | - | ||||||||||||||||||
| 1754 | - | |||||||||||||||||||
| 1755 | Registers all signal transitions whose sender object lives in another thread. | - | ||||||||||||||||||
| 1756 | - | |||||||||||||||||||
| 1757 | Normally, signal transitions are lazily registered (when a state becomes | - | ||||||||||||||||||
| 1758 | active). But if the sender is in a different thread, the transition must be | - | ||||||||||||||||||
| 1759 | registered early to keep the state machine from "dropping" signals; e.g., | - | ||||||||||||||||||
| 1760 | a second (transition-bound) signal could be emitted on the sender thread | - | ||||||||||||||||||
| 1761 | before the state machine gets to process the first signal. | - | ||||||||||||||||||
| 1762 | */ | - | ||||||||||||||||||
| 1763 | void QStateMachinePrivate::registerMultiThreadedSignalTransitions() | - | ||||||||||||||||||
| 1764 | { | - | ||||||||||||||||||
| 1765 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1766 | QList<QSignalTransition*> transitions = rootState()->findChildren<QSignalTransition*>(); | - | ||||||||||||||||||
| 1767 | for (int i = 0; i < transitions.size(); ++i) {
| 81-153 | ||||||||||||||||||
| 1768 | QSignalTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 1769 | if ((t->machine() == q) && t->senderObject() && (t->senderObject()->thread() != q->thread()))
| 1-78 | ||||||||||||||||||
| 1770 | registerSignalTransition(t); executed 7 times by 1 test: registerSignalTransition(t);Executed by:
| 7 | ||||||||||||||||||
| 1771 | } executed 81 times by 2 tests: end of blockExecuted by:
| 81 | ||||||||||||||||||
| 1772 | } executed 153 times by 2 tests: end of blockExecuted by:
| 153 | ||||||||||||||||||
| 1773 | - | |||||||||||||||||||
| 1774 | void QStateMachinePrivate::_q_start() | - | ||||||||||||||||||
| 1775 | { | - | ||||||||||||||||||
| 1776 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1777 | Q_ASSERT(state == Starting); | - | ||||||||||||||||||
| 1778 | foreach (QAbstractState *state, configuration) { | - | ||||||||||||||||||
| 1779 | QAbstractStatePrivate *abstractStatePrivate = QAbstractStatePrivate::get(state); | - | ||||||||||||||||||
| 1780 | abstractStatePrivate->active = false; | - | ||||||||||||||||||
| 1781 | emit state->activeChanged(false); | - | ||||||||||||||||||
| 1782 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 1783 | configuration.clear(); | - | ||||||||||||||||||
| 1784 | qDeleteAll(internalEventQueue); | - | ||||||||||||||||||
| 1785 | internalEventQueue.clear(); | - | ||||||||||||||||||
| 1786 | qDeleteAll(externalEventQueue); | - | ||||||||||||||||||
| 1787 | externalEventQueue.clear(); | - | ||||||||||||||||||
| 1788 | clearHistory(); | - | ||||||||||||||||||
| 1789 | - | |||||||||||||||||||
| 1790 | registerMultiThreadedSignalTransitions(); | - | ||||||||||||||||||
| 1791 | - | |||||||||||||||||||
| 1792 | startupHook(); | - | ||||||||||||||||||
| 1793 | - | |||||||||||||||||||
| 1794 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1795 | qDebug() << q << ": starting"; | - | ||||||||||||||||||
| 1796 | #endif | - | ||||||||||||||||||
| 1797 | state = Running; | - | ||||||||||||||||||
| 1798 | processingScheduled = true; // we call _q_process() below | - | ||||||||||||||||||
| 1799 | - | |||||||||||||||||||
| 1800 | QList<QAbstractTransition*> transitions; | - | ||||||||||||||||||
| 1801 | CalculationCache calculationCache; | - | ||||||||||||||||||
| 1802 | QAbstractTransition *initialTransition = createInitialTransition(); | - | ||||||||||||||||||
| 1803 | transitions.append(initialTransition); | - | ||||||||||||||||||
| 1804 | - | |||||||||||||||||||
| 1805 | QEvent nullEvent(QEvent::None); | - | ||||||||||||||||||
| 1806 | executeTransitionContent(&nullEvent, transitions); | - | ||||||||||||||||||
| 1807 | QList<QAbstractState*> exitedStates = QList<QAbstractState*>(); | - | ||||||||||||||||||
| 1808 | QSet<QAbstractState*> statesForDefaultEntry; | - | ||||||||||||||||||
| 1809 | QList<QAbstractState*> enteredStates = computeEntrySet(transitions, statesForDefaultEntry, &calculationCache); | - | ||||||||||||||||||
| 1810 | QHash<RestorableId, QVariant> pendingRestorables; | - | ||||||||||||||||||
| 1811 | QHash<QAbstractState*, QVector<QPropertyAssignment> > assignmentsForEnteredStates = | - | ||||||||||||||||||
| 1812 | computePropertyAssignments(enteredStates, pendingRestorables); | - | ||||||||||||||||||
| 1813 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1814 | QList<QAbstractAnimation*> selectedAnimations = selectAnimations(transitions); | - | ||||||||||||||||||
| 1815 | #endif | - | ||||||||||||||||||
| 1816 | // enterStates() will set stopProcessingReason to Finished if a final | - | ||||||||||||||||||
| 1817 | // state is entered. | - | ||||||||||||||||||
| 1818 | stopProcessingReason = EventQueueEmpty; | - | ||||||||||||||||||
| 1819 | enterStates(&nullEvent, exitedStates, enteredStates, statesForDefaultEntry, | - | ||||||||||||||||||
| 1820 | assignmentsForEnteredStates | - | ||||||||||||||||||
| 1821 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 1822 | , selectedAnimations | - | ||||||||||||||||||
| 1823 | #endif | - | ||||||||||||||||||
| 1824 | ); | - | ||||||||||||||||||
| 1825 | delete initialTransition; | - | ||||||||||||||||||
| 1826 | - | |||||||||||||||||||
| 1827 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1828 | qDebug() << q << ": initial configuration:" << configuration; | - | ||||||||||||||||||
| 1829 | #endif | - | ||||||||||||||||||
| 1830 | - | |||||||||||||||||||
| 1831 | emit q->started(QStateMachine::QPrivateSignal()); | - | ||||||||||||||||||
| 1832 | emit q->runningChanged(true); | - | ||||||||||||||||||
| 1833 | - | |||||||||||||||||||
| 1834 | if (stopProcessingReason == Finished) {
| 2-151 | ||||||||||||||||||
| 1835 | // The state machine immediately reached a final state. | - | ||||||||||||||||||
| 1836 | processingScheduled = false; | - | ||||||||||||||||||
| 1837 | state = NotRunning; | - | ||||||||||||||||||
| 1838 | unregisterAllTransitions(); | - | ||||||||||||||||||
| 1839 | emitFinished(); | - | ||||||||||||||||||
| 1840 | emit q->runningChanged(false); | - | ||||||||||||||||||
| 1841 | exitInterpreter(); | - | ||||||||||||||||||
| 1842 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 1843 | _q_process(); | - | ||||||||||||||||||
| 1844 | } executed 151 times by 2 tests: end of blockExecuted by:
| 151 | ||||||||||||||||||
| 1845 | } | - | ||||||||||||||||||
| 1846 | - | |||||||||||||||||||
| 1847 | void QStateMachinePrivate::_q_process() | - | ||||||||||||||||||
| 1848 | { | - | ||||||||||||||||||
| 1849 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1850 | Q_ASSERT(state == Running); | - | ||||||||||||||||||
| 1851 | Q_ASSERT(!processing); | - | ||||||||||||||||||
| 1852 | processing = true; | - | ||||||||||||||||||
| 1853 | processingScheduled = false; | - | ||||||||||||||||||
| 1854 | beginMacrostep(); | - | ||||||||||||||||||
| 1855 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1856 | qDebug() << q << ": starting the event processing loop"; | - | ||||||||||||||||||
| 1857 | #endif | - | ||||||||||||||||||
| 1858 | bool didChange = false; | - | ||||||||||||||||||
| 1859 | while (processing) {
| 355-1548 | ||||||||||||||||||
| 1860 | if (stop) {
| 19-1529 | ||||||||||||||||||
| 1861 | processing = false; | - | ||||||||||||||||||
| 1862 | break; executed 19 times by 1 test: break;Executed by:
| 19 | ||||||||||||||||||
| 1863 | } | - | ||||||||||||||||||
| 1864 | QList<QAbstractTransition*> enabledTransitions; | - | ||||||||||||||||||
| 1865 | CalculationCache calculationCache; | - | ||||||||||||||||||
| 1866 | - | |||||||||||||||||||
| 1867 | QEvent *e = new QEvent(QEvent::None); | - | ||||||||||||||||||
| 1868 | enabledTransitions = selectTransitions(e, &calculationCache); | - | ||||||||||||||||||
| 1869 | if (enabledTransitions.isEmpty()) {
| 25-1504 | ||||||||||||||||||
| 1870 | delete e; | - | ||||||||||||||||||
| 1871 | e = 0; | - | ||||||||||||||||||
| 1872 | } executed 1504 times by 2 tests: end of blockExecuted by:
| 1504 | ||||||||||||||||||
| 1873 | while (enabledTransitions.isEmpty() && ((e = dequeueInternalEvent()) != 0)) {
| 99-1512 | ||||||||||||||||||
| 1874 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1875 | qDebug() << q << ": dequeued internal event" << e << "of type" << e->type(); | - | ||||||||||||||||||
| 1876 | #endif | - | ||||||||||||||||||
| 1877 | enabledTransitions = selectTransitions(e, &calculationCache); | - | ||||||||||||||||||
| 1878 | if (enabledTransitions.isEmpty()) {
| 8-91 | ||||||||||||||||||
| 1879 | delete e; | - | ||||||||||||||||||
| 1880 | e = 0; | - | ||||||||||||||||||
| 1881 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 1882 | } executed 99 times by 2 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1883 | while (enabledTransitions.isEmpty() && ((e = dequeueExternalEvent()) != 0)) {
| 294-2416 | ||||||||||||||||||
| 1884 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1885 | qDebug() << q << ": dequeued external event" << e << "of type" << e->type(); | - | ||||||||||||||||||
| 1886 | #endif | - | ||||||||||||||||||
| 1887 | enabledTransitions = selectTransitions(e, &calculationCache); | - | ||||||||||||||||||
| 1888 | if (enabledTransitions.isEmpty()) {
| 1003-1119 | ||||||||||||||||||
| 1889 | delete e; | - | ||||||||||||||||||
| 1890 | e = 0; | - | ||||||||||||||||||
| 1891 | } executed 1003 times by 1 test: end of blockExecuted by:
| 1003 | ||||||||||||||||||
| 1892 | } executed 2122 times by 2 tests: end of blockExecuted by:
| 2122 | ||||||||||||||||||
| 1893 | if (enabledTransitions.isEmpty()) {
| 294-1235 | ||||||||||||||||||
| 1894 | if (isInternalEventQueueEmpty()) {
| 1-293 | ||||||||||||||||||
| 1895 | processing = false; | - | ||||||||||||||||||
| 1896 | stopProcessingReason = EventQueueEmpty; | - | ||||||||||||||||||
| 1897 | noMicrostep(); | - | ||||||||||||||||||
| 1898 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1899 | qDebug() << q << ": no transitions enabled"; | - | ||||||||||||||||||
| 1900 | #endif | - | ||||||||||||||||||
| 1901 | } executed 293 times by 2 tests: end of blockExecuted by:
| 293 | ||||||||||||||||||
| 1902 | } else { executed 294 times by 2 tests: end of blockExecuted by:
| 294 | ||||||||||||||||||
| 1903 | didChange = true; | - | ||||||||||||||||||
| 1904 | q->beginMicrostep(e); | - | ||||||||||||||||||
| 1905 | microstep(e, enabledTransitions, &calculationCache); | - | ||||||||||||||||||
| 1906 | q->endMicrostep(e); | - | ||||||||||||||||||
| 1907 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 1908 | delete e; | - | ||||||||||||||||||
| 1909 | } executed 1529 times by 2 tests: end of blockExecuted by:
| 1529 | ||||||||||||||||||
| 1910 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 1911 | qDebug() << q << ": finished the event processing loop"; | - | ||||||||||||||||||
| 1912 | #endif | - | ||||||||||||||||||
| 1913 | if (stop) {
| 22-352 | ||||||||||||||||||
| 1914 | stop = false; | - | ||||||||||||||||||
| 1915 | stopProcessingReason = Stopped; | - | ||||||||||||||||||
| 1916 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 1917 | - | |||||||||||||||||||
| 1918 | switch (stopProcessingReason) { | - | ||||||||||||||||||
| 1919 | case EventQueueEmpty: executed 291 times by 2 tests: case EventQueueEmpty:Executed by:
| 291 | ||||||||||||||||||
| 1920 | processedPendingEvents(didChange); | - | ||||||||||||||||||
| 1921 | break; executed 291 times by 2 tests: break;Executed by:
| 291 | ||||||||||||||||||
| 1922 | case Finished: executed 61 times by 1 test: case Finished:Executed by:
| 61 | ||||||||||||||||||
| 1923 | state = NotRunning; | - | ||||||||||||||||||
| 1924 | cancelAllDelayedEvents(); | - | ||||||||||||||||||
| 1925 | unregisterAllTransitions(); | - | ||||||||||||||||||
| 1926 | emitFinished(); | - | ||||||||||||||||||
| 1927 | emit q->runningChanged(false); | - | ||||||||||||||||||
| 1928 | break; executed 61 times by 1 test: break;Executed by:
| 61 | ||||||||||||||||||
| 1929 | case Stopped: executed 22 times by 1 test: case Stopped:Executed by:
| 22 | ||||||||||||||||||
| 1930 | state = NotRunning; | - | ||||||||||||||||||
| 1931 | cancelAllDelayedEvents(); | - | ||||||||||||||||||
| 1932 | unregisterAllTransitions(); | - | ||||||||||||||||||
| 1933 | emit q->stopped(QStateMachine::QPrivateSignal()); | - | ||||||||||||||||||
| 1934 | emit q->runningChanged(false); | - | ||||||||||||||||||
| 1935 | break; executed 22 times by 1 test: break;Executed by:
| 22 | ||||||||||||||||||
| 1936 | } | - | ||||||||||||||||||
| 1937 | endMacrostep(didChange); | - | ||||||||||||||||||
| 1938 | if (stopProcessingReason == Finished)
| 61-313 | ||||||||||||||||||
| 1939 | exitInterpreter(); executed 61 times by 1 test: exitInterpreter();Executed by:
| 61 | ||||||||||||||||||
| 1940 | } executed 374 times by 2 tests: end of blockExecuted by:
| 374 | ||||||||||||||||||
| 1941 | - | |||||||||||||||||||
| 1942 | void QStateMachinePrivate::_q_startDelayedEventTimer(int id, int delay) | - | ||||||||||||||||||
| 1943 | { | - | ||||||||||||||||||
| 1944 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1945 | QMutexLocker locker(&delayedEventsMutex); | - | ||||||||||||||||||
| 1946 | QHash<int, DelayedEvent>::iterator it = delayedEvents.find(id); | - | ||||||||||||||||||
| 1947 | if (it != delayedEvents.end()) {
| 1 | ||||||||||||||||||
| 1948 | DelayedEvent &e = it.value(); | - | ||||||||||||||||||
| 1949 | Q_ASSERT(!e.timerId); | - | ||||||||||||||||||
| 1950 | e.timerId = q->startTimer(delay); | - | ||||||||||||||||||
| 1951 | if (!e.timerId) {
| 0-1 | ||||||||||||||||||
| 1952 | qWarning("QStateMachine::postDelayedEvent: failed to start timer (id=%d, delay=%d)", id, delay); | - | ||||||||||||||||||
| 1953 | delete e.event; | - | ||||||||||||||||||
| 1954 | delayedEvents.erase(it); | - | ||||||||||||||||||
| 1955 | delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 1956 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1957 | timerIdToDelayedEventId.insert(e.timerId, id); | - | ||||||||||||||||||
| 1958 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 1959 | } else { | - | ||||||||||||||||||
| 1960 | // It's been cancelled already | - | ||||||||||||||||||
| 1961 | delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 1962 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 1963 | } | - | ||||||||||||||||||
| 1964 | - | |||||||||||||||||||
| 1965 | void QStateMachinePrivate::_q_killDelayedEventTimer(int id, int timerId) | - | ||||||||||||||||||
| 1966 | { | - | ||||||||||||||||||
| 1967 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 1968 | q->killTimer(timerId); | - | ||||||||||||||||||
| 1969 | QMutexLocker locker(&delayedEventsMutex); | - | ||||||||||||||||||
| 1970 | delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 1971 | } never executed: end of block | 0 | ||||||||||||||||||
| 1972 | - | |||||||||||||||||||
| 1973 | void QStateMachinePrivate::postInternalEvent(QEvent *e) | - | ||||||||||||||||||
| 1974 | { | - | ||||||||||||||||||
| 1975 | QMutexLocker locker(&internalEventMutex); | - | ||||||||||||||||||
| 1976 | internalEventQueue.append(e); | - | ||||||||||||||||||
| 1977 | } executed 99 times by 2 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1978 | - | |||||||||||||||||||
| 1979 | void QStateMachinePrivate::postExternalEvent(QEvent *e) | - | ||||||||||||||||||
| 1980 | { | - | ||||||||||||||||||
| 1981 | QMutexLocker locker(&externalEventMutex); | - | ||||||||||||||||||
| 1982 | externalEventQueue.append(e); | - | ||||||||||||||||||
| 1983 | } executed 2123 times by 2 tests: end of blockExecuted by:
| 2123 | ||||||||||||||||||
| 1984 | - | |||||||||||||||||||
| 1985 | QEvent *QStateMachinePrivate::dequeueInternalEvent() | - | ||||||||||||||||||
| 1986 | { | - | ||||||||||||||||||
| 1987 | QMutexLocker locker(&internalEventMutex); | - | ||||||||||||||||||
| 1988 | if (internalEventQueue.isEmpty())
| 99-1413 | ||||||||||||||||||
| 1989 | return 0; executed 1413 times by 2 tests: return 0;Executed by:
| 1413 | ||||||||||||||||||
| 1990 | return internalEventQueue.takeFirst(); executed 99 times by 2 tests: return internalEventQueue.takeFirst();Executed by:
| 99 | ||||||||||||||||||
| 1991 | } | - | ||||||||||||||||||
| 1992 | - | |||||||||||||||||||
| 1993 | QEvent *QStateMachinePrivate::dequeueExternalEvent() | - | ||||||||||||||||||
| 1994 | { | - | ||||||||||||||||||
| 1995 | QMutexLocker locker(&externalEventMutex); | - | ||||||||||||||||||
| 1996 | if (externalEventQueue.isEmpty())
| 294-2122 | ||||||||||||||||||
| 1997 | return 0; executed 294 times by 2 tests: return 0;Executed by:
| 294 | ||||||||||||||||||
| 1998 | return externalEventQueue.takeFirst(); executed 2122 times by 2 tests: return externalEventQueue.takeFirst();Executed by:
| 2122 | ||||||||||||||||||
| 1999 | } | - | ||||||||||||||||||
| 2000 | - | |||||||||||||||||||
| 2001 | bool QStateMachinePrivate::isInternalEventQueueEmpty() | - | ||||||||||||||||||
| 2002 | { | - | ||||||||||||||||||
| 2003 | QMutexLocker locker(&internalEventMutex); | - | ||||||||||||||||||
| 2004 | return internalEventQueue.isEmpty(); executed 294 times by 2 tests: return internalEventQueue.isEmpty();Executed by:
| 294 | ||||||||||||||||||
| 2005 | } | - | ||||||||||||||||||
| 2006 | - | |||||||||||||||||||
| 2007 | bool QStateMachinePrivate::isExternalEventQueueEmpty() | - | ||||||||||||||||||
| 2008 | { | - | ||||||||||||||||||
| 2009 | QMutexLocker locker(&externalEventMutex); | - | ||||||||||||||||||
| 2010 | return externalEventQueue.isEmpty(); never executed: return externalEventQueue.isEmpty(); | 0 | ||||||||||||||||||
| 2011 | } | - | ||||||||||||||||||
| 2012 | - | |||||||||||||||||||
| 2013 | void QStateMachinePrivate::processEvents(EventProcessingMode processingMode) | - | ||||||||||||||||||
| 2014 | { | - | ||||||||||||||||||
| 2015 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2016 | if ((state != Running) || processing || processingScheduled)
| 0-2249 | ||||||||||||||||||
| 2017 | return; executed 2026 times by 1 test: return;Executed by:
| 2026 | ||||||||||||||||||
| 2018 | switch (processingMode) { | - | ||||||||||||||||||
| 2019 | case DirectProcessing: executed 93 times by 2 tests: case DirectProcessing:Executed by:
| 93 | ||||||||||||||||||
| 2020 | if (QThread::currentThread() == q->thread()) {
| 0-93 | ||||||||||||||||||
| 2021 | _q_process(); | - | ||||||||||||||||||
| 2022 | break; executed 93 times by 2 tests: break;Executed by:
| 93 | ||||||||||||||||||
| 2023 | } // fallthrough -- processing must be done in the machine thread | - | ||||||||||||||||||
| 2024 | case QueuedProcessing: code before this statement never executed: case QueuedProcessing:executed 130 times by 2 tests: case QueuedProcessing:Executed by:
| 0-130 | ||||||||||||||||||
| 2025 | processingScheduled = true; | - | ||||||||||||||||||
| 2026 | QMetaObject::invokeMethod(q, "_q_process", Qt::QueuedConnection); | - | ||||||||||||||||||
| 2027 | break; executed 130 times by 2 tests: break;Executed by:
| 130 | ||||||||||||||||||
| 2028 | } | - | ||||||||||||||||||
| 2029 | } executed 223 times by 2 tests: end of blockExecuted by:
| 223 | ||||||||||||||||||
| 2030 | - | |||||||||||||||||||
| 2031 | void QStateMachinePrivate::cancelAllDelayedEvents() | - | ||||||||||||||||||
| 2032 | { | - | ||||||||||||||||||
| 2033 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2034 | QMutexLocker locker(&delayedEventsMutex); | - | ||||||||||||||||||
| 2035 | QHash<int, DelayedEvent>::const_iterator it; | - | ||||||||||||||||||
| 2036 | for (it = delayedEvents.constBegin(); it != delayedEvents.constEnd(); ++it) {
| 2-83 | ||||||||||||||||||
| 2037 | const DelayedEvent &e = it.value(); | - | ||||||||||||||||||
| 2038 | if (e.timerId) {
| 0-2 | ||||||||||||||||||
| 2039 | timerIdToDelayedEventId.remove(e.timerId); | - | ||||||||||||||||||
| 2040 | q->killTimer(e.timerId); | - | ||||||||||||||||||
| 2041 | delayedEventIdFreeList.release(it.key()); | - | ||||||||||||||||||
| 2042 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2043 | // Cancellation will be detected in pending _q_startDelayedEventTimer() call | - | ||||||||||||||||||
| 2044 | } never executed: end of block | 0 | ||||||||||||||||||
| 2045 | delete e.event; | - | ||||||||||||||||||
| 2046 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2047 | delayedEvents.clear(); | - | ||||||||||||||||||
| 2048 | } executed 83 times by 1 test: end of blockExecuted by:
| 83 | ||||||||||||||||||
| 2049 | - | |||||||||||||||||||
| 2050 | /* | - | ||||||||||||||||||
| 2051 | This function is called when the state machine is performing no | - | ||||||||||||||||||
| 2052 | microstep because no transition is enabled (i.e. an event is ignored). | - | ||||||||||||||||||
| 2053 | - | |||||||||||||||||||
| 2054 | The default implementation does nothing. | - | ||||||||||||||||||
| 2055 | */ | - | ||||||||||||||||||
| 2056 | void QStateMachinePrivate::noMicrostep() | - | ||||||||||||||||||
| 2057 | { } | - | ||||||||||||||||||
| 2058 | - | |||||||||||||||||||
| 2059 | /* | - | ||||||||||||||||||
| 2060 | This function is called when the state machine has reached a stable | - | ||||||||||||||||||
| 2061 | state (no pending events), and has not finished yet. | - | ||||||||||||||||||
| 2062 | For each event the state machine receives it is guaranteed that | - | ||||||||||||||||||
| 2063 | 1) beginMacrostep is called | - | ||||||||||||||||||
| 2064 | 2) selectTransition is called at least once | - | ||||||||||||||||||
| 2065 | 3) begin/endMicrostep is called at least once or noMicrostep is called | - | ||||||||||||||||||
| 2066 | at least once (possibly both, but at least one) | - | ||||||||||||||||||
| 2067 | 4) the state machine either enters an infinite loop, or stops (runningChanged(false), | - | ||||||||||||||||||
| 2068 | and either finished or stopped are emitted), or processedPendingEvents() is called. | - | ||||||||||||||||||
| 2069 | 5) if the machine is not in an infinite loop endMacrostep is called | - | ||||||||||||||||||
| 2070 | 6) when the machine is finished and all processing (like signal emission) is done, | - | ||||||||||||||||||
| 2071 | exitInterpreter() is called. (This is the same name as the SCXML specification uses.) | - | ||||||||||||||||||
| 2072 | - | |||||||||||||||||||
| 2073 | didChange is set to true if at least one microstep was performed, it is possible | - | ||||||||||||||||||
| 2074 | that the machine returned to exactly the same state as before, but some transitions | - | ||||||||||||||||||
| 2075 | were triggered. | - | ||||||||||||||||||
| 2076 | - | |||||||||||||||||||
| 2077 | The default implementation does nothing. | - | ||||||||||||||||||
| 2078 | */ | - | ||||||||||||||||||
| 2079 | void QStateMachinePrivate::processedPendingEvents(bool didChange) | - | ||||||||||||||||||
| 2080 | { | - | ||||||||||||||||||
| 2081 | Q_UNUSED(didChange); | - | ||||||||||||||||||
| 2082 | } executed 291 times by 2 tests: end of blockExecuted by:
| 291 | ||||||||||||||||||
| 2083 | - | |||||||||||||||||||
| 2084 | void QStateMachinePrivate::beginMacrostep() | - | ||||||||||||||||||
| 2085 | { } | - | ||||||||||||||||||
| 2086 | - | |||||||||||||||||||
| 2087 | void QStateMachinePrivate::endMacrostep(bool didChange) | - | ||||||||||||||||||
| 2088 | { | - | ||||||||||||||||||
| 2089 | Q_UNUSED(didChange); | - | ||||||||||||||||||
| 2090 | } executed 374 times by 2 tests: end of blockExecuted by:
| 374 | ||||||||||||||||||
| 2091 | - | |||||||||||||||||||
| 2092 | void QStateMachinePrivate::exitInterpreter() | - | ||||||||||||||||||
| 2093 | { | - | ||||||||||||||||||
| 2094 | } | - | ||||||||||||||||||
| 2095 | - | |||||||||||||||||||
| 2096 | void QStateMachinePrivate::emitStateFinished(QState *forState, QFinalState *guiltyState) | - | ||||||||||||||||||
| 2097 | { | - | ||||||||||||||||||
| 2098 | Q_UNUSED(guiltyState); | - | ||||||||||||||||||
| 2099 | Q_ASSERT(guiltyState); | - | ||||||||||||||||||
| 2100 | - | |||||||||||||||||||
| 2101 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2102 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2103 | qDebug() << q << ": emitting finished signal for" << forState; | - | ||||||||||||||||||
| 2104 | #endif | - | ||||||||||||||||||
| 2105 | - | |||||||||||||||||||
| 2106 | QStatePrivate::get(forState)->emitFinished(); | - | ||||||||||||||||||
| 2107 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 2108 | - | |||||||||||||||||||
| 2109 | void QStateMachinePrivate::startupHook() | - | ||||||||||||||||||
| 2110 | { | - | ||||||||||||||||||
| 2111 | } | - | ||||||||||||||||||
| 2112 | - | |||||||||||||||||||
| 2113 | namespace _QStateMachine_Internal{ | - | ||||||||||||||||||
| 2114 | - | |||||||||||||||||||
| 2115 | class GoToStateTransition : public QAbstractTransition | - | ||||||||||||||||||
| 2116 | { | - | ||||||||||||||||||
| 2117 | Q_OBJECT | - | ||||||||||||||||||
| 2118 | public: | - | ||||||||||||||||||
| 2119 | GoToStateTransition(QAbstractState *target) | - | ||||||||||||||||||
| 2120 | : QAbstractTransition() | - | ||||||||||||||||||
| 2121 | { setTargetState(target); } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 2122 | protected: | - | ||||||||||||||||||
| 2123 | void onTransition(QEvent *) Q_DECL_OVERRIDE { deleteLater(); } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 2124 | bool eventTest(QEvent *) Q_DECL_OVERRIDE { return true; } executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 2125 | }; | - | ||||||||||||||||||
| 2126 | - | |||||||||||||||||||
| 2127 | } // namespace | - | ||||||||||||||||||
| 2128 | // mingw compiler tries to export QObject::findChild<GoToStateTransition>(), | - | ||||||||||||||||||
| 2129 | // which doesn't work if its in an anonymous namespace. | - | ||||||||||||||||||
| 2130 | using namespace _QStateMachine_Internal; | - | ||||||||||||||||||
| 2131 | /*! | - | ||||||||||||||||||
| 2132 | \internal | - | ||||||||||||||||||
| 2133 | - | |||||||||||||||||||
| 2134 | Causes this state machine to unconditionally transition to the given | - | ||||||||||||||||||
| 2135 | \a targetState. | - | ||||||||||||||||||
| 2136 | - | |||||||||||||||||||
| 2137 | Provides a backdoor for using the state machine "imperatively"; i.e. rather | - | ||||||||||||||||||
| 2138 | than defining explicit transitions, you drive the machine's execution by | - | ||||||||||||||||||
| 2139 | calling this function. It breaks the whole integrity of the | - | ||||||||||||||||||
| 2140 | transition-driven model, but is provided for pragmatic reasons. | - | ||||||||||||||||||
| 2141 | */ | - | ||||||||||||||||||
| 2142 | void QStateMachinePrivate::goToState(QAbstractState *targetState) | - | ||||||||||||||||||
| 2143 | { | - | ||||||||||||||||||
| 2144 | if (!targetState) {
| 0-7 | ||||||||||||||||||
| 2145 | qWarning("QStateMachine::goToState(): cannot go to null state"); | - | ||||||||||||||||||
| 2146 | return; never executed: return; | 0 | ||||||||||||||||||
| 2147 | } | - | ||||||||||||||||||
| 2148 | - | |||||||||||||||||||
| 2149 | if (configuration.contains(targetState))
| 2-5 | ||||||||||||||||||
| 2150 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 2151 | - | |||||||||||||||||||
| 2152 | Q_ASSERT(state == Running); | - | ||||||||||||||||||
| 2153 | QState *sourceState = 0; | - | ||||||||||||||||||
| 2154 | QSet<QAbstractState*>::const_iterator it; | - | ||||||||||||||||||
| 2155 | for (it = configuration.constBegin(); it != configuration.constEnd(); ++it) {
| 0-5 | ||||||||||||||||||
| 2156 | sourceState = toStandardState(*it); | - | ||||||||||||||||||
| 2157 | if (sourceState != 0)
| 0-5 | ||||||||||||||||||
| 2158 | break; executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||
| 2159 | } never executed: end of block | 0 | ||||||||||||||||||
| 2160 | - | |||||||||||||||||||
| 2161 | Q_ASSERT(sourceState != 0); | - | ||||||||||||||||||
| 2162 | // Reuse previous GoToStateTransition in case of several calls to | - | ||||||||||||||||||
| 2163 | // goToState() in a row. | - | ||||||||||||||||||
| 2164 | GoToStateTransition *trans = sourceState->findChild<GoToStateTransition*>(); | - | ||||||||||||||||||
| 2165 | if (!trans) {
| 1-4 | ||||||||||||||||||
| 2166 | trans = new GoToStateTransition(targetState); | - | ||||||||||||||||||
| 2167 | sourceState->addTransition(trans); | - | ||||||||||||||||||
| 2168 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 2169 | trans->setTargetState(targetState); | - | ||||||||||||||||||
| 2170 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2171 | - | |||||||||||||||||||
| 2172 | processEvents(QueuedProcessing); | - | ||||||||||||||||||
| 2173 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 2174 | - | |||||||||||||||||||
| 2175 | void QStateMachinePrivate::registerTransitions(QAbstractState *state) | - | ||||||||||||||||||
| 2176 | { | - | ||||||||||||||||||
| 2177 | QState *group = toStandardState(state); | - | ||||||||||||||||||
| 2178 | if (!group)
| 72-1435 | ||||||||||||||||||
| 2179 | return; executed 72 times by 1 test: return;Executed by:
| 72 | ||||||||||||||||||
| 2180 | QList<QAbstractTransition*> transitions = QStatePrivate::get(group)->transitions(); | - | ||||||||||||||||||
| 2181 | for (int i = 0; i < transitions.size(); ++i) {
| 1435-2314 | ||||||||||||||||||
| 2182 | QAbstractTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 2183 | registerTransition(t); | - | ||||||||||||||||||
| 2184 | } executed 2314 times by 2 tests: end of blockExecuted by:
| 2314 | ||||||||||||||||||
| 2185 | } executed 1435 times by 2 tests: end of blockExecuted by:
| 1435 | ||||||||||||||||||
| 2186 | - | |||||||||||||||||||
| 2187 | void QStateMachinePrivate::maybeRegisterTransition(QAbstractTransition *transition) | - | ||||||||||||||||||
| 2188 | { | - | ||||||||||||||||||
| 2189 | if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
| 70-154 | ||||||||||||||||||
| 2190 | maybeRegisterSignalTransition(st); | - | ||||||||||||||||||
| 2191 | } executed 70 times by 2 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 2192 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2193 | else if (QEventTransition *et = qobject_cast<QEventTransition*>(transition)) {
| 16-138 | ||||||||||||||||||
| 2194 | maybeRegisterEventTransition(et); | - | ||||||||||||||||||
| 2195 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 2196 | #endif | - | ||||||||||||||||||
| 2197 | } executed 224 times by 2 tests: end of blockExecuted by:
| 224 | ||||||||||||||||||
| 2198 | - | |||||||||||||||||||
| 2199 | void QStateMachinePrivate::registerTransition(QAbstractTransition *transition) | - | ||||||||||||||||||
| 2200 | { | - | ||||||||||||||||||
| 2201 | if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
| 1083-1231 | ||||||||||||||||||
| 2202 | registerSignalTransition(st); | - | ||||||||||||||||||
| 2203 | } executed 1083 times by 2 tests: end of blockExecuted by:
| 1083 | ||||||||||||||||||
| 2204 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2205 | else if (QEventTransition *oet = qobject_cast<QEventTransition*>(transition)) {
| 20-1211 | ||||||||||||||||||
| 2206 | registerEventTransition(oet); | - | ||||||||||||||||||
| 2207 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 2208 | #endif | - | ||||||||||||||||||
| 2209 | } executed 2314 times by 2 tests: end of blockExecuted by:
| 2314 | ||||||||||||||||||
| 2210 | - | |||||||||||||||||||
| 2211 | void QStateMachinePrivate::unregisterTransition(QAbstractTransition *transition) | - | ||||||||||||||||||
| 2212 | { | - | ||||||||||||||||||
| 2213 | if (QSignalTransition *st = qobject_cast<QSignalTransition*>(transition)) {
| 2-3 | ||||||||||||||||||
| 2214 | unregisterSignalTransition(st); | - | ||||||||||||||||||
| 2215 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2216 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2217 | else if (QEventTransition *oet = qobject_cast<QEventTransition*>(transition)) {
| 1-2 | ||||||||||||||||||
| 2218 | unregisterEventTransition(oet); | - | ||||||||||||||||||
| 2219 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2220 | #endif | - | ||||||||||||||||||
| 2221 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 2222 | - | |||||||||||||||||||
| 2223 | void QStateMachinePrivate::maybeRegisterSignalTransition(QSignalTransition *transition) | - | ||||||||||||||||||
| 2224 | { | - | ||||||||||||||||||
| 2225 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2226 | if ((state == Running) && (configuration.contains(transition->sourceState())
| 1-200012 | ||||||||||||||||||
| 2227 | || (transition->senderObject() && (transition->senderObject()->thread() != q->thread())))) {
| 0-1 | ||||||||||||||||||
| 2228 | registerSignalTransition(transition); | - | ||||||||||||||||||
| 2229 | } executed 200011 times by 1 test: end of blockExecuted by:
| 200011 | ||||||||||||||||||
| 2230 | } executed 200080 times by 2 tests: end of blockExecuted by:
| 200080 | ||||||||||||||||||
| 2231 | - | |||||||||||||||||||
| 2232 | void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transition) | - | ||||||||||||||||||
| 2233 | { | - | ||||||||||||||||||
| 2234 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2235 | if (QSignalTransitionPrivate::get(transition)->signalIndex != -1)
| 1011-200090 | ||||||||||||||||||
| 2236 | return; // already registered executed 1011 times by 1 test: return;Executed by:
| 1011 | ||||||||||||||||||
| 2237 | const QObject *sender = QSignalTransitionPrivate::get(transition)->sender; | - | ||||||||||||||||||
| 2238 | if (!sender)
| 100003-100087 | ||||||||||||||||||
| 2239 | return; executed 100003 times by 1 test: return;Executed by:
| 100003 | ||||||||||||||||||
| 2240 | QByteArray signal = QSignalTransitionPrivate::get(transition)->signal; | - | ||||||||||||||||||
| 2241 | if (signal.isEmpty())
| 1-100086 | ||||||||||||||||||
| 2242 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2243 | if (signal.startsWith('0'+QSIGNAL_CODE))
| 2-100084 | ||||||||||||||||||
| 2244 | signal.remove(0, 1); executed 100084 times by 2 tests: signal.remove(0, 1);Executed by:
| 100084 | ||||||||||||||||||
| 2245 | const QMetaObject *meta = sender->metaObject(); | - | ||||||||||||||||||
| 2246 | int signalIndex = meta->indexOfSignal(signal); | - | ||||||||||||||||||
| 2247 | int originalSignalIndex = signalIndex; | - | ||||||||||||||||||
| 2248 | if (signalIndex == -1) {
| 1-100085 | ||||||||||||||||||
| 2249 | signalIndex = meta->indexOfSignal(QMetaObject::normalizedSignature(signal)); | - | ||||||||||||||||||
| 2250 | if (signalIndex == -1) {
| 0-1 | ||||||||||||||||||
| 2251 | qWarning("QSignalTransition: no such signal: %s::%s", | - | ||||||||||||||||||
| 2252 | meta->className(), signal.constData()); | - | ||||||||||||||||||
| 2253 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2254 | } | - | ||||||||||||||||||
| 2255 | originalSignalIndex = signalIndex; | - | ||||||||||||||||||
| 2256 | } never executed: end of block | 0 | ||||||||||||||||||
| 2257 | // The signal index we actually want to connect to is the one | - | ||||||||||||||||||
| 2258 | // that is going to be sent, i.e. the non-cloned original index. | - | ||||||||||||||||||
| 2259 | while (meta->method(signalIndex).attributes() & QMetaMethod::Cloned)
| 2-100085 | ||||||||||||||||||
| 2260 | --signalIndex; executed 2 times by 1 test: --signalIndex;Executed by:
| 2 | ||||||||||||||||||
| 2261 | - | |||||||||||||||||||
| 2262 | connectionsMutex.lock(); | - | ||||||||||||||||||
| 2263 | QVector<int> &connectedSignalIndexes = connections[sender]; | - | ||||||||||||||||||
| 2264 | if (connectedSignalIndexes.size() <= signalIndex)
| 13-100072 | ||||||||||||||||||
| 2265 | connectedSignalIndexes.resize(signalIndex+1); executed 100072 times by 2 tests: connectedSignalIndexes.resize(signalIndex+1);Executed by:
| 100072 | ||||||||||||||||||
| 2266 | if (connectedSignalIndexes.at(signalIndex) == 0) {
| 12-100073 | ||||||||||||||||||
| 2267 | if (!signalEventGenerator)
| 43-100030 | ||||||||||||||||||
| 2268 | signalEventGenerator = new QSignalEventGenerator(q); executed 43 times by 2 tests: signalEventGenerator = new QSignalEventGenerator(q);Executed by:
| 43 | ||||||||||||||||||
| 2269 | static const int generatorMethodOffset = QSignalEventGenerator::staticMetaObject.methodOffset(); | - | ||||||||||||||||||
| 2270 | bool ok = QMetaObject::connect(sender, signalIndex, signalEventGenerator, generatorMethodOffset); | - | ||||||||||||||||||
| 2271 | if (!ok) {
| 0-100073 | ||||||||||||||||||
| 2272 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2273 | qDebug() << q << ": FAILED to add signal transition from" << transition->sourceState() | - | ||||||||||||||||||
| 2274 | << ": ( sender =" << sender << ", signal =" << signal | - | ||||||||||||||||||
| 2275 | << ", targets =" << transition->targetStates() << ')'; | - | ||||||||||||||||||
| 2276 | #endif | - | ||||||||||||||||||
| 2277 | return; never executed: return; | 0 | ||||||||||||||||||
| 2278 | } | - | ||||||||||||||||||
| 2279 | } executed 100073 times by 2 tests: end of blockExecuted by:
| 100073 | ||||||||||||||||||
| 2280 | ++connectedSignalIndexes[signalIndex]; | - | ||||||||||||||||||
| 2281 | connectionsMutex.unlock(); | - | ||||||||||||||||||
| 2282 | - | |||||||||||||||||||
| 2283 | QSignalTransitionPrivate::get(transition)->signalIndex = signalIndex; | - | ||||||||||||||||||
| 2284 | QSignalTransitionPrivate::get(transition)->originalSignalIndex = originalSignalIndex; | - | ||||||||||||||||||
| 2285 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2286 | qDebug() << q << ": added signal transition from" << transition->sourceState() | - | ||||||||||||||||||
| 2287 | << ": ( sender =" << sender << ", signal =" << signal | - | ||||||||||||||||||
| 2288 | << ", targets =" << transition->targetStates() << ')'; | - | ||||||||||||||||||
| 2289 | #endif | - | ||||||||||||||||||
| 2290 | } executed 100085 times by 2 tests: end of blockExecuted by:
| 100085 | ||||||||||||||||||
| 2291 | - | |||||||||||||||||||
| 2292 | void QStateMachinePrivate::unregisterSignalTransition(QSignalTransition *transition) | - | ||||||||||||||||||
| 2293 | { | - | ||||||||||||||||||
| 2294 | int signalIndex = QSignalTransitionPrivate::get(transition)->signalIndex; | - | ||||||||||||||||||
| 2295 | if (signalIndex == -1)
| 0-100049 | ||||||||||||||||||
| 2296 | return; // not registered never executed: return; | 0 | ||||||||||||||||||
| 2297 | const QObject *sender = QSignalTransitionPrivate::get(transition)->sender; | - | ||||||||||||||||||
| 2298 | QSignalTransitionPrivate::get(transition)->signalIndex = -1; | - | ||||||||||||||||||
| 2299 | - | |||||||||||||||||||
| 2300 | connectionsMutex.lock(); | - | ||||||||||||||||||
| 2301 | QVector<int> &connectedSignalIndexes = connections[sender]; | - | ||||||||||||||||||
| 2302 | Q_ASSERT(connectedSignalIndexes.size() > signalIndex); | - | ||||||||||||||||||
| 2303 | Q_ASSERT(connectedSignalIndexes.at(signalIndex) != 0); | - | ||||||||||||||||||
| 2304 | if (--connectedSignalIndexes[signalIndex] == 0) {
| 1-100048 | ||||||||||||||||||
| 2305 | Q_ASSERT(signalEventGenerator != 0); | - | ||||||||||||||||||
| 2306 | static const int generatorMethodOffset = QSignalEventGenerator::staticMetaObject.methodOffset(); | - | ||||||||||||||||||
| 2307 | QMetaObject::disconnect(sender, signalIndex, signalEventGenerator, generatorMethodOffset); | - | ||||||||||||||||||
| 2308 | int sum = 0; | - | ||||||||||||||||||
| 2309 | for (int i = 0; i < connectedSignalIndexes.size(); ++i)
| 100048-300412 | ||||||||||||||||||
| 2310 | sum += connectedSignalIndexes.at(i); executed 300412 times by 1 test: sum += connectedSignalIndexes.at(i);Executed by:
| 300412 | ||||||||||||||||||
| 2311 | if (sum == 0)
| 10-100038 | ||||||||||||||||||
| 2312 | connections.remove(sender); executed 100038 times by 1 test: connections.remove(sender);Executed by:
| 100038 | ||||||||||||||||||
| 2313 | } executed 100048 times by 1 test: end of blockExecuted by:
| 100048 | ||||||||||||||||||
| 2314 | connectionsMutex.unlock(); | - | ||||||||||||||||||
| 2315 | } executed 100049 times by 1 test: end of blockExecuted by:
| 100049 | ||||||||||||||||||
| 2316 | - | |||||||||||||||||||
| 2317 | void QStateMachinePrivate::unregisterAllTransitions() | - | ||||||||||||||||||
| 2318 | { | - | ||||||||||||||||||
| 2319 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2320 | { | - | ||||||||||||||||||
| 2321 | QList<QSignalTransition*> transitions = rootState()->findChildren<QSignalTransition*>(); | - | ||||||||||||||||||
| 2322 | for (int i = 0; i < transitions.size(); ++i) {
| 47-85 | ||||||||||||||||||
| 2323 | QSignalTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 2324 | if (t->machine() == q)
| 3-44 | ||||||||||||||||||
| 2325 | unregisterSignalTransition(t); executed 44 times by 1 test: unregisterSignalTransition(t);Executed by:
| 44 | ||||||||||||||||||
| 2326 | } executed 47 times by 1 test: end of blockExecuted by:
| 47 | ||||||||||||||||||
| 2327 | } | - | ||||||||||||||||||
| 2328 | { | - | ||||||||||||||||||
| 2329 | QList<QEventTransition*> transitions = rootState()->findChildren<QEventTransition*>(); | - | ||||||||||||||||||
| 2330 | for (int i = 0; i < transitions.size(); ++i) {
| 15-85 | ||||||||||||||||||
| 2331 | QEventTransition *t = transitions.at(i); | - | ||||||||||||||||||
| 2332 | if (t->machine() == q)
| 0-15 | ||||||||||||||||||
| 2333 | unregisterEventTransition(t); executed 15 times by 1 test: unregisterEventTransition(t);Executed by:
| 15 | ||||||||||||||||||
| 2334 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 2335 | } | - | ||||||||||||||||||
| 2336 | } executed 85 times by 1 test: end of blockExecuted by:
| 85 | ||||||||||||||||||
| 2337 | - | |||||||||||||||||||
| 2338 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2339 | void QStateMachinePrivate::maybeRegisterEventTransition(QEventTransition *transition) | - | ||||||||||||||||||
| 2340 | { | - | ||||||||||||||||||
| 2341 | if ((state == Running) && configuration.contains(transition->sourceState()))
| 1-15 | ||||||||||||||||||
| 2342 | registerEventTransition(transition); executed 7 times by 1 test: registerEventTransition(transition);Executed by:
| 7 | ||||||||||||||||||
| 2343 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 2344 | - | |||||||||||||||||||
| 2345 | void QStateMachinePrivate::registerEventTransition(QEventTransition *transition) | - | ||||||||||||||||||
| 2346 | { | - | ||||||||||||||||||
| 2347 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2348 | if (QEventTransitionPrivate::get(transition)->registered)
| 0-27 | ||||||||||||||||||
| 2349 | return; never executed: return; | 0 | ||||||||||||||||||
| 2350 | if (transition->eventType() >= QEvent::User) {
| 1-26 | ||||||||||||||||||
| 2351 | qWarning("QObject event transitions are not supported for custom types"); | - | ||||||||||||||||||
| 2352 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2353 | } | - | ||||||||||||||||||
| 2354 | QObject *object = QEventTransitionPrivate::get(transition)->object; | - | ||||||||||||||||||
| 2355 | if (!object)
| 0-26 | ||||||||||||||||||
| 2356 | return; never executed: return; | 0 | ||||||||||||||||||
| 2357 | QObjectPrivate *od = QObjectPrivate::get(object); | - | ||||||||||||||||||
| 2358 | if (!od->extraData || !od->extraData->eventFilters.contains(q))
| 5-21 | ||||||||||||||||||
| 2359 | object->installEventFilter(q); executed 19 times by 1 test: object->installEventFilter(q);Executed by:
| 19 | ||||||||||||||||||
| 2360 | ++qobjectEvents[object][transition->eventType()]; | - | ||||||||||||||||||
| 2361 | QEventTransitionPrivate::get(transition)->registered = true; | - | ||||||||||||||||||
| 2362 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2363 | qDebug() << q << ": added event transition from" << transition->sourceState() | - | ||||||||||||||||||
| 2364 | << ": ( object =" << object << ", event =" << transition->eventType() | - | ||||||||||||||||||
| 2365 | << ", targets =" << transition->targetStates() << ')'; | - | ||||||||||||||||||
| 2366 | #endif | - | ||||||||||||||||||
| 2367 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 2368 | - | |||||||||||||||||||
| 2369 | void QStateMachinePrivate::unregisterEventTransition(QEventTransition *transition) | - | ||||||||||||||||||
| 2370 | { | - | ||||||||||||||||||
| 2371 | Q_Q(QStateMachine); | - | ||||||||||||||||||
| 2372 | if (!QEventTransitionPrivate::get(transition)->registered)
| 0-20 | ||||||||||||||||||
| 2373 | return; never executed: return; | 0 | ||||||||||||||||||
| 2374 | QObject *object = QEventTransitionPrivate::get(transition)->object; | - | ||||||||||||||||||
| 2375 | QHash<QEvent::Type, int> &events = qobjectEvents[object]; | - | ||||||||||||||||||
| 2376 | Q_ASSERT(events.value(transition->eventType()) > 0); | - | ||||||||||||||||||
| 2377 | if (--events[transition->eventType()] == 0) {
| 1-19 | ||||||||||||||||||
| 2378 | events.remove(transition->eventType()); | - | ||||||||||||||||||
| 2379 | int sum = 0; | - | ||||||||||||||||||
| 2380 | QHash<QEvent::Type, int>::const_iterator it; | - | ||||||||||||||||||
| 2381 | for (it = events.constBegin(); it != events.constEnd(); ++it)
| 3-19 | ||||||||||||||||||
| 2382 | sum += it.value(); executed 3 times by 1 test: sum += it.value();Executed by:
| 3 | ||||||||||||||||||
| 2383 | if (sum == 0) {
| 3-16 | ||||||||||||||||||
| 2384 | qobjectEvents.remove(object); | - | ||||||||||||||||||
| 2385 | object->removeEventFilter(q); | - | ||||||||||||||||||
| 2386 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 2387 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||
| 2388 | QEventTransitionPrivate::get(transition)->registered = false; | - | ||||||||||||||||||
| 2389 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 2390 | - | |||||||||||||||||||
| 2391 | void QStateMachinePrivate::handleFilteredEvent(QObject *watched, QEvent *event) | - | ||||||||||||||||||
| 2392 | { | - | ||||||||||||||||||
| 2393 | if (qobjectEvents.value(watched).contains(event->type())) {
| 2-25 | ||||||||||||||||||
| 2394 | postInternalEvent(new QStateMachine::WrappedEvent(watched, handler->cloneEvent(event))); | - | ||||||||||||||||||
| 2395 | processEvents(DirectProcessing); | - | ||||||||||||||||||
| 2396 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 2397 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 2398 | #endif | - | ||||||||||||||||||
| 2399 | - | |||||||||||||||||||
| 2400 | void QStateMachinePrivate::handleTransitionSignal(QObject *sender, int signalIndex, | - | ||||||||||||||||||
| 2401 | void **argv) | - | ||||||||||||||||||
| 2402 | { | - | ||||||||||||||||||
| 2403 | #ifndef QT_NO_DEBUG | - | ||||||||||||||||||
| 2404 | connectionsMutex.lock(); | - | ||||||||||||||||||
| 2405 | Q_ASSERT(connections[sender].at(signalIndex) != 0); | - | ||||||||||||||||||
| 2406 | connectionsMutex.unlock(); | - | ||||||||||||||||||
| 2407 | #endif | - | ||||||||||||||||||
| 2408 | const QMetaObject *meta = sender->metaObject(); | - | ||||||||||||||||||
| 2409 | QMetaMethod method = meta->method(signalIndex); | - | ||||||||||||||||||
| 2410 | int argc = method.parameterCount(); | - | ||||||||||||||||||
| 2411 | QList<QVariant> vargs; | - | ||||||||||||||||||
| 2412 | vargs.reserve(argc); | - | ||||||||||||||||||
| 2413 | for (int i = 0; i < argc; ++i) {
| 10-70 | ||||||||||||||||||
| 2414 | int type = method.parameterType(i); | - | ||||||||||||||||||
| 2415 | vargs.append(QVariant(type, argv[i+1])); | - | ||||||||||||||||||
| 2416 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 2417 | - | |||||||||||||||||||
| 2418 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2419 | qDebug() << q_func() << ": sending signal event ( sender =" << sender | - | ||||||||||||||||||
| 2420 | << ", signal =" << method.methodSignature().constData() << ')'; | - | ||||||||||||||||||
| 2421 | #endif | - | ||||||||||||||||||
| 2422 | postInternalEvent(new QStateMachine::SignalEvent(sender, signalIndex, vargs)); | - | ||||||||||||||||||
| 2423 | processEvents(DirectProcessing); | - | ||||||||||||||||||
| 2424 | } executed 70 times by 2 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 2425 | - | |||||||||||||||||||
| 2426 | /*! | - | ||||||||||||||||||
| 2427 | Constructs a new state machine with the given \a parent. | - | ||||||||||||||||||
| 2428 | */ | - | ||||||||||||||||||
| 2429 | QStateMachine::QStateMachine(QObject *parent) | - | ||||||||||||||||||
| 2430 | : QState(*new QStateMachinePrivate, /*parentState=*/0) | - | ||||||||||||||||||
| 2431 | { | - | ||||||||||||||||||
| 2432 | // Can't pass the parent to the QState constructor, as it expects a QState | - | ||||||||||||||||||
| 2433 | // But this works as expected regardless of whether parent is a QState or not | - | ||||||||||||||||||
| 2434 | setParent(parent); | - | ||||||||||||||||||
| 2435 | } executed 139 times by 2 tests: end of blockExecuted by:
| 139 | ||||||||||||||||||
| 2436 | - | |||||||||||||||||||
| 2437 | /*! | - | ||||||||||||||||||
| 2438 | \since 5.0 | - | ||||||||||||||||||
| 2439 | - | |||||||||||||||||||
| 2440 | Constructs a new state machine with the given \a childMode | - | ||||||||||||||||||
| 2441 | and \a parent. | - | ||||||||||||||||||
| 2442 | */ | - | ||||||||||||||||||
| 2443 | QStateMachine::QStateMachine(QState::ChildMode childMode, QObject *parent) | - | ||||||||||||||||||
| 2444 | : QState(*new QStateMachinePrivate, /*parentState=*/0) | - | ||||||||||||||||||
| 2445 | { | - | ||||||||||||||||||
| 2446 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2447 | d->childMode = childMode; | - | ||||||||||||||||||
| 2448 | setParent(parent); // See comment in constructor above | - | ||||||||||||||||||
| 2449 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 2450 | - | |||||||||||||||||||
| 2451 | /*! | - | ||||||||||||||||||
| 2452 | \internal | - | ||||||||||||||||||
| 2453 | */ | - | ||||||||||||||||||
| 2454 | QStateMachine::QStateMachine(QStateMachinePrivate &dd, QObject *parent) | - | ||||||||||||||||||
| 2455 | : QState(dd, /*parentState=*/0) | - | ||||||||||||||||||
| 2456 | { | - | ||||||||||||||||||
| 2457 | setParent(parent); | - | ||||||||||||||||||
| 2458 | } never executed: end of block | 0 | ||||||||||||||||||
| 2459 | - | |||||||||||||||||||
| 2460 | /*! | - | ||||||||||||||||||
| 2461 | Destroys this state machine. | - | ||||||||||||||||||
| 2462 | */ | - | ||||||||||||||||||
| 2463 | QStateMachine::~QStateMachine() | - | ||||||||||||||||||
| 2464 | { | - | ||||||||||||||||||
| 2465 | } | - | ||||||||||||||||||
| 2466 | - | |||||||||||||||||||
| 2467 | /*! | - | ||||||||||||||||||
| 2468 | \enum QStateMachine::EventPriority | - | ||||||||||||||||||
| 2469 | - | |||||||||||||||||||
| 2470 | This enum type specifies the priority of an event posted to the state | - | ||||||||||||||||||
| 2471 | machine using postEvent(). | - | ||||||||||||||||||
| 2472 | - | |||||||||||||||||||
| 2473 | Events of high priority are processed before events of normal priority. | - | ||||||||||||||||||
| 2474 | - | |||||||||||||||||||
| 2475 | \value NormalPriority The event has normal priority. | - | ||||||||||||||||||
| 2476 | \value HighPriority The event has high priority. | - | ||||||||||||||||||
| 2477 | */ | - | ||||||||||||||||||
| 2478 | - | |||||||||||||||||||
| 2479 | /*! \enum QStateMachine::Error | - | ||||||||||||||||||
| 2480 | - | |||||||||||||||||||
| 2481 | This enum type defines errors that can occur in the state machine at run time. When the state | - | ||||||||||||||||||
| 2482 | machine encounters an unrecoverable error at run time, it will set the error code returned | - | ||||||||||||||||||
| 2483 | by error(), the error message returned by errorString(), and enter an error state based on | - | ||||||||||||||||||
| 2484 | the context of the error. | - | ||||||||||||||||||
| 2485 | - | |||||||||||||||||||
| 2486 | \value NoError No error has occurred. | - | ||||||||||||||||||
| 2487 | \value NoInitialStateError The machine has entered a QState with children which does not have an | - | ||||||||||||||||||
| 2488 | initial state set. The context of this error is the state which is missing an initial | - | ||||||||||||||||||
| 2489 | state. | - | ||||||||||||||||||
| 2490 | \value NoDefaultStateInHistoryStateError The machine has entered a QHistoryState which does not have | - | ||||||||||||||||||
| 2491 | a default state set. The context of this error is the QHistoryState which is missing a | - | ||||||||||||||||||
| 2492 | default state. | - | ||||||||||||||||||
| 2493 | \value NoCommonAncestorForTransitionError The machine has selected a transition whose source | - | ||||||||||||||||||
| 2494 | and targets are not part of the same tree of states, and thus are not part of the same | - | ||||||||||||||||||
| 2495 | state machine. Commonly, this could mean that one of the states has not been given | - | ||||||||||||||||||
| 2496 | any parent or added to any machine. The context of this error is the source state of | - | ||||||||||||||||||
| 2497 | the transition. | - | ||||||||||||||||||
| 2498 | - | |||||||||||||||||||
| 2499 | \sa setErrorState() | - | ||||||||||||||||||
| 2500 | */ | - | ||||||||||||||||||
| 2501 | - | |||||||||||||||||||
| 2502 | /*! | - | ||||||||||||||||||
| 2503 | Returns the error code of the last error that occurred in the state machine. | - | ||||||||||||||||||
| 2504 | */ | - | ||||||||||||||||||
| 2505 | QStateMachine::Error QStateMachine::error() const | - | ||||||||||||||||||
| 2506 | { | - | ||||||||||||||||||
| 2507 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2508 | return d->error; executed 13 times by 1 test: return d->error;Executed by:
| 13 | ||||||||||||||||||
| 2509 | } | - | ||||||||||||||||||
| 2510 | - | |||||||||||||||||||
| 2511 | /*! | - | ||||||||||||||||||
| 2512 | Returns the error string of the last error that occurred in the state machine. | - | ||||||||||||||||||
| 2513 | */ | - | ||||||||||||||||||
| 2514 | QString QStateMachine::errorString() const | - | ||||||||||||||||||
| 2515 | { | - | ||||||||||||||||||
| 2516 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2517 | return d->errorString; executed 11 times by 1 test: return d->errorString;Executed by:
| 11 | ||||||||||||||||||
| 2518 | } | - | ||||||||||||||||||
| 2519 | - | |||||||||||||||||||
| 2520 | /*! | - | ||||||||||||||||||
| 2521 | Clears the error string and error code of the state machine. | - | ||||||||||||||||||
| 2522 | */ | - | ||||||||||||||||||
| 2523 | void QStateMachine::clearError() | - | ||||||||||||||||||
| 2524 | { | - | ||||||||||||||||||
| 2525 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2526 | d->errorString.clear(); | - | ||||||||||||||||||
| 2527 | d->error = NoError; | - | ||||||||||||||||||
| 2528 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2529 | - | |||||||||||||||||||
| 2530 | /*! | - | ||||||||||||||||||
| 2531 | Returns the restore policy of the state machine. | - | ||||||||||||||||||
| 2532 | - | |||||||||||||||||||
| 2533 | \sa setGlobalRestorePolicy() | - | ||||||||||||||||||
| 2534 | */ | - | ||||||||||||||||||
| 2535 | QState::RestorePolicy QStateMachine::globalRestorePolicy() const | - | ||||||||||||||||||
| 2536 | { | - | ||||||||||||||||||
| 2537 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2538 | return d->globalRestorePolicy; executed 1 time by 1 test: return d->globalRestorePolicy;Executed by:
| 1 | ||||||||||||||||||
| 2539 | } | - | ||||||||||||||||||
| 2540 | - | |||||||||||||||||||
| 2541 | /*! | - | ||||||||||||||||||
| 2542 | Sets the restore policy of the state machine to \a restorePolicy. The default | - | ||||||||||||||||||
| 2543 | restore policy is QState::DontRestoreProperties. | - | ||||||||||||||||||
| 2544 | - | |||||||||||||||||||
| 2545 | \sa globalRestorePolicy() | - | ||||||||||||||||||
| 2546 | */ | - | ||||||||||||||||||
| 2547 | void QStateMachine::setGlobalRestorePolicy(QState::RestorePolicy restorePolicy) | - | ||||||||||||||||||
| 2548 | { | - | ||||||||||||||||||
| 2549 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2550 | d->globalRestorePolicy = restorePolicy; | - | ||||||||||||||||||
| 2551 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 2552 | - | |||||||||||||||||||
| 2553 | /*! | - | ||||||||||||||||||
| 2554 | Adds the given \a state to this state machine. The state becomes a top-level | - | ||||||||||||||||||
| 2555 | state. | - | ||||||||||||||||||
| 2556 | - | |||||||||||||||||||
| 2557 | If the state is already in a different machine, it will first be removed | - | ||||||||||||||||||
| 2558 | from its old machine, and then added to this machine. | - | ||||||||||||||||||
| 2559 | - | |||||||||||||||||||
| 2560 | \sa removeState(), setInitialState() | - | ||||||||||||||||||
| 2561 | */ | - | ||||||||||||||||||
| 2562 | void QStateMachine::addState(QAbstractState *state) | - | ||||||||||||||||||
| 2563 | { | - | ||||||||||||||||||
| 2564 | if (!state) {
| 1-47 | ||||||||||||||||||
| 2565 | qWarning("QStateMachine::addState: cannot add null state"); | - | ||||||||||||||||||
| 2566 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2567 | } | - | ||||||||||||||||||
| 2568 | if (QAbstractStatePrivate::get(state)->machine() == this) {
| 2-45 | ||||||||||||||||||
| 2569 | qWarning("QStateMachine::addState: state has already been added to this machine"); | - | ||||||||||||||||||
| 2570 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 2571 | } | - | ||||||||||||||||||
| 2572 | state->setParent(this); | - | ||||||||||||||||||
| 2573 | } executed 45 times by 1 test: end of blockExecuted by:
| 45 | ||||||||||||||||||
| 2574 | - | |||||||||||||||||||
| 2575 | /*! | - | ||||||||||||||||||
| 2576 | Removes the given \a state from this state machine. The state machine | - | ||||||||||||||||||
| 2577 | releases ownership of the state. | - | ||||||||||||||||||
| 2578 | - | |||||||||||||||||||
| 2579 | \sa addState() | - | ||||||||||||||||||
| 2580 | */ | - | ||||||||||||||||||
| 2581 | void QStateMachine::removeState(QAbstractState *state) | - | ||||||||||||||||||
| 2582 | { | - | ||||||||||||||||||
| 2583 | if (!state) {
| 1-3 | ||||||||||||||||||
| 2584 | qWarning("QStateMachine::removeState: cannot remove null state"); | - | ||||||||||||||||||
| 2585 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2586 | } | - | ||||||||||||||||||
| 2587 | if (QAbstractStatePrivate::get(state)->machine() != this) {
| 1-2 | ||||||||||||||||||
| 2588 | qWarning("QStateMachine::removeState: state %p's machine (%p)" | - | ||||||||||||||||||
| 2589 | " is different from this machine (%p)", | - | ||||||||||||||||||
| 2590 | state, QAbstractStatePrivate::get(state)->machine(), this); | - | ||||||||||||||||||
| 2591 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||
| 2592 | } | - | ||||||||||||||||||
| 2593 | state->setParent(0); | - | ||||||||||||||||||
| 2594 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2595 | - | |||||||||||||||||||
| 2596 | bool QStateMachine::isRunning() const | - | ||||||||||||||||||
| 2597 | { | - | ||||||||||||||||||
| 2598 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2599 | return (d->state == QStateMachinePrivate::Running); executed 174 times by 1 test: return (d->state == QStateMachinePrivate::Running);Executed by:
| 174 | ||||||||||||||||||
| 2600 | } | - | ||||||||||||||||||
| 2601 | - | |||||||||||||||||||
| 2602 | /*! | - | ||||||||||||||||||
| 2603 | Starts this state machine. The machine will reset its configuration and | - | ||||||||||||||||||
| 2604 | transition to the initial state. When a final top-level state (QFinalState) | - | ||||||||||||||||||
| 2605 | is entered, the machine will emit the finished() signal. | - | ||||||||||||||||||
| 2606 | - | |||||||||||||||||||
| 2607 | \note A state machine will not run without a running event loop, such as | - | ||||||||||||||||||
| 2608 | the main application event loop started with QCoreApplication::exec() or | - | ||||||||||||||||||
| 2609 | QApplication::exec(). | - | ||||||||||||||||||
| 2610 | - | |||||||||||||||||||
| 2611 | \sa started(), finished(), stop(), initialState(), setRunning() | - | ||||||||||||||||||
| 2612 | */ | - | ||||||||||||||||||
| 2613 | void QStateMachine::start() | - | ||||||||||||||||||
| 2614 | { | - | ||||||||||||||||||
| 2615 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2616 | - | |||||||||||||||||||
| 2617 | if ((childMode() == QState::ExclusiveStates) && (initialState() == 0)) {
| 1-157 | ||||||||||||||||||
| 2618 | qWarning("QStateMachine::start: No initial state set for machine. Refusing to start."); | - | ||||||||||||||||||
| 2619 | return; executed 3 times by 1 test: return;Executed by:
| 3 | ||||||||||||||||||
| 2620 | } | - | ||||||||||||||||||
| 2621 | - | |||||||||||||||||||
| 2622 | switch (d->state) { | - | ||||||||||||||||||
| 2623 | case QStateMachinePrivate::NotRunning: executed 153 times by 2 tests: case QStateMachinePrivate::NotRunning:Executed by:
| 153 | ||||||||||||||||||
| 2624 | d->state = QStateMachinePrivate::Starting; | - | ||||||||||||||||||
| 2625 | QMetaObject::invokeMethod(this, "_q_start", Qt::QueuedConnection); | - | ||||||||||||||||||
| 2626 | break; executed 153 times by 2 tests: break;Executed by:
| 153 | ||||||||||||||||||
| 2627 | case QStateMachinePrivate::Starting: never executed: case QStateMachinePrivate::Starting: | 0 | ||||||||||||||||||
| 2628 | break; never executed: break; | 0 | ||||||||||||||||||
| 2629 | case QStateMachinePrivate::Running: executed 2 times by 1 test: case QStateMachinePrivate::Running:Executed by:
| 2 | ||||||||||||||||||
| 2630 | qWarning("QStateMachine::start(): already running"); | - | ||||||||||||||||||
| 2631 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 2632 | } | - | ||||||||||||||||||
| 2633 | } executed 155 times by 2 tests: end of blockExecuted by:
| 155 | ||||||||||||||||||
| 2634 | - | |||||||||||||||||||
| 2635 | /*! | - | ||||||||||||||||||
| 2636 | Stops this state machine. The state machine will stop processing events and | - | ||||||||||||||||||
| 2637 | then emit the stopped() signal. | - | ||||||||||||||||||
| 2638 | - | |||||||||||||||||||
| 2639 | \sa stopped(), start(), setRunning() | - | ||||||||||||||||||
| 2640 | */ | - | ||||||||||||||||||
| 2641 | void QStateMachine::stop() | - | ||||||||||||||||||
| 2642 | { | - | ||||||||||||||||||
| 2643 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2644 | switch (d->state) { | - | ||||||||||||||||||
| 2645 | case QStateMachinePrivate::NotRunning: executed 7 times by 1 test: case QStateMachinePrivate::NotRunning:Executed by:
| 7 | ||||||||||||||||||
| 2646 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||
| 2647 | case QStateMachinePrivate::Starting: never executed: case QStateMachinePrivate::Starting: | 0 | ||||||||||||||||||
| 2648 | // the machine will exit as soon as it enters the event processing loop | - | ||||||||||||||||||
| 2649 | d->stop = true; | - | ||||||||||||||||||
| 2650 | break; never executed: break; | 0 | ||||||||||||||||||
| 2651 | case QStateMachinePrivate::Running: executed 22 times by 1 test: case QStateMachinePrivate::Running:Executed by:
| 22 | ||||||||||||||||||
| 2652 | d->stop = true; | - | ||||||||||||||||||
| 2653 | d->processEvents(QStateMachinePrivate::QueuedProcessing); | - | ||||||||||||||||||
| 2654 | break; executed 22 times by 1 test: break;Executed by:
| 22 | ||||||||||||||||||
| 2655 | } | - | ||||||||||||||||||
| 2656 | } executed 29 times by 1 test: end of blockExecuted by:
| 29 | ||||||||||||||||||
| 2657 | - | |||||||||||||||||||
| 2658 | void QStateMachine::setRunning(bool running) | - | ||||||||||||||||||
| 2659 | { | - | ||||||||||||||||||
| 2660 | if (running)
| 4-5 | ||||||||||||||||||
| 2661 | start(); executed 4 times by 1 test: start();Executed by:
| 4 | ||||||||||||||||||
| 2662 | else | - | ||||||||||||||||||
| 2663 | stop(); executed 5 times by 1 test: stop();Executed by:
| 5 | ||||||||||||||||||
| 2664 | } | - | ||||||||||||||||||
| 2665 | - | |||||||||||||||||||
| 2666 | /*! | - | ||||||||||||||||||
| 2667 | \threadsafe | - | ||||||||||||||||||
| 2668 | - | |||||||||||||||||||
| 2669 | Posts the given \a event of the given \a priority for processing by this | - | ||||||||||||||||||
| 2670 | state machine. | - | ||||||||||||||||||
| 2671 | - | |||||||||||||||||||
| 2672 | This function returns immediately. The event is added to the state machine's | - | ||||||||||||||||||
| 2673 | event queue. Events are processed in the order posted. The state machine | - | ||||||||||||||||||
| 2674 | takes ownership of the event and deletes it once it has been processed. | - | ||||||||||||||||||
| 2675 | - | |||||||||||||||||||
| 2676 | You can only post events when the state machine is running or when it is starting up. | - | ||||||||||||||||||
| 2677 | - | |||||||||||||||||||
| 2678 | \sa postDelayedEvent() | - | ||||||||||||||||||
| 2679 | */ | - | ||||||||||||||||||
| 2680 | void QStateMachine::postEvent(QEvent *event, EventPriority priority) | - | ||||||||||||||||||
| 2681 | { | - | ||||||||||||||||||
| 2682 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2683 | switch (d->state) { | - | ||||||||||||||||||
| 2684 | case QStateMachinePrivate::Running: executed 2123 times by 2 tests: case QStateMachinePrivate::Running:Executed by:
| 2123 | ||||||||||||||||||
| 2685 | case QStateMachinePrivate::Starting: never executed: case QStateMachinePrivate::Starting: | 0 | ||||||||||||||||||
| 2686 | break; executed 2123 times by 2 tests: break;Executed by:
| 2123 | ||||||||||||||||||
| 2687 | default: executed 2 times by 1 test: default:Executed by:
| 2 | ||||||||||||||||||
| 2688 | qWarning("QStateMachine::postEvent: cannot post event when the state machine is not running"); | - | ||||||||||||||||||
| 2689 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 2690 | } | - | ||||||||||||||||||
| 2691 | if (!event) {
| 0-2123 | ||||||||||||||||||
| 2692 | qWarning("QStateMachine::postEvent: cannot post null event"); | - | ||||||||||||||||||
| 2693 | return; never executed: return; | 0 | ||||||||||||||||||
| 2694 | } | - | ||||||||||||||||||
| 2695 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2696 | qDebug() << this << ": posting event" << event; | - | ||||||||||||||||||
| 2697 | #endif | - | ||||||||||||||||||
| 2698 | switch (priority) { | - | ||||||||||||||||||
| 2699 | case NormalPriority: executed 2119 times by 2 tests: case NormalPriority:Executed by:
| 2119 | ||||||||||||||||||
| 2700 | d->postExternalEvent(event); | - | ||||||||||||||||||
| 2701 | break; executed 2119 times by 2 tests: break;Executed by:
| 2119 | ||||||||||||||||||
| 2702 | case HighPriority: executed 4 times by 1 test: case HighPriority:Executed by:
| 4 | ||||||||||||||||||
| 2703 | d->postInternalEvent(event); | - | ||||||||||||||||||
| 2704 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 2705 | } | - | ||||||||||||||||||
| 2706 | d->processEvents(QStateMachinePrivate::QueuedProcessing); | - | ||||||||||||||||||
| 2707 | } executed 2123 times by 2 tests: end of blockExecuted by:
| 2123 | ||||||||||||||||||
| 2708 | - | |||||||||||||||||||
| 2709 | /*! | - | ||||||||||||||||||
| 2710 | \threadsafe | - | ||||||||||||||||||
| 2711 | - | |||||||||||||||||||
| 2712 | Posts the given \a event for processing by this state machine, with the | - | ||||||||||||||||||
| 2713 | given \a delay in milliseconds. Returns an identifier associated with the | - | ||||||||||||||||||
| 2714 | delayed event, or -1 if the event could not be posted. | - | ||||||||||||||||||
| 2715 | - | |||||||||||||||||||
| 2716 | This function returns immediately. When the delay has expired, the event | - | ||||||||||||||||||
| 2717 | will be added to the state machine's event queue for processing. The state | - | ||||||||||||||||||
| 2718 | machine takes ownership of the event and deletes it once it has been | - | ||||||||||||||||||
| 2719 | processed. | - | ||||||||||||||||||
| 2720 | - | |||||||||||||||||||
| 2721 | You can only post events when the state machine is running. | - | ||||||||||||||||||
| 2722 | - | |||||||||||||||||||
| 2723 | \sa cancelDelayedEvent(), postEvent() | - | ||||||||||||||||||
| 2724 | */ | - | ||||||||||||||||||
| 2725 | int QStateMachine::postDelayedEvent(QEvent *event, int delay) | - | ||||||||||||||||||
| 2726 | { | - | ||||||||||||||||||
| 2727 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2728 | if (d->state != QStateMachinePrivate::Running) {
| 0-9 | ||||||||||||||||||
| 2729 | qWarning("QStateMachine::postDelayedEvent: cannot post event when the state machine is not running"); | - | ||||||||||||||||||
| 2730 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2731 | } | - | ||||||||||||||||||
| 2732 | if (!event) {
| 0-9 | ||||||||||||||||||
| 2733 | qWarning("QStateMachine::postDelayedEvent: cannot post null event"); | - | ||||||||||||||||||
| 2734 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2735 | } | - | ||||||||||||||||||
| 2736 | if (delay < 0) {
| 0-9 | ||||||||||||||||||
| 2737 | qWarning("QStateMachine::postDelayedEvent: delay cannot be negative"); | - | ||||||||||||||||||
| 2738 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2739 | } | - | ||||||||||||||||||
| 2740 | #ifdef QSTATEMACHINE_DEBUG | - | ||||||||||||||||||
| 2741 | qDebug() << this << ": posting event" << event << "with delay" << delay; | - | ||||||||||||||||||
| 2742 | #endif | - | ||||||||||||||||||
| 2743 | QMutexLocker locker(&d->delayedEventsMutex); | - | ||||||||||||||||||
| 2744 | int id = d->delayedEventIdFreeList.next(); | - | ||||||||||||||||||
| 2745 | bool inMachineThread = (QThread::currentThread() == thread()); | - | ||||||||||||||||||
| 2746 | int timerId = inMachineThread ? startTimer(delay) : 0;
| 2-7 | ||||||||||||||||||
| 2747 | if (inMachineThread && !timerId) {
| 0-7 | ||||||||||||||||||
| 2748 | qWarning("QStateMachine::postDelayedEvent: failed to start timer with interval %d", delay); | - | ||||||||||||||||||
| 2749 | d->delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 2750 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2751 | } | - | ||||||||||||||||||
| 2752 | QStateMachinePrivate::DelayedEvent delayedEvent(event, timerId); | - | ||||||||||||||||||
| 2753 | d->delayedEvents.insert(id, delayedEvent); | - | ||||||||||||||||||
| 2754 | if (timerId) {
| 2-7 | ||||||||||||||||||
| 2755 | d->timerIdToDelayedEventId.insert(timerId, id); | - | ||||||||||||||||||
| 2756 | } else { executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||
| 2757 | Q_ASSERT(!inMachineThread); | - | ||||||||||||||||||
| 2758 | QMetaObject::invokeMethod(this, "_q_startDelayedEventTimer", | - | ||||||||||||||||||
| 2759 | Qt::QueuedConnection, | - | ||||||||||||||||||
| 2760 | Q_ARG(int, id), | - | ||||||||||||||||||
| 2761 | Q_ARG(int, delay)); | - | ||||||||||||||||||
| 2762 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2763 | return id; executed 9 times by 1 test: return id;Executed by:
| 9 | ||||||||||||||||||
| 2764 | } | - | ||||||||||||||||||
| 2765 | - | |||||||||||||||||||
| 2766 | /*! | - | ||||||||||||||||||
| 2767 | \threadsafe | - | ||||||||||||||||||
| 2768 | - | |||||||||||||||||||
| 2769 | Cancels the delayed event identified by the given \a id. The id should be a | - | ||||||||||||||||||
| 2770 | value returned by a call to postDelayedEvent(). Returns \c true if the event | - | ||||||||||||||||||
| 2771 | was successfully cancelled, otherwise returns \c false. | - | ||||||||||||||||||
| 2772 | - | |||||||||||||||||||
| 2773 | \sa postDelayedEvent() | - | ||||||||||||||||||
| 2774 | */ | - | ||||||||||||||||||
| 2775 | bool QStateMachine::cancelDelayedEvent(int id) | - | ||||||||||||||||||
| 2776 | { | - | ||||||||||||||||||
| 2777 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2778 | if (d->state != QStateMachinePrivate::Running) {
| 1-5 | ||||||||||||||||||
| 2779 | qWarning("QStateMachine::cancelDelayedEvent: the machine is not running"); | - | ||||||||||||||||||
| 2780 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 2781 | } | - | ||||||||||||||||||
| 2782 | QMutexLocker locker(&d->delayedEventsMutex); | - | ||||||||||||||||||
| 2783 | QStateMachinePrivate::DelayedEvent e = d->delayedEvents.take(id); | - | ||||||||||||||||||
| 2784 | if (!e.event)
| 2-3 | ||||||||||||||||||
| 2785 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 2786 | if (e.timerId) {
| 1-2 | ||||||||||||||||||
| 2787 | d->timerIdToDelayedEventId.remove(e.timerId); | - | ||||||||||||||||||
| 2788 | bool inMachineThread = (QThread::currentThread() == thread()); | - | ||||||||||||||||||
| 2789 | if (inMachineThread) {
| 0-2 | ||||||||||||||||||
| 2790 | killTimer(e.timerId); | - | ||||||||||||||||||
| 2791 | d->delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 2792 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2793 | QMetaObject::invokeMethod(this, "_q_killDelayedEventTimer", | - | ||||||||||||||||||
| 2794 | Qt::QueuedConnection, | - | ||||||||||||||||||
| 2795 | Q_ARG(int, id), | - | ||||||||||||||||||
| 2796 | Q_ARG(int, e.timerId)); | - | ||||||||||||||||||
| 2797 | } never executed: end of block | 0 | ||||||||||||||||||
| 2798 | } else { | - | ||||||||||||||||||
| 2799 | // Cancellation will be detected in pending _q_startDelayedEventTimer() call | - | ||||||||||||||||||
| 2800 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 2801 | delete e.event; | - | ||||||||||||||||||
| 2802 | return true; executed 3 times by 1 test: return true;Executed by:
| 3 | ||||||||||||||||||
| 2803 | } | - | ||||||||||||||||||
| 2804 | - | |||||||||||||||||||
| 2805 | /*! | - | ||||||||||||||||||
| 2806 | Returns the maximal consistent set of states (including parallel and final | - | ||||||||||||||||||
| 2807 | states) that this state machine is currently in. If a state \c s is in the | - | ||||||||||||||||||
| 2808 | configuration, it is always the case that the parent of \c s is also in | - | ||||||||||||||||||
| 2809 | c. Note, however, that the machine itself is not an explicit member of the | - | ||||||||||||||||||
| 2810 | configuration. | - | ||||||||||||||||||
| 2811 | */ | - | ||||||||||||||||||
| 2812 | QSet<QAbstractState*> QStateMachine::configuration() const | - | ||||||||||||||||||
| 2813 | { | - | ||||||||||||||||||
| 2814 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2815 | return d->configuration; executed 938 times by 2 tests: return d->configuration;Executed by:
| 938 | ||||||||||||||||||
| 2816 | } | - | ||||||||||||||||||
| 2817 | - | |||||||||||||||||||
| 2818 | /*! | - | ||||||||||||||||||
| 2819 | \fn QStateMachine::started() | - | ||||||||||||||||||
| 2820 | - | |||||||||||||||||||
| 2821 | This signal is emitted when the state machine has entered its initial state | - | ||||||||||||||||||
| 2822 | (QStateMachine::initialState). | - | ||||||||||||||||||
| 2823 | - | |||||||||||||||||||
| 2824 | \sa QStateMachine::finished(), QStateMachine::start() | - | ||||||||||||||||||
| 2825 | */ | - | ||||||||||||||||||
| 2826 | - | |||||||||||||||||||
| 2827 | /*! | - | ||||||||||||||||||
| 2828 | \fn QStateMachine::stopped() | - | ||||||||||||||||||
| 2829 | - | |||||||||||||||||||
| 2830 | This signal is emitted when the state machine has stopped. | - | ||||||||||||||||||
| 2831 | - | |||||||||||||||||||
| 2832 | \sa QStateMachine::stop(), QStateMachine::finished() | - | ||||||||||||||||||
| 2833 | */ | - | ||||||||||||||||||
| 2834 | - | |||||||||||||||||||
| 2835 | /*! | - | ||||||||||||||||||
| 2836 | \reimp | - | ||||||||||||||||||
| 2837 | */ | - | ||||||||||||||||||
| 2838 | bool QStateMachine::event(QEvent *e) | - | ||||||||||||||||||
| 2839 | { | - | ||||||||||||||||||
| 2840 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2841 | if (e->type() == QEvent::Timer) {
| 4-685 | ||||||||||||||||||
| 2842 | QTimerEvent *te = static_cast<QTimerEvent*>(e); | - | ||||||||||||||||||
| 2843 | int tid = te->timerId(); | - | ||||||||||||||||||
| 2844 | if (d->state != QStateMachinePrivate::Running) {
| 0-4 | ||||||||||||||||||
| 2845 | // This event has been cancelled already | - | ||||||||||||||||||
| 2846 | QMutexLocker locker(&d->delayedEventsMutex); | - | ||||||||||||||||||
| 2847 | Q_ASSERT(!d->timerIdToDelayedEventId.contains(tid)); | - | ||||||||||||||||||
| 2848 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2849 | } | - | ||||||||||||||||||
| 2850 | d->delayedEventsMutex.lock(); | - | ||||||||||||||||||
| 2851 | int id = d->timerIdToDelayedEventId.take(tid); | - | ||||||||||||||||||
| 2852 | QStateMachinePrivate::DelayedEvent ee = d->delayedEvents.take(id); | - | ||||||||||||||||||
| 2853 | if (ee.event != 0) {
| 0-4 | ||||||||||||||||||
| 2854 | Q_ASSERT(ee.timerId == tid); | - | ||||||||||||||||||
| 2855 | killTimer(tid); | - | ||||||||||||||||||
| 2856 | d->delayedEventIdFreeList.release(id); | - | ||||||||||||||||||
| 2857 | d->delayedEventsMutex.unlock(); | - | ||||||||||||||||||
| 2858 | d->postExternalEvent(ee.event); | - | ||||||||||||||||||
| 2859 | d->processEvents(QStateMachinePrivate::DirectProcessing); | - | ||||||||||||||||||
| 2860 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 2861 | } else { | - | ||||||||||||||||||
| 2862 | d->delayedEventsMutex.unlock(); | - | ||||||||||||||||||
| 2863 | } never executed: end of block | 0 | ||||||||||||||||||
| 2864 | } | - | ||||||||||||||||||
| 2865 | return QState::event(e); executed 685 times by 2 tests: return QState::event(e);Executed by:
| 685 | ||||||||||||||||||
| 2866 | } | - | ||||||||||||||||||
| 2867 | - | |||||||||||||||||||
| 2868 | #ifndef QT_NO_STATEMACHINE_EVENTFILTER | - | ||||||||||||||||||
| 2869 | /*! | - | ||||||||||||||||||
| 2870 | \reimp | - | ||||||||||||||||||
| 2871 | */ | - | ||||||||||||||||||
| 2872 | bool QStateMachine::eventFilter(QObject *watched, QEvent *event) | - | ||||||||||||||||||
| 2873 | { | - | ||||||||||||||||||
| 2874 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2875 | d->handleFilteredEvent(watched, event); | - | ||||||||||||||||||
| 2876 | return false; executed 27 times by 1 test: return false;Executed by:
| 27 | ||||||||||||||||||
| 2877 | } | - | ||||||||||||||||||
| 2878 | #endif | - | ||||||||||||||||||
| 2879 | - | |||||||||||||||||||
| 2880 | /*! | - | ||||||||||||||||||
| 2881 | \internal | - | ||||||||||||||||||
| 2882 | - | |||||||||||||||||||
| 2883 | This function is called when the state machine is about to select | - | ||||||||||||||||||
| 2884 | transitions based on the given \a event. | - | ||||||||||||||||||
| 2885 | - | |||||||||||||||||||
| 2886 | The default implementation does nothing. | - | ||||||||||||||||||
| 2887 | */ | - | ||||||||||||||||||
| 2888 | void QStateMachine::beginSelectTransitions(QEvent *event) | - | ||||||||||||||||||
| 2889 | { | - | ||||||||||||||||||
| 2890 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2891 | } executed 3744 times by 2 tests: end of blockExecuted by:
| 3744 | ||||||||||||||||||
| 2892 | - | |||||||||||||||||||
| 2893 | /*! | - | ||||||||||||||||||
| 2894 | \internal | - | ||||||||||||||||||
| 2895 | - | |||||||||||||||||||
| 2896 | This function is called when the state machine has finished selecting | - | ||||||||||||||||||
| 2897 | transitions based on the given \a event. | - | ||||||||||||||||||
| 2898 | - | |||||||||||||||||||
| 2899 | The default implementation does nothing. | - | ||||||||||||||||||
| 2900 | */ | - | ||||||||||||||||||
| 2901 | void QStateMachine::endSelectTransitions(QEvent *event) | - | ||||||||||||||||||
| 2902 | { | - | ||||||||||||||||||
| 2903 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2904 | } executed 3750 times by 2 tests: end of blockExecuted by:
| 3750 | ||||||||||||||||||
| 2905 | - | |||||||||||||||||||
| 2906 | /*! | - | ||||||||||||||||||
| 2907 | \internal | - | ||||||||||||||||||
| 2908 | - | |||||||||||||||||||
| 2909 | This function is called when the state machine is about to do a microstep. | - | ||||||||||||||||||
| 2910 | - | |||||||||||||||||||
| 2911 | The default implementation does nothing. | - | ||||||||||||||||||
| 2912 | */ | - | ||||||||||||||||||
| 2913 | void QStateMachine::beginMicrostep(QEvent *event) | - | ||||||||||||||||||
| 2914 | { | - | ||||||||||||||||||
| 2915 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2916 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 2917 | - | |||||||||||||||||||
| 2918 | /*! | - | ||||||||||||||||||
| 2919 | \internal | - | ||||||||||||||||||
| 2920 | - | |||||||||||||||||||
| 2921 | This function is called when the state machine has finished doing a | - | ||||||||||||||||||
| 2922 | microstep. | - | ||||||||||||||||||
| 2923 | - | |||||||||||||||||||
| 2924 | The default implementation does nothing. | - | ||||||||||||||||||
| 2925 | */ | - | ||||||||||||||||||
| 2926 | void QStateMachine::endMicrostep(QEvent *event) | - | ||||||||||||||||||
| 2927 | { | - | ||||||||||||||||||
| 2928 | Q_UNUSED(event); | - | ||||||||||||||||||
| 2929 | } executed 1235 times by 2 tests: end of blockExecuted by:
| 1235 | ||||||||||||||||||
| 2930 | - | |||||||||||||||||||
| 2931 | /*! | - | ||||||||||||||||||
| 2932 | \reimp | - | ||||||||||||||||||
| 2933 | This function will call start() to start the state machine. | - | ||||||||||||||||||
| 2934 | */ | - | ||||||||||||||||||
| 2935 | void QStateMachine::onEntry(QEvent *event) | - | ||||||||||||||||||
| 2936 | { | - | ||||||||||||||||||
| 2937 | start(); | - | ||||||||||||||||||
| 2938 | QState::onEntry(event); | - | ||||||||||||||||||
| 2939 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 2940 | - | |||||||||||||||||||
| 2941 | /*! | - | ||||||||||||||||||
| 2942 | \reimp | - | ||||||||||||||||||
| 2943 | This function will call stop() to stop the state machine and | - | ||||||||||||||||||
| 2944 | subsequently emit the stopped() signal. | - | ||||||||||||||||||
| 2945 | */ | - | ||||||||||||||||||
| 2946 | void QStateMachine::onExit(QEvent *event) | - | ||||||||||||||||||
| 2947 | { | - | ||||||||||||||||||
| 2948 | stop(); | - | ||||||||||||||||||
| 2949 | QState::onExit(event); | - | ||||||||||||||||||
| 2950 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 2951 | - | |||||||||||||||||||
| 2952 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 2953 | - | |||||||||||||||||||
| 2954 | /*! | - | ||||||||||||||||||
| 2955 | Returns whether animations are enabled for this state machine. | - | ||||||||||||||||||
| 2956 | */ | - | ||||||||||||||||||
| 2957 | bool QStateMachine::isAnimated() const | - | ||||||||||||||||||
| 2958 | { | - | ||||||||||||||||||
| 2959 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2960 | return d->animated; executed 3 times by 1 test: return d->animated;Executed by:
| 3 | ||||||||||||||||||
| 2961 | } | - | ||||||||||||||||||
| 2962 | - | |||||||||||||||||||
| 2963 | /*! | - | ||||||||||||||||||
| 2964 | Sets whether animations are \a enabled for this state machine. | - | ||||||||||||||||||
| 2965 | */ | - | ||||||||||||||||||
| 2966 | void QStateMachine::setAnimated(bool enabled) | - | ||||||||||||||||||
| 2967 | { | - | ||||||||||||||||||
| 2968 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2969 | d->animated = enabled; | - | ||||||||||||||||||
| 2970 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 2971 | - | |||||||||||||||||||
| 2972 | /*! | - | ||||||||||||||||||
| 2973 | Adds a default \a animation to be considered for any transition. | - | ||||||||||||||||||
| 2974 | */ | - | ||||||||||||||||||
| 2975 | void QStateMachine::addDefaultAnimation(QAbstractAnimation *animation) | - | ||||||||||||||||||
| 2976 | { | - | ||||||||||||||||||
| 2977 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2978 | d->defaultAnimations.append(animation); | - | ||||||||||||||||||
| 2979 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 2980 | - | |||||||||||||||||||
| 2981 | /*! | - | ||||||||||||||||||
| 2982 | Returns the list of default animations that will be considered for any transition. | - | ||||||||||||||||||
| 2983 | */ | - | ||||||||||||||||||
| 2984 | QList<QAbstractAnimation*> QStateMachine::defaultAnimations() const | - | ||||||||||||||||||
| 2985 | { | - | ||||||||||||||||||
| 2986 | Q_D(const QStateMachine); | - | ||||||||||||||||||
| 2987 | return d->defaultAnimations; executed 10 times by 1 test: return d->defaultAnimations;Executed by:
| 10 | ||||||||||||||||||
| 2988 | } | - | ||||||||||||||||||
| 2989 | - | |||||||||||||||||||
| 2990 | /*! | - | ||||||||||||||||||
| 2991 | Removes \a animation from the list of default animations. | - | ||||||||||||||||||
| 2992 | */ | - | ||||||||||||||||||
| 2993 | void QStateMachine::removeDefaultAnimation(QAbstractAnimation *animation) | - | ||||||||||||||||||
| 2994 | { | - | ||||||||||||||||||
| 2995 | Q_D(QStateMachine); | - | ||||||||||||||||||
| 2996 | d->defaultAnimations.removeAll(animation); | - | ||||||||||||||||||
| 2997 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 2998 | - | |||||||||||||||||||
| 2999 | #endif // QT_NO_ANIMATION | - | ||||||||||||||||||
| 3000 | - | |||||||||||||||||||
| 3001 | - | |||||||||||||||||||
| 3002 | // Begin moc-generated code -- modify carefully (check "HAND EDIT" parts)! | - | ||||||||||||||||||
| 3003 | struct qt_meta_stringdata_QSignalEventGenerator_t { | - | ||||||||||||||||||
| 3004 | QByteArrayData data[3]; | - | ||||||||||||||||||
| 3005 | char stringdata[32]; | - | ||||||||||||||||||
| 3006 | }; | - | ||||||||||||||||||
| 3007 | #define QT_MOC_LITERAL(idx, ofs, len) \ | - | ||||||||||||||||||
| 3008 | Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ | - | ||||||||||||||||||
| 3009 | offsetof(qt_meta_stringdata_QSignalEventGenerator_t, stringdata) + ofs \ | - | ||||||||||||||||||
| 3010 | - idx * sizeof(QByteArrayData) \ | - | ||||||||||||||||||
| 3011 | ) | - | ||||||||||||||||||
| 3012 | static const qt_meta_stringdata_QSignalEventGenerator_t qt_meta_stringdata_QSignalEventGenerator = { | - | ||||||||||||||||||
| 3013 | { | - | ||||||||||||||||||
| 3014 | QT_MOC_LITERAL(0, 0, 21), | - | ||||||||||||||||||
| 3015 | QT_MOC_LITERAL(1, 22, 7), | - | ||||||||||||||||||
| 3016 | QT_MOC_LITERAL(2, 30, 0) | - | ||||||||||||||||||
| 3017 | }, | - | ||||||||||||||||||
| 3018 | "QSignalEventGenerator\0execute\0\0" | - | ||||||||||||||||||
| 3019 | }; | - | ||||||||||||||||||
| 3020 | #undef QT_MOC_LITERAL | - | ||||||||||||||||||
| 3021 | - | |||||||||||||||||||
| 3022 | static const uint qt_meta_data_QSignalEventGenerator[] = { | - | ||||||||||||||||||
| 3023 | - | |||||||||||||||||||
| 3024 | // content: | - | ||||||||||||||||||
| 3025 | 7, // revision | - | ||||||||||||||||||
| 3026 | 0, // classname | - | ||||||||||||||||||
| 3027 | 0, 0, // classinfo | - | ||||||||||||||||||
| 3028 | 1, 14, // methods | - | ||||||||||||||||||
| 3029 | 0, 0, // properties | - | ||||||||||||||||||
| 3030 | 0, 0, // enums/sets | - | ||||||||||||||||||
| 3031 | 0, 0, // constructors | - | ||||||||||||||||||
| 3032 | 0, // flags | - | ||||||||||||||||||
| 3033 | 0, // signalCount | - | ||||||||||||||||||
| 3034 | - | |||||||||||||||||||
| 3035 | // slots: name, argc, parameters, tag, flags | - | ||||||||||||||||||
| 3036 | 1, 0, 19, 2, 0x0a, | - | ||||||||||||||||||
| 3037 | - | |||||||||||||||||||
| 3038 | // slots: parameters | - | ||||||||||||||||||
| 3039 | QMetaType::Void, | - | ||||||||||||||||||
| 3040 | - | |||||||||||||||||||
| 3041 | 0 // eod | - | ||||||||||||||||||
| 3042 | }; | - | ||||||||||||||||||
| 3043 | - | |||||||||||||||||||
| 3044 | void QSignalEventGenerator::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) | - | ||||||||||||||||||
| 3045 | { | - | ||||||||||||||||||
| 3046 | if (_c == QMetaObject::InvokeMetaMethod) { | - | ||||||||||||||||||
| 3047 | Q_ASSERT(staticMetaObject.cast(_o)); | - | ||||||||||||||||||
| 3048 | QSignalEventGenerator *_t = static_cast<QSignalEventGenerator *>(_o); | - | ||||||||||||||||||
| 3049 | switch (_id) { | - | ||||||||||||||||||
| 3050 | case 0: _t->execute(_a); break; // HAND EDIT: add the _a parameter | - | ||||||||||||||||||
| 3051 | default: ; | - | ||||||||||||||||||
| 3052 | } | - | ||||||||||||||||||
| 3053 | } | - | ||||||||||||||||||
| 3054 | Q_UNUSED(_a); | - | ||||||||||||||||||
| 3055 | } | - | ||||||||||||||||||
| 3056 | - | |||||||||||||||||||
| 3057 | const QMetaObject QSignalEventGenerator::staticMetaObject = { | - | ||||||||||||||||||
| 3058 | { &QObject::staticMetaObject, qt_meta_stringdata_QSignalEventGenerator.data, | - | ||||||||||||||||||
| 3059 | qt_meta_data_QSignalEventGenerator, qt_static_metacall, 0, 0 } | - | ||||||||||||||||||
| 3060 | }; | - | ||||||||||||||||||
| 3061 | - | |||||||||||||||||||
| 3062 | const QMetaObject *QSignalEventGenerator::metaObject() const | - | ||||||||||||||||||
| 3063 | { | - | ||||||||||||||||||
| 3064 | return &staticMetaObject; | - | ||||||||||||||||||
| 3065 | } | - | ||||||||||||||||||
| 3066 | - | |||||||||||||||||||
| 3067 | void *QSignalEventGenerator::qt_metacast(const char *_clname) | - | ||||||||||||||||||
| 3068 | { | - | ||||||||||||||||||
| 3069 | if (!_clname) return 0; | - | ||||||||||||||||||
| 3070 | if (!strcmp(_clname, qt_meta_stringdata_QSignalEventGenerator.stringdata)) | - | ||||||||||||||||||
| 3071 | return static_cast<void*>(const_cast< QSignalEventGenerator*>(this)); | - | ||||||||||||||||||
| 3072 | return QObject::qt_metacast(_clname); | - | ||||||||||||||||||
| 3073 | } | - | ||||||||||||||||||
| 3074 | - | |||||||||||||||||||
| 3075 | int QSignalEventGenerator::qt_metacall(QMetaObject::Call _c, int _id, void **_a) | - | ||||||||||||||||||
| 3076 | { | - | ||||||||||||||||||
| 3077 | _id = QObject::qt_metacall(_c, _id, _a); | - | ||||||||||||||||||
| 3078 | if (_id < 0) | - | ||||||||||||||||||
| 3079 | return _id; | - | ||||||||||||||||||
| 3080 | if (_c == QMetaObject::InvokeMetaMethod) { | - | ||||||||||||||||||
| 3081 | if (_id < 1) | - | ||||||||||||||||||
| 3082 | qt_static_metacall(this, _c, _id, _a); | - | ||||||||||||||||||
| 3083 | _id -= 1; | - | ||||||||||||||||||
| 3084 | } | - | ||||||||||||||||||
| 3085 | return _id; | - | ||||||||||||||||||
| 3086 | } | - | ||||||||||||||||||
| 3087 | // End moc-generated code | - | ||||||||||||||||||
| 3088 | - | |||||||||||||||||||
| 3089 | void QSignalEventGenerator::execute(void **_a) | - | ||||||||||||||||||
| 3090 | { | - | ||||||||||||||||||
| 3091 | int signalIndex = senderSignalIndex(); | - | ||||||||||||||||||
| 3092 | Q_ASSERT(signalIndex != -1); | - | ||||||||||||||||||
| 3093 | QStateMachine *machine = qobject_cast<QStateMachine*>(parent()); | - | ||||||||||||||||||
| 3094 | QStateMachinePrivate::get(machine)->handleTransitionSignal(sender(), signalIndex, _a); | - | ||||||||||||||||||
| 3095 | } executed 70 times by 2 tests: end of blockExecuted by:
| 70 | ||||||||||||||||||
| 3096 | - | |||||||||||||||||||
| 3097 | QSignalEventGenerator::QSignalEventGenerator(QStateMachine *parent) | - | ||||||||||||||||||
| 3098 | : QObject(parent) | - | ||||||||||||||||||
| 3099 | { | - | ||||||||||||||||||
| 3100 | } executed 43 times by 2 tests: end of blockExecuted by:
| 43 | ||||||||||||||||||
| 3101 | - | |||||||||||||||||||
| 3102 | /*! | - | ||||||||||||||||||
| 3103 | \class QStateMachine::SignalEvent | - | ||||||||||||||||||
| 3104 | \inmodule QtCore | - | ||||||||||||||||||
| 3105 | - | |||||||||||||||||||
| 3106 | \brief The SignalEvent class represents a Qt signal event. | - | ||||||||||||||||||
| 3107 | - | |||||||||||||||||||
| 3108 | \since 4.6 | - | ||||||||||||||||||
| 3109 | \ingroup statemachine | - | ||||||||||||||||||
| 3110 | - | |||||||||||||||||||
| 3111 | A signal event is generated by a QStateMachine in response to a Qt | - | ||||||||||||||||||
| 3112 | signal. The QSignalTransition class provides a transition associated with a | - | ||||||||||||||||||
| 3113 | signal event. QStateMachine::SignalEvent is part of \l{The State Machine Framework}. | - | ||||||||||||||||||
| 3114 | - | |||||||||||||||||||
| 3115 | The sender() function returns the object that generated the signal. The | - | ||||||||||||||||||
| 3116 | signalIndex() function returns the index of the signal. The arguments() | - | ||||||||||||||||||
| 3117 | function returns the arguments of the signal. | - | ||||||||||||||||||
| 3118 | - | |||||||||||||||||||
| 3119 | \sa QSignalTransition | - | ||||||||||||||||||
| 3120 | */ | - | ||||||||||||||||||
| 3121 | - | |||||||||||||||||||
| 3122 | /*! | - | ||||||||||||||||||
| 3123 | \internal | - | ||||||||||||||||||
| 3124 | - | |||||||||||||||||||
| 3125 | Constructs a new SignalEvent object with the given \a sender, \a | - | ||||||||||||||||||
| 3126 | signalIndex and \a arguments. | - | ||||||||||||||||||
| 3127 | */ | - | ||||||||||||||||||
| 3128 | QStateMachine::SignalEvent::SignalEvent(QObject *sender, int signalIndex, | - | ||||||||||||||||||
| 3129 | const QList<QVariant> &arguments) | - | ||||||||||||||||||
| 3130 | : QEvent(QEvent::StateMachineSignal), m_sender(sender), | - | ||||||||||||||||||
| 3131 | m_signalIndex(signalIndex), m_arguments(arguments) | - | ||||||||||||||||||
| 3132 | { | - | ||||||||||||||||||
| 3133 | } executed 71 times by 2 tests: end of blockExecuted by:
| 71 | ||||||||||||||||||
| 3134 | - | |||||||||||||||||||
| 3135 | /*! | - | ||||||||||||||||||
| 3136 | Destroys this SignalEvent. | - | ||||||||||||||||||
| 3137 | */ | - | ||||||||||||||||||
| 3138 | QStateMachine::SignalEvent::~SignalEvent() | - | ||||||||||||||||||
| 3139 | { | - | ||||||||||||||||||
| 3140 | } | - | ||||||||||||||||||
| 3141 | - | |||||||||||||||||||
| 3142 | /*! | - | ||||||||||||||||||
| 3143 | \fn QStateMachine::SignalEvent::sender() const | - | ||||||||||||||||||
| 3144 | - | |||||||||||||||||||
| 3145 | Returns the object that emitted the signal. | - | ||||||||||||||||||
| 3146 | - | |||||||||||||||||||
| 3147 | \sa QObject::sender() | - | ||||||||||||||||||
| 3148 | */ | - | ||||||||||||||||||
| 3149 | - | |||||||||||||||||||
| 3150 | /*! | - | ||||||||||||||||||
| 3151 | \fn QStateMachine::SignalEvent::signalIndex() const | - | ||||||||||||||||||
| 3152 | - | |||||||||||||||||||
| 3153 | Returns the index of the signal. | - | ||||||||||||||||||
| 3154 | - | |||||||||||||||||||
| 3155 | \sa QMetaObject::indexOfSignal(), QMetaObject::method() | - | ||||||||||||||||||
| 3156 | */ | - | ||||||||||||||||||
| 3157 | - | |||||||||||||||||||
| 3158 | /*! | - | ||||||||||||||||||
| 3159 | \fn QStateMachine::SignalEvent::arguments() const | - | ||||||||||||||||||
| 3160 | - | |||||||||||||||||||
| 3161 | Returns the arguments of the signal. | - | ||||||||||||||||||
| 3162 | */ | - | ||||||||||||||||||
| 3163 | - | |||||||||||||||||||
| 3164 | - | |||||||||||||||||||
| 3165 | /*! | - | ||||||||||||||||||
| 3166 | \class QStateMachine::WrappedEvent | - | ||||||||||||||||||
| 3167 | \inmodule QtCore | - | ||||||||||||||||||
| 3168 | - | |||||||||||||||||||
| 3169 | \brief The WrappedEvent class inherits QEvent and holds a clone of an event associated with a QObject. | - | ||||||||||||||||||
| 3170 | - | |||||||||||||||||||
| 3171 | \since 4.6 | - | ||||||||||||||||||
| 3172 | \ingroup statemachine | - | ||||||||||||||||||
| 3173 | - | |||||||||||||||||||
| 3174 | A wrapped event is generated by a QStateMachine in response to a Qt | - | ||||||||||||||||||
| 3175 | event. The QEventTransition class provides a transition associated with a | - | ||||||||||||||||||
| 3176 | such an event. QStateMachine::WrappedEvent is part of \l{The State Machine | - | ||||||||||||||||||
| 3177 | Framework}. | - | ||||||||||||||||||
| 3178 | - | |||||||||||||||||||
| 3179 | The object() function returns the object that generated the event. The | - | ||||||||||||||||||
| 3180 | event() function returns a clone of the original event. | - | ||||||||||||||||||
| 3181 | - | |||||||||||||||||||
| 3182 | \sa QEventTransition | - | ||||||||||||||||||
| 3183 | */ | - | ||||||||||||||||||
| 3184 | - | |||||||||||||||||||
| 3185 | /*! | - | ||||||||||||||||||
| 3186 | \internal | - | ||||||||||||||||||
| 3187 | - | |||||||||||||||||||
| 3188 | Constructs a new WrappedEvent object with the given \a object | - | ||||||||||||||||||
| 3189 | and \a event. | - | ||||||||||||||||||
| 3190 | - | |||||||||||||||||||
| 3191 | The WrappedEvent object takes ownership of \a event. | - | ||||||||||||||||||
| 3192 | */ | - | ||||||||||||||||||
| 3193 | QStateMachine::WrappedEvent::WrappedEvent(QObject *object, QEvent *event) | - | ||||||||||||||||||
| 3194 | : QEvent(QEvent::StateMachineWrapped), m_object(object), m_event(event) | - | ||||||||||||||||||
| 3195 | { | - | ||||||||||||||||||
| 3196 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 3197 | - | |||||||||||||||||||
| 3198 | /*! | - | ||||||||||||||||||
| 3199 | Destroys this WrappedEvent. | - | ||||||||||||||||||
| 3200 | */ | - | ||||||||||||||||||
| 3201 | QStateMachine::WrappedEvent::~WrappedEvent() | - | ||||||||||||||||||
| 3202 | { | - | ||||||||||||||||||
| 3203 | delete m_event; | - | ||||||||||||||||||
| 3204 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 3205 | - | |||||||||||||||||||
| 3206 | /*! | - | ||||||||||||||||||
| 3207 | \fn QStateMachine::WrappedEvent::object() const | - | ||||||||||||||||||
| 3208 | - | |||||||||||||||||||
| 3209 | Returns the object that the event is associated with. | - | ||||||||||||||||||
| 3210 | */ | - | ||||||||||||||||||
| 3211 | - | |||||||||||||||||||
| 3212 | /*! | - | ||||||||||||||||||
| 3213 | \fn QStateMachine::WrappedEvent::event() const | - | ||||||||||||||||||
| 3214 | - | |||||||||||||||||||
| 3215 | Returns a clone of the original event. | - | ||||||||||||||||||
| 3216 | */ | - | ||||||||||||||||||
| 3217 | - | |||||||||||||||||||
| 3218 | /*! | - | ||||||||||||||||||
| 3219 | \fn QStateMachine::runningChanged(bool running) | - | ||||||||||||||||||
| 3220 | \since 5.4 | - | ||||||||||||||||||
| 3221 | - | |||||||||||||||||||
| 3222 | This signal is emitted when the running property is changed with \a running as argument. | - | ||||||||||||||||||
| 3223 | - | |||||||||||||||||||
| 3224 | \sa QStateMachine::running | - | ||||||||||||||||||
| 3225 | */ | - | ||||||||||||||||||
| 3226 | - | |||||||||||||||||||
| 3227 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 3228 | - | |||||||||||||||||||
| 3229 | #include "qstatemachine.moc" | - | ||||||||||||||||||
| 3230 | #include "moc_qstatemachine.cpp" | - | ||||||||||||||||||
| 3231 | - | |||||||||||||||||||
| 3232 | #endif //QT_NO_STATEMACHINE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |