| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qeventtransition.h" | - |
| 43 | | - |
| 44 | #ifndef QT_NO_STATEMACHINE | - |
| 45 | | - |
| 46 | #include "qeventtransition_p.h" | - |
| 47 | #include "qstate.h" | - |
| 48 | #include "qstate_p.h" | - |
| 49 | #include "qstatemachine.h" | - |
| 50 | #include "qstatemachine_p.h" | - |
| 51 | #include <qdebug.h> | - |
| 52 | | - |
| 53 | QT_BEGIN_NAMESPACE | - |
| 54 | | - |
| 55 | /*! | - |
| 56 | \class QEventTransition | - |
| 57 | \inmodule QtCore | - |
| 58 | | - |
| 59 | \brief The QEventTransition class provides a QObject-specific transition for Qt events. | - |
| 60 | | - |
| 61 | \since 4.6 | - |
| 62 | \ingroup statemachine | - |
| 63 | | - |
| 64 | A QEventTransition object binds an event to a particular QObject. | - |
| 65 | QEventTransition is part of \l{The State Machine Framework}. | - |
| 66 | | - |
| 67 | Example: | - |
| 68 | | - |
| 69 | \code | - |
| 70 | QPushButton *button = ...; | - |
| 71 | QState *s1 = ...; | - |
| 72 | QState *s2 = ...; | - |
| 73 | // If in s1 and the button receives an Enter event, transition to s2 | - |
| 74 | QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter); | - |
| 75 | enterTransition->setTargetState(s2); | - |
| 76 | s1->addTransition(enterTransition); | - |
| 77 | // If in s2 and the button receives an Exit event, transition back to s1 | - |
| 78 | QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave); | - |
| 79 | leaveTransition->setTargetState(s1); | - |
| 80 | s2->addTransition(leaveTransition); | - |
| 81 | \endcode | - |
| 82 | | - |
| 83 | \section1 Subclassing | - |
| 84 | | - |
| 85 | When reimplementing the eventTest() function, you should first call the base | - |
| 86 | implementation to verify that the event is a QStateMachine::WrappedEvent for | - |
| 87 | the proper object and event type. You may then cast the event to a | - |
| 88 | QStateMachine::WrappedEvent and get the original event by calling | - |
| 89 | QStateMachine::WrappedEvent::event(), and perform additional checks on that | - |
| 90 | object. | - |
| 91 | | - |
| 92 | \sa QState::addTransition() | - |
| 93 | */ | - |
| 94 | | - |
| 95 | /*! | - |
| 96 | \property QEventTransition::eventSource | - |
| 97 | | - |
| 98 | \brief the event source that this event transition is associated with | - |
| 99 | */ | - |
| 100 | | - |
| 101 | /*! | - |
| 102 | \property QEventTransition::eventType | - |
| 103 | | - |
| 104 | \brief the type of event that this event transition is associated with | - |
| 105 | */ | - |
| 106 | QEventTransitionPrivate::QEventTransitionPrivate() | - |
| 107 | { | - |
| 108 | object = 0; executed (the execution status of this line is deduced): object = 0; | - |
| 109 | eventType = QEvent::None; executed (the execution status of this line is deduced): eventType = QEvent::None; | - |
| 110 | registered = false; executed (the execution status of this line is deduced): registered = false; | - |
| 111 | } executed: }Execution Count:18 | 18 |
| 112 | | - |
| 113 | QEventTransitionPrivate *QEventTransitionPrivate::get(QEventTransition *q) | - |
| 114 | { | - |
| 115 | return q->d_func(); executed: return q->d_func();Execution Count:139 | 139 |
| 116 | } | - |
| 117 | | - |
| 118 | void QEventTransitionPrivate::unregister() | - |
| 119 | { | - |
| 120 | Q_Q(QEventTransition); executed (the execution status of this line is deduced): QEventTransition * const q = q_func(); | - |
| 121 | if (!registered || !machine()) evaluated: !registered| yes Evaluation Count:10 | yes Evaluation Count:3 |
partially evaluated: !machine()| no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-10 |
| 122 | return; executed: return;Execution Count:10 | 10 |
| 123 | QStateMachinePrivate::get(machine())->unregisterEventTransition(q); executed (the execution status of this line is deduced): QStateMachinePrivate::get(machine())->unregisterEventTransition(q); | - |
| 124 | } executed: }Execution Count:3 | 3 |
| 125 | | - |
| 126 | void QEventTransitionPrivate::maybeRegister() | - |
| 127 | { | - |
| 128 | Q_Q(QEventTransition); executed (the execution status of this line is deduced): QEventTransition * const q = q_func(); | - |
| 129 | if (QStateMachine *mach = machine()) evaluated: QStateMachine *mach = machine()| yes Evaluation Count:7 | yes Evaluation Count:18 |
| 7-18 |
| 130 | QStateMachinePrivate::get(mach)->maybeRegisterEventTransition(q); executed: QStateMachinePrivate::get(mach)->maybeRegisterEventTransition(q);Execution Count:7 | 7 |
| 131 | } executed: }Execution Count:25 | 25 |
| 132 | | - |
| 133 | /*! | - |
| 134 | Constructs a new QEventTransition object with the given \a sourceState. | - |
| 135 | */ | - |
| 136 | QEventTransition::QEventTransition(QState *sourceState) | - |
| 137 | : QAbstractTransition(*new QEventTransitionPrivate, sourceState) | - |
| 138 | { | - |
| 139 | } executed: }Execution Count:4 | 4 |
| 140 | | - |
| 141 | /*! | - |
| 142 | Constructs a new QEventTransition object associated with events of the given | - |
| 143 | \a type for the given \a object, and with the given \a sourceState. | - |
| 144 | */ | - |
| 145 | QEventTransition::QEventTransition(QObject *object, QEvent::Type type, | - |
| 146 | QState *sourceState) | - |
| 147 | : QAbstractTransition(*new QEventTransitionPrivate, sourceState) | - |
| 148 | { | - |
| 149 | Q_D(QEventTransition); executed (the execution status of this line is deduced): QEventTransitionPrivate * const d = d_func(); | - |
| 150 | d->registered = false; executed (the execution status of this line is deduced): d->registered = false; | - |
| 151 | d->object = object; executed (the execution status of this line is deduced): d->object = object; | - |
| 152 | d->eventType = type; executed (the execution status of this line is deduced): d->eventType = type; | - |
| 153 | d->maybeRegister(); executed (the execution status of this line is deduced): d->maybeRegister(); | - |
| 154 | } executed: }Execution Count:10 | 10 |
| 155 | | - |
| 156 | /*! | - |
| 157 | \internal | - |
| 158 | */ | - |
| 159 | QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QState *parent) | - |
| 160 | : QAbstractTransition(dd, parent) | - |
| 161 | { | - |
| 162 | } executed: }Execution Count:2 | 2 |
| 163 | | - |
| 164 | /*! | - |
| 165 | \internal | - |
| 166 | */ | - |
| 167 | QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object, | - |
| 168 | QEvent::Type type, QState *parent) | - |
| 169 | : QAbstractTransition(dd, parent) | - |
| 170 | { | - |
| 171 | Q_D(QEventTransition); executed (the execution status of this line is deduced): QEventTransitionPrivate * const d = d_func(); | - |
| 172 | d->registered = false; executed (the execution status of this line is deduced): d->registered = false; | - |
| 173 | d->object = object; executed (the execution status of this line is deduced): d->object = object; | - |
| 174 | d->eventType = type; executed (the execution status of this line is deduced): d->eventType = type; | - |
| 175 | d->maybeRegister(); executed (the execution status of this line is deduced): d->maybeRegister(); | - |
| 176 | } executed: }Execution Count:2 | 2 |
| 177 | | - |
| 178 | /*! | - |
| 179 | Destroys this QObject event transition. | - |
| 180 | */ | - |
| 181 | QEventTransition::~QEventTransition() | - |
| 182 | { | - |
| 183 | } | - |
| 184 | | - |
| 185 | /*! | - |
| 186 | Returns the event type that this event transition is associated with. | - |
| 187 | */ | - |
| 188 | QEvent::Type QEventTransition::eventType() const | - |
| 189 | { | - |
| 190 | Q_D(const QEventTransition); executed (the execution status of this line is deduced): const QEventTransitionPrivate * const d = d_func(); | - |
| 191 | return d->eventType; executed: return d->eventType;Execution Count:100 | 100 |
| 192 | } | - |
| 193 | | - |
| 194 | /*! | - |
| 195 | Sets the event \a type that this event transition is associated with. | - |
| 196 | */ | - |
| 197 | void QEventTransition::setEventType(QEvent::Type type) | - |
| 198 | { | - |
| 199 | Q_D(QEventTransition); executed (the execution status of this line is deduced): QEventTransitionPrivate * const d = d_func(); | - |
| 200 | if (d->eventType == type) partially evaluated: d->eventType == type| no Evaluation Count:0 | yes Evaluation Count:7 |
| 0-7 |
| 201 | return; | 0 |
| 202 | d->unregister(); executed (the execution status of this line is deduced): d->unregister(); | - |
| 203 | d->eventType = type; executed (the execution status of this line is deduced): d->eventType = type; | - |
| 204 | d->maybeRegister(); executed (the execution status of this line is deduced): d->maybeRegister(); | - |
| 205 | } executed: }Execution Count:7 | 7 |
| 206 | | - |
| 207 | /*! | - |
| 208 | Returns the event source associated with this event transition. | - |
| 209 | */ | - |
| 210 | QObject *QEventTransition::eventSource() const | - |
| 211 | { | - |
| 212 | Q_D(const QEventTransition); executed (the execution status of this line is deduced): const QEventTransitionPrivate * const d = d_func(); | - |
| 213 | return d->object; executed: return d->object;Execution Count:5 | 5 |
| 214 | } | - |
| 215 | | - |
| 216 | /*! | - |
| 217 | Sets the event source associated with this event transition to be the given | - |
| 218 | \a object. | - |
| 219 | */ | - |
| 220 | void QEventTransition::setEventSource(QObject *object) | - |
| 221 | { | - |
| 222 | Q_D(QEventTransition); executed (the execution status of this line is deduced): QEventTransitionPrivate * const d = d_func(); | - |
| 223 | if (d->object == object) partially evaluated: d->object == object| no Evaluation Count:0 | yes Evaluation Count:6 |
| 0-6 |
| 224 | return; | 0 |
| 225 | d->unregister(); executed (the execution status of this line is deduced): d->unregister(); | - |
| 226 | d->object = object; executed (the execution status of this line is deduced): d->object = object; | - |
| 227 | d->maybeRegister(); executed (the execution status of this line is deduced): d->maybeRegister(); | - |
| 228 | } executed: }Execution Count:6 | 6 |
| 229 | | - |
| 230 | /*! | - |
| 231 | \reimp | - |
| 232 | */ | - |
| 233 | bool QEventTransition::eventTest(QEvent *event) | - |
| 234 | { | - |
| 235 | Q_D(const QEventTransition); executed (the execution status of this line is deduced): const QEventTransitionPrivate * const d = d_func(); | - |
| 236 | if (event->type() == QEvent::StateMachineWrapped) { evaluated: event->type() == QEvent::StateMachineWrapped| yes Evaluation Count:21 | yes Evaluation Count:42 |
| 21-42 |
| 237 | QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(event); executed (the execution status of this line is deduced): QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(event); | - |
| 238 | return (we->object() == d->object) executed: return (we->object() == d->object) && (we->event()->type() == d->eventType);Execution Count:21 | 21 |
| 239 | && (we->event()->type() == d->eventType); executed: return (we->object() == d->object) && (we->event()->type() == d->eventType);Execution Count:21 | 21 |
| 240 | } | - |
| 241 | return false; executed: return false;Execution Count:42 | 42 |
| 242 | } | - |
| 243 | | - |
| 244 | /*! | - |
| 245 | \reimp | - |
| 246 | */ | - |
| 247 | void QEventTransition::onTransition(QEvent *event) | - |
| 248 | { | - |
| 249 | Q_UNUSED(event); executed (the execution status of this line is deduced): (void)event;; | - |
| 250 | } executed: }Execution Count:20 | 20 |
| 251 | | - |
| 252 | /*! | - |
| 253 | \reimp | - |
| 254 | */ | - |
| 255 | bool QEventTransition::event(QEvent *e) | - |
| 256 | { | - |
| 257 | return QAbstractTransition::event(e); never executed: return QAbstractTransition::event(e); | 0 |
| 258 | } | - |
| 259 | | - |
| 260 | QT_END_NAMESPACE | - |
| 261 | | - |
| 262 | #endif //QT_NO_STATEMACHINE | - |
| 263 | | - |
| | |