QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SequenceState Class Reference

#include <SequenceState.h>

+ Inheritance diagram for SequenceState:
+ Collaboration diagram for SequenceState:

Classes

struct  Step
 

Public Types

using StepAction = std::function< bool()>
 Step action - returns true to continue, false to stop with error.
 
- Public Types inherited from QGCAbstractState
using EntryCallback = std::function< void()>
 
using ExitCallback = std::function< void()>
 
using EventHandler = std::function< bool(QEvent *)>
 

Signals

void stepCompleted (const QString &stepName, int index)
 Emitted after each step completes successfully.
 
- Signals inherited from QGCAbstractState
void advance ()
 
void error ()
 

Public Member Functions

 SequenceState (const QString &stateName, QState *parent)
 
void addStep (const QString &name, StepAction action)
 
void addSteps (const QList< Step > &steps)
 Add multiple steps at once.
 
int currentStepIndex () const
 Get the current step index.
 
QString currentStepName () const
 Get the current step name.
 
int stepCount () const
 Get the total number of steps.
 
QString failedStepName () const
 Get the name of the step that failed (valid after error())
 
- Public Member Functions inherited from QGCState
 QGCState (const QString &stateName, QState *parentState)
 
template<typename PointerToMemberFunction >
QSignalTransition * addThisTransition (PointerToMemberFunction signal, QAbstractState *target)
 Simpler version of QState::addTransition which assumes the sender is this.
 
void setLocalErrorState (QAbstractState *errorState)
 
QAbstractState * localErrorState () const
 Get the per-state error state (nullptr if using global)
 
void setProperty (QObject *object, const char *name, const QVariant &value)
 
void setEnabled (QObject *object, bool enabled)
 Convenience overload for setting enabled state on widgets/controls.
 
void setVisible (QObject *object, bool visible)
 Convenience overload for setting visible state on widgets/controls.
 
- Public Member Functions inherited from QGCAbstractState
 QGCAbstractState (const QString &stateName, QState *parent)
 
QGCStateMachinemachine () const
 
Vehiclevehicle () const
 
QString stateName () const
 
class StateContextcontext () const
 
void setOnEntry (EntryCallback callback)
 Set a callback to be invoked when the state is entered.
 
void setOnExit (ExitCallback callback)
 Set a callback to be invoked when the state is exited.
 
void setCallbacks (EntryCallback onEntry, ExitCallback onExit=nullptr)
 Set both entry and exit callbacks.
 
void setEventHandler (EventHandler handler)
 Set a custom event handler for this state.
 

Protected Member Functions

void onEnter () override
 Override to perform actions on state entry.
 
- Protected Member Functions inherited from QGCAbstractState
virtual void onLeave ()
 Override to perform actions on state exit.
 
void onEntry (QEvent *event) override
 
void onExit (QEvent *event) override
 
bool event (QEvent *event) override
 

Detailed Description

A composite state that executes a sequence of actions in order.

Each action is executed in turn. If any action fails (returns false), the sequence stops and error() is emitted. When all actions complete successfully, advance() is emitted.

Example usage:

auto* seqState = new SequenceState("LoadSequence", &machine);
seqState->addStep("Validate", []() {
// Validation logic
return isValid; // Return false to stop sequence
});
seqState->addStep("Load", []() {
// Load logic
return true;
});
seqState->addStep("Initialize", []() {
// Init logic
return true;
});
seqState->addTransition(seqState, &SequenceState::advance, successState);
seqState->addTransition(seqState, &SequenceState::error, errorState);
QGCStateMachine * machine() const

Definition at line 32 of file SequenceState.h.

Member Typedef Documentation

◆ StepAction

using SequenceState::StepAction = std::function<bool()>

Step action - returns true to continue, false to stop with error.

Definition at line 39 of file SequenceState.h.

Constructor & Destructor Documentation

◆ SequenceState()

SequenceState::SequenceState ( const QString &  stateName,
QState *  parent 
)

Definition at line 4 of file SequenceState.cc.

Member Function Documentation

◆ addStep()

void SequenceState::addStep ( const QString &  name,
StepAction  action 
)

Add a step to the sequence

Parameters
nameStep name for logging
actionAction to execute (returns true to continue, false to error)

Definition at line 9 of file SequenceState.cc.

◆ addSteps()

void SequenceState::addSteps ( const QList< Step > &  steps)

Add multiple steps at once.

Definition at line 14 of file SequenceState.cc.

◆ currentStepIndex()

int SequenceState::currentStepIndex ( ) const
inline

Get the current step index.

Definition at line 57 of file SequenceState.h.

◆ currentStepName()

QString SequenceState::currentStepName ( ) const

Get the current step name.

Definition at line 19 of file SequenceState.cc.

◆ failedStepName()

QString SequenceState::failedStepName ( ) const
inline

Get the name of the step that failed (valid after error())

Definition at line 66 of file SequenceState.h.

◆ onEnter()

void SequenceState::onEnter ( )
overrideprotectedvirtual

Override to perform actions on state entry.

Reimplemented from QGCAbstractState.

Definition at line 27 of file SequenceState.cc.

◆ stepCompleted

void SequenceState::stepCompleted ( const QString &  stepName,
int  index 
)
signal

Emitted after each step completes successfully.

◆ stepCount()

int SequenceState::stepCount ( ) const
inline

Get the total number of steps.

Definition at line 63 of file SequenceState.h.


The documentation for this class was generated from the following files: