Skip to content

Commit ecd6d20

Browse files
committed
LP-597 Progress bar for GCS log replay - first batch of fixes from review and some others
- remove extraneous parentheses - use Qt naming convention for playbackPosition -> setPlaybackPosition - consistently use playback instead of playBack - most places: use of "state" instead of "status" - removed empty line - updated file headers - removed QThread include (leftover from debugging) - renamed pauseAndResetPosition to pauseReplayAndResetPosition for consistency with the related functions
1 parent fa70cb7 commit ecd6d20

4 files changed

Lines changed: 61 additions & 62 deletions

File tree

ground/gcs/src/libs/utils/logfile.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
******************************************************************************
33
*
44
* @file logfile.cpp
5-
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017-2018.
66
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
77
* @see The GNU Public License (GPL) Version 3
88
*
@@ -27,7 +27,6 @@
2727
#include <QDebug>
2828
#include <QtGlobal>
2929
#include <QDataStream>
30-
#include <QThread> // DEBUG: to display the thread ID
3130

3231
#define TIMESTAMP_SIZE_BYTES 4
3332

@@ -38,7 +37,7 @@ LogFile::LogFile(QObject *parent) : QIODevice(parent),
3837
m_lastPlayed(0),
3938
m_timeOffset(0),
4039
m_playbackSpeed(1.0),
41-
m_replayStatus(STOPPED),
40+
m_replayState(STOPPED),
4241
m_useProvidedTimeStamp(false),
4342
m_providedTimeStamp(0),
4443
m_beginTimeStamp(0),
@@ -150,10 +149,9 @@ qint64 LogFile::bytesAvailable() const
150149
This function is called at a 10 ms interval to fill the replay buffers.
151150
152151
*/
153-
154152
void LogFile::timerFired()
155153
{
156-
if (m_replayStatus != PLAYING) {
154+
if (m_replayState != PLAYING) {
157155
return;
158156
}
159157
m_timer_tick++;
@@ -213,7 +211,7 @@ void LogFile::timerFired()
213211

214212
// rate-limit slider bar position updates to 10 updates per second
215213
if (m_timer_tick % 10 == 0) {
216-
emit playbackPosition(m_nextTimeStamp);
214+
emit setPlaybackPosition(m_nextTimeStamp);
217215
}
218216
// read next timestamp
219217
if (m_file.bytesAvailable() < (qint64)sizeof(m_nextTimeStamp)) {
@@ -289,7 +287,7 @@ bool LogFile::startReplay()
289287

290288
m_timer.setInterval(10);
291289
m_timer.start();
292-
m_replayStatus = PLAYING;
290+
m_replayState = PLAYING;
293291

294292
emit replayStarted();
295293
return true;
@@ -312,7 +310,7 @@ bool LogFile::stopReplay()
312310
}
313311
qDebug() << "LogFile - stopReplay";
314312
m_timer.stop();
315-
m_replayStatus = STOPPED;
313+
m_replayState = STOPPED;
316314

317315
emit replayFinished();
318316
return true;
@@ -363,9 +361,9 @@ bool LogFile::resumeReplay(quint32 desiredPosition)
363361

364362
// Set the real-time interval to 0 to start with:
365363
m_myTime.restart();
366-
m_timeOffset = 0;
364+
m_timeOffset = 0;
367365

368-
m_replayStatus = PLAYING;
366+
m_replayState = PLAYING;
369367

370368
m_timer.start();
371369

@@ -387,27 +385,27 @@ bool LogFile::pauseReplay()
387385
}
388386
qDebug() << "LogFile - pauseReplay";
389387
m_timer.stop();
390-
m_replayStatus = PAUSED;
388+
m_replayState = PAUSED;
391389

392390
// hack to notify UI that replay paused
393391
emit replayStarted();
394392
return true;
395393
}
396394

397395
/**
398-
* SLOT: pauseAndResetPosition()
396+
* SLOT: pauseReplayAndResetPosition()
399397
*
400398
* Pauses replay and resets the playback position to the start of the logfile
401399
*
402400
*/
403-
bool LogFile::pauseAndResetPosition()
401+
bool LogFile::pauseReplayAndResetPosition()
404402
{
405403
if (!m_file.isOpen() || !m_timer.isActive()) {
406404
return false;
407405
}
408-
qDebug() << "LogFile - pauseAndResetPosition";
406+
qDebug() << "LogFile - pauseReplayAndResetPosition";
409407
m_timer.stop();
410-
m_replayStatus = STOPPED;
408+
m_replayState = STOPPED;
411409

412410
m_timeOffset = 0;
413411
m_lastPlayed = m_timeStamps.at(0);
@@ -418,14 +416,14 @@ bool LogFile::pauseAndResetPosition()
418416
}
419417

