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

#include <ProgressState.h>

+ Inheritance diagram for ProgressState:
+ Collaboration diagram for ProgressState:

Public Types

using ProgressCallback = std::function< float()>
 
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 progressChanged (float progress)
 Emitted when the state is entered with the current progress value.
 
- Signals inherited from QGCAbstractState
void advance ()
 
void error ()
 

Public Member Functions

 ProgressState (const QString &stateName, QState *parent, float progress, Action action=nullptr)
 
 ProgressState (const QString &stateName, QState *parent, ProgressCallback progressCallback, Action action=nullptr)
 
float progress () const
 Get the current progress value.
 
void setProgress (float progress)
 Set a fixed progress value.
 
void setProgressCallback (ProgressCallback callback)
 Set a progress callback.
 
- 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

State that reports progress on entry. Useful for state machines that need to track progress through a sequence of states.

Progress can be reported as:

  • A fixed value (0.0 to 1.0)
  • Via a callback function for dynamic calculation

Example usage:

// Fixed progress
auto* state1 = new ProgressState("Step1", &machine, 0.25);
connect(state1, &ProgressState::progressChanged, this, &MyClass::onProgress);
// Dynamic progress via callback
auto* state2 = new ProgressState("Step2", &machine, [this]() {
return calculateProgress();
});
void progressChanged(float progress)
Emitted when the state is entered with the current progress value.
QGCStateMachine * machine() const

Definition at line 25 of file ProgressState.h.

Member Typedef Documentation

◆ Action

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

Definition at line 32 of file ProgressState.h.

◆ ProgressCallback

using ProgressState::ProgressCallback = std::function<float()>

Definition at line 31 of file ProgressState.h.

Constructor & Destructor Documentation

◆ ProgressState() [1/2]

ProgressState::ProgressState ( const QString &  stateName,
QState *  parent,
float  progress,
Action  action = nullptr 
)

Create a progress state with a fixed progress value

Parameters
stateNameName for this state
parentParent state
progressFixed progress value (0.0 to 1.0)
actionOptional action to execute on entry

Definition at line 5 of file ProgressState.cc.

◆ ProgressState() [2/2]

ProgressState::ProgressState ( const QString &  stateName,
QState *  parent,
ProgressCallback  progressCallback,
Action  action = nullptr 
)

Create a progress state with a dynamic progress callback

Parameters
stateNameName for this state
parentParent state
progressCallbackFunction that returns current progress (0.0 to 1.0)
actionOptional action to execute on entry

Definition at line 13 of file ProgressState.cc.

Member Function Documentation

◆ onEnter()

void ProgressState::onEnter ( )
overrideprotectedvirtual

Override to perform actions on state entry.

Reimplemented from QGCAbstractState.

Definition at line 41 of file ProgressState.cc.

References QGCAbstractState::advance(), progress(), and progressChanged().

◆ progress()

float ProgressState::progress ( ) const

Get the current progress value.

Definition at line 21 of file ProgressState.cc.

Referenced by onEnter(), and setProgress().

◆ progressChanged

void ProgressState::progressChanged ( float  progress)
signal

Emitted when the state is entered with the current progress value.

Referenced by onEnter().

◆ setProgress()

void ProgressState::setProgress ( float  progress)

Set a fixed progress value.

Definition at line 29 of file ProgressState.cc.

References progress().

◆ setProgressCallback()

void ProgressState::setProgressCallback ( ProgressCallback  callback)

Set a progress callback.

Definition at line 35 of file ProgressState.cc.


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