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) disconnect(_link);
24
25 _isPlaying = false;
26 emit isPlayingChanged(_isPlaying);
27
28 _percentComplete = 0;
29 emit percentCompleteChanged(_percentComplete);
30
31 _playheadTime.clear();
32 emit playheadTimeChanged(_playheadTime);
33
34 _totalTime.clear();
35 emit totalTimeChanged(_totalTime);
36
37 _link = nullptr;
38 emit linkChanged(_link);
39 }
40
41 if (link) {
42 _link = link;
43
44 (void) connect(_link, &LogReplayLink::logFileStats, this, &LogReplayLinkController::_logFileStats);
45 (void) connect(_link, &LogReplayLink::playbackStarted, this, &LogReplayLinkController::_playbackStarted);
46 (void) connect(_link, &LogReplayLink::playbackPaused, this, &LogReplayLinkController::_playbackPaused);
47 (void) connect(_link, &LogReplayLink::playbackPercentCompleteChanged, this, &LogReplayLinkController::_playbackPercentCompleteChanged);
48 (void) connect(_link, &LogReplayLink::currentLogTimeSecs, this, &LogReplayLinkController::_currentLogTimeSecs);
49 (void) connect(_link, &LogReplayLink::disconnected, this, &LogReplayLinkController::_linkDisconnected);
50
52
53 emit linkChanged(_link);
54 }
55}
56
57void LogReplayLinkController::setIsPlaying(bool isPlaying) const
58{
59 if (!_link) {
60 return;
61 }
62
63 if (isPlaying) {
64 _link->play();
65 } else {
66 _link->pause();
67 }
68}
69
70void LogReplayLinkController::setPercentComplete(qreal percentComplete) const
71{
72 if (!_link) {
73 return;
74 }
75
76 _link->movePlayhead(percentComplete);
77}
78
79void LogReplayLinkController::_logFileStats(uint32_t logDurationSecs)
80{
81 const QString totalTime = _secondsToHMS(logDurationSecs);
82 if (totalTime != _totalTime) {
83 _totalTime = totalTime;
84 emit totalTimeChanged(_totalTime);
85 }
86}
87
88void LogReplayLinkController::_playbackStarted()
89{
90 if (!_isPlaying) {
91 _isPlaying = true;
92 emit isPlayingChanged(_isPlaying);
93 }
94}
95
96void LogReplayLinkController::_playbackPaused()
97{
98 if (_isPlaying) {
99 _isPlaying = false;
100 emit isPlayingChanged(_isPlaying);
101 }
102}
103
104void LogReplayLinkController::_playbackAtEnd()
105{
106 if (_isPlaying) {
107 _isPlaying = false;
108 emit isPlayingChanged(_isPlaying);
109 }
110}
111
112void LogReplayLinkController::_playbackPercentCompleteChanged(qreal percentComplete)
113{
114 if (percentComplete != _percentComplete) {
115 _percentComplete = percentComplete;
116 emit percentCompleteChanged(_percentComplete);
117 }
118}
119
120void LogReplayLinkController::_currentLogTimeSecs(uint32_t secs)
121{
122 if (secs != _playheadSecs) {
123 _playheadSecs = secs;
124 _playheadTime = _secondsToHMS(secs);
125 emit playheadTimeChanged(_playheadTime);
126 }
127}
128
129QString LogReplayLinkController::_secondsToHMS(uint32_t seconds)
130{
131 uint32_t secondsPart = seconds;
132 uint32_t minutesPart = secondsPart / 60;
133 const uint32_t hoursPart = minutesPart / 60;
134 secondsPart -= (60 * minutesPart);
135 minutesPart -= (60 * hoursPart);
136
137 QString result = QStringLiteral("%2m:%3s").arg(minutesPart, 2, 10, QLatin1Char('0')).arg(secondsPart, 2, 10, QLatin1Char('0'));
138 if (hoursPart != 0) {
139 (void) result.prepend(QStringLiteral("%1h:").arg(hoursPart, 2, 10, QLatin1Char('0')));
140 }
141
142 return result;
143}
#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)