420418
/**
421-
* FUNCTION: getReplayStatus()
419+
* FUNCTION: getReplayState()
422420
*
423421
* Returns the current replay status.
424422
*
425423
*/
426-
ReplayState LogFile::getReplayStatus()
424+
ReplayState LogFile::getReplayState()
427425
{
428-
return m_replayStatus;
426+
return m_replayState;
429427
}
430428

431429
/**

ground/gcs/src/libs/utils/logfile.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
******************************************************************************
33
*
44
* @file logfile.h
5-
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017-2018.
66
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
77
* @see The GNU Public License (GPL) Version 3
88
*
@@ -32,7 +32,6 @@
3232
#include <QTimer>
3333
#include <QMutexLocker>
3434
#include <QDebug>
35-
#include <QBuffer>
3635
#include <QFile>
3736
#include <QVector>
3837

@@ -78,7 +77,7 @@ class QTCREATOR_UTILS_EXPORT LogFile : public QIODevice {
7877
m_providedTimeStamp = providedTimestamp;
7978
}
8079

81-
ReplayState getReplayStatus();
80+
ReplayState getReplayState();
8281

8382
public slots:
8483
void setReplaySpeed(double val)
@@ -91,15 +90,15 @@ public slots:
9190

9291
bool resumeReplay(quint32);
9392
bool pauseReplay();
94-
bool pauseAndResetPosition();
93+
bool pauseReplayAndResetPosition();
9594

9695
protected slots:
9796
void timerFired();
9897

9998
signals:
10099
void replayStarted();
101100
void replayFinished();
102-
void playbackPosition(quint32);
101+
void setPlaybackPosition(quint32);
103102
void updateBeginAndEndTimes(quint32, quint32);
104103

105104
protected:
@@ -116,7 +115,7 @@ protected slots:
116115

117116
int m_timeOffset;
118117
double m_playbackSpeed;
119-
ReplayState m_replayStatus;
118+
ReplayState m_replayState;
120119

121120
private:
122121
bool m_useProvidedTimeStamp;

ground/gcs/src/plugins/logging/logginggadgetwidget.cpp

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/**
22
******************************************************************************
33
*
4-
* @file GCSControlgadgetwidget.cpp
5-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
4+
* @file logginggadgetwidget.cpp
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018.
6+
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
67
* @addtogroup GCSPlugins GCS Plugins
78
* @{
8-
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
9+
* @addtogroup LoggingGadgetPlugin Logging Gadget Plugin
910
* @{
10-
* @brief A gadget to control the UAV, either from the keyboard or a joystick
11+
* @brief A gadget to control playback of a GCS log.
1112
*****************************************************************************/
1213
/*
1314
* This program is free software; you can redistribute it and/or modify
@@ -66,24 +67,24 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
6667
// GUI elements to gadgetwidget functions
6768
connect(m_logging->playPauseButton, &QPushButton::clicked, this, &LoggingGadgetWidget::playPauseButtonAction);
6869
connect(m_logging->stopButton, &QPushButton::clicked, this, &LoggingGadgetWidget::stopButtonAction);
69-
connect(m_logging->playBackPosition, &QSlider::valueChanged, this, &LoggingGadgetWidget::sliderMoved);
70+
connect(m_logging->playbackPosition, &QSlider::valueChanged, this, &LoggingGadgetWidget::sliderMoved);
7071

7172
connect(m_logging->playbackSpeed, static_cast<void(QDoubleSpinBox::*) (double)>(&QDoubleSpinBox::valueChanged), logFile, &LogFile::setReplaySpeed);
7273

7374
// gadgetwidget functions to logfile actions
7475
connect(this, &LoggingGadgetWidget::resumeReplay, logFile, &LogFile::resumeReplay);
7576
connect(this, &LoggingGadgetWidget::pauseReplay, logFile, &LogFile::pauseReplay);
76-
connect(this, &LoggingGadgetWidget::pauseAndResetPosition, logFile, &LogFile::pauseAndResetPosition);
77+
connect(this, &LoggingGadgetWidget::pauseReplayAndResetPosition, logFile, &LogFile::pauseReplayAndResetPosition);
7778

7879
// gadgetwidget functions to scope actions
7980
connect(this, &LoggingGadgetWidget::resumeReplay, scpPlugin, &ScopeGadgetFactory::startPlotting);
8081
connect(this, &LoggingGadgetWidget::pauseReplay, scpPlugin, &ScopeGadgetFactory::stopPlotting);
81-
connect(this, &LoggingGadgetWidget::pauseAndResetPosition, scpPlugin, &ScopeGadgetFactory::stopPlotting);
82+
connect(this, &LoggingGadgetWidget::pauseReplayAndResetPosition, scpPlugin, &ScopeGadgetFactory::stopPlotting);
8283

8384
// Feedback from logfile to GUI
8485
connect(loggingPlugin, &LoggingPlugin::stateChanged, this, &LoggingGadgetWidget::stateChanged);
8586
connect(logFile, &LogFile::updateBeginAndEndTimes, this, &LoggingGadgetWidget::updateBeginAndEndTimes);
86-
connect(logFile, &LogFile::playbackPosition, this, &LoggingGadgetWidget::playbackPosition);
87+
connect(logFile, &LogFile::setPlaybackPosition, this, &LoggingGadgetWidget::setPlaybackPosition);
8788
connect(logFile, &LogFile::replayStarted, this, &LoggingGadgetWidget::enableButtons);
8889
connect(logFile, &LogFile::replayFinished, this, &LoggingGadgetWidget::disableButtons);
8990

@@ -146,32 +147,32 @@ void LoggingGadgetWidget::setPlayPauseButtonToPause()
146147

147148
void LoggingGadgetWidget::playPauseButtonAction()
148149
{
149-
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus();
150+
ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
150151

151152
if (replayState == PLAYING) {
152153
emit pauseReplay();
153154
setPlayPauseButtonToPlay();
154155
} else {
155-
emit resumeReplay(m_logging->playBackPosition->value());
156+
emit resumeReplay(m_logging->playbackPosition->value());
156157
setPlayPauseButtonToPause();
157158
}
158159
m_logging->stopButton->setEnabled(true);
159160
}
160161

161162
void LoggingGadgetWidget::stopButtonAction()
162163
{
163-
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus();
164+
ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
164165

165166
if (replayState != STOPPED) {
166-
emit pauseAndResetPosition();
167+
emit pauseReplayAndResetPosition();
167168
}
168169
m_logging->stopButton->setEnabled(false);
169170
setPlayPauseButtonToPlay();
170171

171172
// Block signals while setting the slider to the start position
172-
m_logging->playBackPosition->blockSignals(true);
173-
m_logging->playBackPosition->setValue(m_logging->playBackPosition->minimum());
174-
m_logging->playBackPosition->blockSignals(false);
173+
m_logging->playbackPosition->blockSignals(true);
174+
m_logging->playbackPosition->setValue(m_logging->playbackPosition->minimum());
175+
m_logging->playbackPosition->blockSignals(false);
175176
}
176177

177178
void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state)
@@ -182,7 +183,7 @@ void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state)
182183
switch (state) {
183184
case LoggingPlugin::IDLE:
184185
status = tr("Idle");
185-
playbackPosition(0);
186+
setPlaybackPosition(0);
186187
break;
187188
case LoggingPlugin::LOGGING:
188189
status = tr("Logging");
@@ -219,23 +220,23 @@ void LoggingGadgetWidget::updateBeginAndEndTimes(quint32 startTimeStamp, quint32
219220
m_logging->endTimeLabel->setText(QString("%1:%2").arg(endMin, 2, 10, QChar('0')).arg(endSec, 2, 10, QChar('0')));
220221

221222
// Update position bar
222-
m_logging->playBackPosition->setMinimum(startTimeStamp);
223-
m_logging->playBackPosition->setMaximum(endTimeStamp);
223+
m_logging->playbackPosition->setMinimum(startTimeStamp);
224+
m_logging->playbackPosition->setMaximum(endTimeStamp);
224225

225-
m_logging->playBackPosition->setSingleStep((endTimeStamp - startTimeStamp) / 100);
226-
m_logging->playBackPosition->setPageStep((endTimeStamp - startTimeStamp) / 10);
227-
m_logging->playBackPosition->setTickInterval((endTimeStamp - startTimeStamp) / 10);
228-
m_logging->playBackPosition->setTickPosition(QSlider::TicksBothSides);
226+
m_logging->playbackPosition->setSingleStep((endTimeStamp - startTimeStamp) / 100);
227+
m_logging->playbackPosition->setPageStep((endTimeStamp - startTimeStamp) / 10);
228+
m_logging->playbackPosition->setTickInterval((endTimeStamp - startTimeStamp) / 10);
229+
m_logging->playbackPosition->setTickPosition(QSlider::TicksBothSides);
229230
}
230231

231-
void LoggingGadgetWidget::playbackPosition(quint32 positionTimeStamp)
232+
void LoggingGadgetWidget::setPlaybackPosition(quint32 positionTimeStamp)
232233
{
233234
// Update position bar, but only if the user is not updating the slider position
234-
if (!m_logging->playBackPosition->isSliderDown() && !sliderActionDelay.isActive()) {
235+
if (!m_logging->playbackPosition->isSliderDown() && !sliderActionDelay.isActive()) {
235236
// Block signals during slider position update:
236-
m_logging->playBackPosition->blockSignals(true);
237-
m_logging->playBackPosition->setValue(positionTimeStamp);
238-
m_logging->playBackPosition->blockSignals(false);
237+
m_logging->playbackPosition->blockSignals(true);
238+
m_logging->playbackPosition->setValue(positionTimeStamp);
239+
m_logging->playbackPosition->blockSignals(false);
239240

240241
// update position label
241242
updatePositionLabel(positionTimeStamp);
@@ -244,7 +245,7 @@ void LoggingGadgetWidget::playbackPosition(quint32 positionTimeStamp)
244245

245246
void LoggingGadgetWidget::enableButtons()
246247
{
247-
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus();
248+
ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
248249

249250
switch (replayState) {
250251
case STOPPED:
@@ -263,7 +264,7 @@ void LoggingGadgetWidget::enableButtons()
263264
break;
264265
}
265266
m_logging->playPauseButton->setEnabled(true);
266-
m_logging->playBackPosition->setEnabled(true);
267+
m_logging->playbackPosition->setEnabled(true);
267268
}
268269

269270
void LoggingGadgetWidget::disableButtons()
@@ -272,7 +273,7 @@ void LoggingGadgetWidget::disableButtons()
272273
setPlayPauseButtonToPlay();
273274
m_logging->stopButton->setEnabled(false);
274275

275-
m_logging->playBackPosition->setEnabled(false);
276+
m_logging->playbackPosition->setEnabled(false);
276277
}
277278

278279
void LoggingGadgetWidget::updateButtonAppearance()
@@ -283,7 +284,7 @@ void LoggingGadgetWidget::updateButtonAppearance()
283284
// loggingPlugin has not been completely initialized: set to STOPPED state
284285
replayState = STOPPED;
285286
} else {
286-
replayState = (loggingPlugin->getLogfile())->getReplayStatus();
287+
replayState = loggingPlugin->getLogfile()->getReplayState();
287288
}
288289

289290
// Update playPause button appearance
@@ -325,7 +326,7 @@ void LoggingGadgetWidget::sliderMoved(int position)
325326

326327
void LoggingGadgetWidget::sliderAction()
327328
{
328-
emit resumeReplay(m_logging->playBackPosition->value());
329+
emit resumeReplay(m_logging->playbackPosition->value());
329330
}
330331

331332

ground/gcs/src/plugins/logging/logginggadgetwidget.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/**
22
******************************************************************************
33
*
4-
* @file GCSControlgadgetwidget.h
5-
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
4+
* @file logginggadgetwidget.h
5+
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018.
6+
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
67
* @addtogroup GCSPlugins GCS Plugins
78
* @{
8-
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
9+
* @addtogroup LoggingGadgetPlugin Logging Gadget Plugin
910
* @{
10-
* @brief A place holder gadget plugin
11+
* @brief A gadget to control playback of a GCS log.
1112
*****************************************************************************/
1213
/*
1314
* This program is free software; you can redistribute it and/or modify
@@ -50,7 +51,7 @@ class LoggingGadgetWidget : public QWidget {
5051
protected slots:
5152
void stateChanged(LoggingPlugin::State state);
5253
void updateBeginAndEndTimes(quint32 startTimeStamp, quint32 endTimeStamp);
53-
void playbackPosition(quint32 positionTimeStamp);
54+
void setPlaybackPosition(quint32 positionTimeStamp);
5455
void playPauseButtonAction();
5556
void stopButtonAction();
5657
void enableButtons();
@@ -61,7 +62,7 @@ protected slots:
6162
signals:
6263
void resumeReplay(quint32 positionTimeStamp);
6364
void pauseReplay();
64-
void pauseAndResetPosition();
65+
void pauseReplayAndResetPosition();
6566

6667
private:
6768
Ui_Logging *m_logging;

0 commit comments

Comments
 (0)