| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qfinalstate_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | /*! |
| 9 | \class QFinalState |
| 10 | \inmodule QtStateMachine |
| 11 | |
| 12 | \brief The QFinalState class provides a final state. |
| 13 | |
| 14 | \since 4.6 |
| 15 | \ingroup statemachine |
| 16 | |
| 17 | A final state is used to communicate that (part of) a QStateMachine has |
| 18 | finished its work. When a final top-level state is entered, the state |
| 19 | machine's \l{QStateMachine::finished()}{finished}() signal is emitted. In |
| 20 | general, when a final substate (a child of a QState) is entered, the parent |
| 21 | state's \l{QState::finished()}{finished}() signal is emitted. QFinalState |
| 22 | is part of \l{Qt State Machine Overview}{Qt State Machine Framework}. |
| 23 | |
| 24 | To use a final state, you create a QFinalState object and add a transition |
| 25 | to it from another state. Example: |
| 26 | |
| 27 | \code |
| 28 | QPushButton button; |
| 29 | |
| 30 | QStateMachine machine; |
| 31 | QState *s1 = new QState(); |
| 32 | QFinalState *s2 = new QFinalState(); |
| 33 | s1->addTransition(&button, SIGNAL(clicked()), s2); |
| 34 | machine.addState(s1); |
| 35 | machine.addState(s2); |
| 36 | |
| 37 | QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit())); |
| 38 | machine.setInitialState(s1); |
| 39 | machine.start(); |
| 40 | \endcode |
| 41 | |
| 42 | \sa QState::finished() |
| 43 | */ |
| 44 | |
| 45 | QFinalStatePrivate::QFinalStatePrivate() |
| 46 | : QAbstractStatePrivate(FinalState) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | QFinalStatePrivate::~QFinalStatePrivate() |
| 51 | { |
| 52 | // to prevent vtables being generated in every file that includes the private header |
| 53 | } |
| 54 | |
| 55 | /*! |
| 56 | Constructs a new QFinalState object with the given \a parent state. |
| 57 | */ |
| 58 | QFinalState::QFinalState(QState *parent) |
| 59 | : QAbstractState(*new QFinalStatePrivate, parent) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | /*! |
| 64 | \internal |
| 65 | */ |
| 66 | QFinalState::QFinalState(QFinalStatePrivate &dd, QState *parent) |
| 67 | : QAbstractState(dd, parent) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | |
| 72 | /*! |
| 73 | Destroys this final state. |
| 74 | */ |
| 75 | QFinalState::~QFinalState() |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | /*! |
| 80 | \reimp |
| 81 | */ |
| 82 | void QFinalState::onEntry(QEvent *event) |
| 83 | { |
| 84 | Q_UNUSED(event); |
| 85 | } |
| 86 | |
| 87 | /*! |
| 88 | \reimp |
| 89 | */ |
| 90 | void QFinalState::onExit(QEvent *event) |
| 91 | { |
| 92 | Q_UNUSED(event); |
| 93 | } |
| 94 | |
| 95 | /*! |
| 96 | \reimp |
| 97 | */ |
| 98 | bool QFinalState::event(QEvent *e) |
| 99 | { |
| 100 | return QAbstractState::event(e); |
| 101 | } |
| 102 | |
| 103 | QT_END_NAMESPACE |
| 104 | |
| 105 | #include "moc_qfinalstate.cpp" |
| 106 | |