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