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

#include <ConditionalState.h>

+ Inheritance diagram for ConditionalState:
+ Collaboration diagram for ConditionalState:

Public Types

using Predicate = std::function< bool()>
 
using Action = std::function< void()>
 
- Public Types inherited from QGCAbstractState
using EntryCallback = std::function< void()>
 
using ExitCallback = std::function< void()>
 
using EventHandler = std::function< bool(QEvent *)>
 

Signals

void skipped ()
 Emitted when the predicate returns false and the state is skipped.
 
- Signals inherited from QGCAbstractState
void advance ()
 
void error ()
 

Public Member Functions

 ConditionalState (const QString &stateName, QState *parent, Predicate predicate, Action action=Action())
 
void setPredicate (Predicate predicate)
 Set the predicate.
 
void setAction (Action action)
 Set the action.
 
- 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.
 

Additional Inherited Members

- Protected Member Functions inherited from QGCAbstractState
virtual void onEnter ()
 Override to perform actions on state entry.
 
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 state that evaluates a predicate on entry and either executes or skips Useful for conditional logic like "skip if high latency link"

Definition at line 9 of file ConditionalState.h.

Member Typedef Documentation

◆ Action

using ConditionalState::Action = std::function<void()>

Definition at line 16 of file ConditionalState.h.

◆ Predicate

using ConditionalState::Predicate = std::function<bool()>

Definition at line 15 of file ConditionalState.h.

Constructor & Destructor Documentation

◆ ConditionalState()

ConditionalState::ConditionalState ( const QString &  stateName,
QState *  parent,
Predicate  predicate,
Action  action = Action() 
)
Parameters
stateNameName for this state (for logging)
parentParent state
predicateIf true, execute action and emit advance(); if false, emit skipped()
actionOptional action to execute when predicate is true

Definition at line 6 of file ConditionalState.cc.

Member Function Documentation

◆ setAction()

void ConditionalState::setAction ( Action  action)
inline

Set the action.

Definition at line 28 of file ConditionalState.h.

◆ setPredicate()

void ConditionalState::setPredicate ( Predicate  predicate)
inline

Set the predicate.

Definition at line 25 of file ConditionalState.h.

◆ skipped

void ConditionalState::skipped ( )
signal

Emitted when the predicate returns false and the state is skipped.


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