1// Copyright (C) 2016 Ford Motor Company
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 "timeouttransition_p.h"
5
6#include <QQmlInfo>
7#include <QTimer>
8#include <QState>
9
10TimeoutTransition::TimeoutTransition(QState* parent)
11 : QSignalTransition((m_timer = new QTimer), SIGNAL(timeout()), parent)
12{
13 m_timer->setSingleShot(true);
14 m_timer->setInterval(1000);
15}
16
17TimeoutTransition::~TimeoutTransition()
18{
19 delete m_timer;
20}
21
22int TimeoutTransition::timeout() const
23{
24 return m_timer->interval();
25}
26
27void TimeoutTransition::setTimeout(int timeout)
28{
29 m_timer->setInterval(timeout);
30}
31
32QBindable<int> TimeoutTransition::bindableTimeout()
33{
34 return m_timer->bindableInterval();
35}
36
37void TimeoutTransition::componentComplete()
38{
39 QState *state = qobject_cast<QState*>(object: parent());
40 if (!state) {
41 qmlWarning(me: this) << "Parent needs to be a State";
42 return;
43 }
44
45 connect(sender: state, SIGNAL(entered()), receiver: m_timer, SLOT(start()));
46 connect(sender: state, SIGNAL(exited()), receiver: m_timer, SLOT(stop()));
47 if (state->active())
48 m_timer->start();
49}
50
51/*!
52 \qmltype TimeoutTransition
53 \inqmlmodule QtQml.StateMachine
54 \inherits QSignalTransition
55 \ingroup statemachine-qmltypes
56 \since 5.4
57
58 \brief The TimeoutTransition type provides a transition based on a timer.
59
60 \l {QtQml::Timer}{Timer} type can be combined with SignalTransition to enact more complex
61 timeout based transitions.
62
63 TimeoutTransition is part of \l{Qt State Machine QML Guide}{Qt State Machine QML API}
64
65 \section1 Example Usage
66
67 \snippet qml/statemachine/timeouttransition.qml document
68
69 \clearfloat
70
71 \sa StateMachine, SignalTransition, FinalState, HistoryState
72*/
73
74/*!
75 \qmlproperty int TimeoutTransition::timeout
76
77 \brief The timeout interval in milliseconds.
78*/
79
80#include "moc_timeouttransition_p.cpp"
81

source code of qtscxml/src/statemachineqml/timeouttransition.cpp