QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ProgressState.cc
Go to the documentation of this file.
1#include "ProgressState.h"
2
3#include <algorithm>
4
5ProgressState::ProgressState(const QString& stateName, QState* parent, float progress, Action action)
6 : QGCState(stateName, parent)
7 , _fixedProgress(std::clamp(progress, 0.0f, 1.0f))
8 , _action(std::move(action))
9 , _useCallback(false)
10{
11}
12
13ProgressState::ProgressState(const QString& stateName, QState* parent, ProgressCallback progressCallback, Action action)
14 : QGCState(stateName, parent)
15 , _progressCallback(std::move(progressCallback))
16 , _action(std::move(action))
17 , _useCallback(true)
18{
19}
20
22{
23 if (_useCallback && _progressCallback) {
24 return std::clamp(_progressCallback(), 0.0f, 1.0f);
25 }
26 return _fixedProgress;
27}
28
29void ProgressState::setProgress(float progress)
30{
31 _fixedProgress = std::clamp(progress, 0.0f, 1.0f);
32 _useCallback = false;
33}
34
36{
37 _progressCallback = std::move(callback);
38 _useCallback = true;
39}
40
42{
44
45 if (_action) {
46 _action();
47 }
48
49 emit advance();
50}
void onEnter() override
Override to perform actions on state entry.
float progress() const
Get the current progress value.
void progressChanged(float progress)
Emitted when the state is entered with the current progress value.
ProgressState(const QString &stateName, QState *parent, float progress, Action action=nullptr)
std::function< void()> Action
void setProgress(float progress)
Set a fixed progress value.
void setProgressCallback(ProgressCallback callback)
Set a progress callback.
std::function< float()> ProgressCallback