QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCAbstractState.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <QtStateMachine/QState>
4
#include <QtCore/QString>
5
6
#include <functional>
7
8
class
QGCStateMachine
;
9
class
Vehicle
;
10
28
class
QGCAbstractState
:
public
QState
29
{
30
Q_OBJECT
31
Q_DISABLE_COPY(
QGCAbstractState
)
32
33
public
:
34
using
EntryCallback
= std::function<void()>;
35
using
ExitCallback
= std::function<void()>;
36
using
EventHandler
= std::function<bool(QEvent*)>;
37
38
QGCAbstractState
(
const
QString&
stateName
, QState* parent);
39
40
QGCStateMachine
*
machine
()
const
;
41
Vehicle
*
vehicle
()
const
;
42
QString
stateName
()
const
;
43
46
class
StateContext
*
context
()
const
;
47
48
// -------------------------------------------------------------------------
49
// Entry/Exit Callbacks
50
// -------------------------------------------------------------------------
51
53
void
setOnEntry
(
EntryCallback
callback) { _entryCallback = std::move(callback); }
54
56
void
setOnExit
(
ExitCallback
callback) { _exitCallback = std::move(callback); }
57
59
void
setCallbacks
(
EntryCallback
onEntry
,
ExitCallback
onExit
=
nullptr
);
60
61
// -------------------------------------------------------------------------
62
// Event Handling
63
// -------------------------------------------------------------------------
64
66
void
setEventHandler
(
EventHandler
handler) { _eventHandler = std::move(handler); }
67
68
signals:
69
void
advance
();
70
void
error
();
71
72
protected
:
74
virtual
void
onEnter
() {}
75
77
virtual
void
onLeave
() {}
78
79
// QState overrides
80
void
onEntry
(QEvent*
event
)
override
;
81
void
onExit
(QEvent*
event
)
override
;
82
bool
event
(QEvent*
event
)
override
;
83
84
private
:
85
EntryCallback
_entryCallback;
86
ExitCallback
_exitCallback;
87
EventHandler
_eventHandler;
88
};
EventHandler
Drives the MAVLink events protocol for a single component.
Definition
EventHandler.h:22
QGCAbstractState
Lightweight base class for simple states.
Definition
QGCAbstractState.h:29
QGCAbstractState::EntryCallback
std::function< void()> EntryCallback
Definition
QGCAbstractState.h:34
QGCAbstractState::onExit
void onExit(QEvent *event) override
Definition
QGCAbstractState.cc:53
QGCAbstractState::setEventHandler
void setEventHandler(EventHandler handler)
Set a custom event handler for this state.
Definition
QGCAbstractState.h:66
QGCAbstractState::setCallbacks
void setCallbacks(EntryCallback onEntry, ExitCallback onExit=nullptr)
Set both entry and exit callbacks.
Definition
QGCAbstractState.cc:35
QGCAbstractState::onEntry
void onEntry(QEvent *event) override
Definition
QGCAbstractState.cc:41
QGCAbstractState::context
class StateContext * context() const
Definition
QGCAbstractState.cc:21
QGCAbstractState::setOnEntry
void setOnEntry(EntryCallback callback)
Set a callback to be invoked when the state is entered.
Definition
QGCAbstractState.h:53
QGCAbstractState::stateName
QString stateName() const
Definition
QGCAbstractState.cc:26
QGCAbstractState::event
bool event(QEvent *event) override
Definition
QGCAbstractState.cc:65
QGCAbstractState::onEnter
virtual void onEnter()
Override to perform actions on state entry.
Definition
QGCAbstractState.h:74
QGCAbstractState::onLeave
virtual void onLeave()
Override to perform actions on state exit.
Definition
QGCAbstractState.h:77
QGCAbstractState::advance
void advance()
QGCAbstractState::ExitCallback
std::function< void()> ExitCallback
Definition
QGCAbstractState.h:35
QGCAbstractState::error
void error()
QGCAbstractState::machine
QGCStateMachine * machine() const
Definition
QGCAbstractState.cc:11
QGCAbstractState::setOnExit
void setOnExit(ExitCallback callback)
Set a callback to be invoked when the state is exited.
Definition
QGCAbstractState.h:56
QGCAbstractState::vehicle
Vehicle * vehicle() const
Definition
QGCAbstractState.cc:16
QGCStateMachine
QGroundControl specific state machine with enhanced error handling.
Definition
QGCStateMachine.h:63
StateContext
Type-safe context for passing data between states in a state machine.
Definition
StateContext.h:32
Vehicle
Definition
Vehicle.h:86
src
Utilities
StateMachine
States
QGCAbstractState.h
Generated by
1.9.8