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