QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LogReplayLinkController.cc
Go to the documentation of this file.
3
4QGC_LOGGING_CATEGORY(LogReplayLinkControllerLog, "Comms.LogReplayLinkController")
5
7 : QObject(parent)
8{
9 qCDebug(LogReplayLinkControllerLog) << this;
10}
11
12LogReplayLinkController::~LogReplayLinkController()
13{
14 qCDebug(LogReplayLinkControllerLog) << this;
15}
16
17void LogReplayLinkController::setLink(LogReplayLink *link)
18{
19 if (_link) {
20 (void) disconnect(_link);
22
23 _isPlaying = false;
24 emit isPlayingChanged(_isPlaying);
25
26 _percentComplete = 0;
27 emit percentCompleteChanged(_percentComplete);
28
29 _playheadTime.clear();
30 emit playheadTimeChanged(_playheadTime);
31
32 _totalTime.clear();
33 emit totalTimeChanged(_totalTime);
34
35 _link = nullptr;
36 emit linkChanged(_link);
37 }
38
39 if (link) {
40 _link = link;
41
42 (void) connect(_link, &LogReplayLink::logFileStats, this, &LogReplayLinkController::_logFileStats);
43 (void) connect(_link, &LogReplayLink::playbackStarted, this, &LogReplayLinkController::_playbackStarted);
44 (void) connect(_link, &LogReplayLink::playbackPaused, this, &LogReplayLinkController::_playbackPaused);
45 (void) connect(_link, &LogReplayLink::playbackPercentCompleteChanged, this, &LogReplayLinkController::_playbackPercentCompleteChanged);
46 (void) connect(_link, &LogReplayLink::currentLogTimeSecs, this, &LogReplayLinkController::_currentLogTimeSecs);
47 (void) connect(_link, &LogReplayLink::disconnected, this, &LogReplayLinkController::_linkDisconnected);
48
50
51 emit linkChanged(_link);
52 }
53}
54
55void LogReplayLinkController::setIsPlaying(bool isPlaying) const
56{
57 if (!_link) {
58 return;
59 }
60
61 if (isPlaying) {
62 _link->play();
63 } else {
64 _link->pause();
65 }
66}
67
68void LogReplayLinkController::setPercentComplete(qreal percentComplete) const
69{
70 if (!_link) {
71 return;
72 }
73
74 _link->movePlayhead(percentComplete);
75}
76
77void LogReplayLinkController::_logFileStats(uint32_t logDurationSecs)
78{
79 const QString totalTime = _secondsToHMS(logDurationSecs);
80 if (totalTime != _totalTime) {
81 _totalTime = totalTime;
82 emit totalTimeChanged(_totalTime);
83 }
84}
85
86void LogReplayLinkController::_playbackStarted()
87{
88 if (!_isPlaying) {
89 _isPlaying = true;
90 emit isPlayingChanged(_isPlaying);
91 }
92}
93
94void LogReplayLinkController::_playbackPaused()
95{
96 if (_isPlaying) {
97 _isPlaying = false;
98 emit isPlayingChanged(_isPlaying);
99 }
100}
101
102void LogReplayLinkController::_playbackAtEnd()
103{
104 if (_isPlaying) {
105 _isPlaying = false;
106 emit isPlayingChanged(_isPlaying);
107 }
108}
109
110void LogReplayLinkController::_playbackPercentCompleteChanged(qreal percentComplete)
111{
112 if (percentComplete != _percentComplete) {
113 _percentComplete = percentComplete;
114 emit percentCompleteChanged(_percentComplete);
115 }
116}
117
118void LogReplayLinkController::_currentLogTimeSecs(uint32_t secs)
119{
120 if (secs != _playheadSecs) {
121 _playheadSecs = secs;
122 _playheadTime = _secondsToHMS(secs);
123 emit playheadTimeChanged(_playheadTime);
124 }
125}
126
127QString LogReplayLinkController::_secondsToHMS(uint32_t seconds)
128{
129 uint32_t secondsPart = seconds;
130 uint32_t minutesPart = secondsPart / 60;
131 const uint32_t hoursPart = minutesPart / 60;
132 secondsPart -= (60 * minutesPart);
133 minutesPart -= (60 * hoursPart);
134
135 QString result = QStringLiteral("%2m:%3s").arg(minutesPart, 2, 10, QLatin1Char('0')).arg(secondsPart, 2, 10, QLatin1Char('0'));
136 if (hoursPart != 0) {
137 (void) result.prepend(QStringLiteral("%1h:").arg(hoursPart, 2, 10, QLatin1Char('0')));
138 }
139
140 return result;
141}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void disconnected()
void percentCompleteChanged(qreal percentComplete)
void isPlayingChanged(bool isPlaying)
void playheadTimeChanged(const QString &playheadTime)
void totalTimeChanged(const QString &totalTime)
void playbackSpeedChanged(qreal playbackSpeed)
void linkChanged(LogReplayLink *link)