1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

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
This commit is contained in:
Jan NIJS 2018-04-30 19:09:38 +02:00
parent fa70cb751c
commit ecd6d20b13
4 changed files with 61 additions and 62 deletions

View File

@ -2,7 +2,7 @@
****************************************************************************** ******************************************************************************
* *
* @file logfile.cpp * @file logfile.cpp
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017-2018.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* *
@ -27,7 +27,6 @@
#include <QDebug> #include <QDebug>
#include <QtGlobal> #include <QtGlobal>
#include <QDataStream> #include <QDataStream>
#include <QThread> // DEBUG: to display the thread ID
#define TIMESTAMP_SIZE_BYTES 4 #define TIMESTAMP_SIZE_BYTES 4
@ -38,7 +37,7 @@ LogFile::LogFile(QObject *parent) : QIODevice(parent),
m_lastPlayed(0), m_lastPlayed(0),
m_timeOffset(0), m_timeOffset(0),
m_playbackSpeed(1.0), m_playbackSpeed(1.0),
m_replayStatus(STOPPED), m_replayState(STOPPED),
m_useProvidedTimeStamp(false), m_useProvidedTimeStamp(false),
m_providedTimeStamp(0), m_providedTimeStamp(0),
m_beginTimeStamp(0), m_beginTimeStamp(0),
@ -150,10 +149,9 @@ qint64 LogFile::bytesAvailable() const
This function is called at a 10 ms interval to fill the replay buffers. This function is called at a 10 ms interval to fill the replay buffers.
*/ */
void LogFile::timerFired() void LogFile::timerFired()
{ {
if (m_replayStatus != PLAYING) { if (m_replayState != PLAYING) {
return; return;
} }
m_timer_tick++; m_timer_tick++;
@ -213,7 +211,7 @@ void LogFile::timerFired()
// rate-limit slider bar position updates to 10 updates per second // rate-limit slider bar position updates to 10 updates per second
if (m_timer_tick % 10 == 0) { if (m_timer_tick % 10 == 0) {
emit playbackPosition(m_nextTimeStamp); emit setPlaybackPosition(m_nextTimeStamp);
} }
// read next timestamp // read next timestamp
if (m_file.bytesAvailable() < (qint64)sizeof(m_nextTimeStamp)) { if (m_file.bytesAvailable() < (qint64)sizeof(m_nextTimeStamp)) {
@ -289,7 +287,7 @@ bool LogFile::startReplay()
m_timer.setInterval(10); m_timer.setInterval(10);
m_timer.start(); m_timer.start();
m_replayStatus = PLAYING; m_replayState = PLAYING;
emit replayStarted(); emit replayStarted();
return true; return true;
@ -312,7 +310,7 @@ bool LogFile::stopReplay()
} }
qDebug() << "LogFile - stopReplay"; qDebug() << "LogFile - stopReplay";
m_timer.stop(); m_timer.stop();
m_replayStatus = STOPPED; m_replayState = STOPPED;
emit replayFinished(); emit replayFinished();
return true; return true;
@ -363,9 +361,9 @@ bool LogFile::resumeReplay(quint32 desiredPosition)
// Set the real-time interval to 0 to start with: // Set the real-time interval to 0 to start with:
m_myTime.restart(); m_myTime.restart();
m_timeOffset = 0; m_timeOffset = 0;
m_replayStatus = PLAYING; m_replayState = PLAYING;
m_timer.start(); m_timer.start();
@ -387,7 +385,7 @@ bool LogFile::pauseReplay()
} }
qDebug() << "LogFile - pauseReplay"; qDebug() << "LogFile - pauseReplay";
m_timer.stop(); m_timer.stop();
m_replayStatus = PAUSED; m_replayState = PAUSED;
// hack to notify UI that replay paused // hack to notify UI that replay paused
emit replayStarted(); emit replayStarted();
@ -395,19 +393,19 @@ bool LogFile::pauseReplay()
} }
/** /**
* SLOT: pauseAndResetPosition() * SLOT: pauseReplayAndResetPosition()
* *
* Pauses replay and resets the playback position to the start of the logfile * Pauses replay and resets the playback position to the start of the logfile
* *
*/ */
bool LogFile::pauseAndResetPosition() bool LogFile::pauseReplayAndResetPosition()
{ {
if (!m_file.isOpen() || !m_timer.isActive()) { if (!m_file.isOpen() || !m_timer.isActive()) {
return false; return false;
} }
qDebug() << "LogFile - pauseAndResetPosition"; qDebug() << "LogFile - pauseReplayAndResetPosition";
m_timer.stop(); m_timer.stop();
m_replayStatus = STOPPED; m_replayState = STOPPED;
m_timeOffset = 0; m_timeOffset = 0;
m_lastPlayed = m_timeStamps.at(0); m_lastPlayed = m_timeStamps.at(0);
@ -418,14 +416,14 @@ bool LogFile::pauseAndResetPosition()
} }
/** /**
* FUNCTION: getReplayStatus() * FUNCTION: getReplayState()
* *
* Returns the current replay status. * Returns the current replay status.
* *
*/ */
ReplayState LogFile::getReplayStatus() ReplayState LogFile::getReplayState()
{ {
return m_replayStatus; return m_replayState;
} }
/** /**

View File

@ -2,7 +2,7 @@
****************************************************************************** ******************************************************************************
* *
* @file logfile.h * @file logfile.h
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017-2018.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* *
@ -32,7 +32,6 @@
#include <QTimer> #include <QTimer>
#include <QMutexLocker> #include <QMutexLocker>
#include <QDebug> #include <QDebug>
#include <QBuffer>
#include <QFile> #include <QFile>
#include <QVector> #include <QVector>
@ -78,7 +77,7 @@ public:
m_providedTimeStamp = providedTimestamp; m_providedTimeStamp = providedTimestamp;
} }
ReplayState getReplayStatus(); ReplayState getReplayState();
public slots: public slots:
void setReplaySpeed(double val) void setReplaySpeed(double val)
@ -91,7 +90,7 @@ public slots:
bool resumeReplay(quint32); bool resumeReplay(quint32);
bool pauseReplay(); bool pauseReplay();
bool pauseAndResetPosition(); bool pauseReplayAndResetPosition();
protected slots: protected slots:
void timerFired(); void timerFired();
@ -99,7 +98,7 @@ protected slots:
signals: signals:
void replayStarted(); void replayStarted();
void replayFinished(); void replayFinished();
void playbackPosition(quint32); void setPlaybackPosition(quint32);
void updateBeginAndEndTimes(quint32, quint32); void updateBeginAndEndTimes(quint32, quint32);
protected: protected:
@ -116,7 +115,7 @@ protected:
int m_timeOffset; int m_timeOffset;
double m_playbackSpeed; double m_playbackSpeed;
ReplayState m_replayStatus; ReplayState m_replayState;
private: private:
bool m_useProvidedTimeStamp; bool m_useProvidedTimeStamp;

View File

@ -1,13 +1,14 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file GCSControlgadgetwidget.cpp * @file logginggadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins * @addtogroup GCSPlugins GCS Plugins
* @{ * @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin * @addtogroup LoggingGadgetPlugin Logging Gadget Plugin
* @{ * @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick * @brief A gadget to control playback of a GCS log.
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -66,24 +67,24 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
// GUI elements to gadgetwidget functions // GUI elements to gadgetwidget functions
connect(m_logging->playPauseButton, &QPushButton::clicked, this, &LoggingGadgetWidget::playPauseButtonAction); connect(m_logging->playPauseButton, &QPushButton::clicked, this, &LoggingGadgetWidget::playPauseButtonAction);
connect(m_logging->stopButton, &QPushButton::clicked, this, &LoggingGadgetWidget::stopButtonAction); connect(m_logging->stopButton, &QPushButton::clicked, this, &LoggingGadgetWidget::stopButtonAction);
connect(m_logging->playBackPosition, &QSlider::valueChanged, this, &LoggingGadgetWidget::sliderMoved); connect(m_logging->playbackPosition, &QSlider::valueChanged, this, &LoggingGadgetWidget::sliderMoved);
connect(m_logging->playbackSpeed, static_cast<void(QDoubleSpinBox::*) (double)>(&QDoubleSpinBox::valueChanged), logFile, &LogFile::setReplaySpeed); connect(m_logging->playbackSpeed, static_cast<void(QDoubleSpinBox::*) (double)>(&QDoubleSpinBox::valueChanged), logFile, &LogFile::setReplaySpeed);
// gadgetwidget functions to logfile actions // gadgetwidget functions to logfile actions
connect(this, &LoggingGadgetWidget::resumeReplay, logFile, &LogFile::resumeReplay); connect(this, &LoggingGadgetWidget::resumeReplay, logFile, &LogFile::resumeReplay);
connect(this, &LoggingGadgetWidget::pauseReplay, logFile, &LogFile::pauseReplay); connect(this, &LoggingGadgetWidget::pauseReplay, logFile, &LogFile::pauseReplay);
connect(this, &LoggingGadgetWidget::pauseAndResetPosition, logFile, &LogFile::pauseAndResetPosition); connect(this, &LoggingGadgetWidget::pauseReplayAndResetPosition, logFile, &LogFile::pauseReplayAndResetPosition);
// gadgetwidget functions to scope actions // gadgetwidget functions to scope actions
connect(this, &LoggingGadgetWidget::resumeReplay, scpPlugin, &ScopeGadgetFactory::startPlotting); connect(this, &LoggingGadgetWidget::resumeReplay, scpPlugin, &ScopeGadgetFactory::startPlotting);
connect(this, &LoggingGadgetWidget::pauseReplay, scpPlugin, &ScopeGadgetFactory::stopPlotting); connect(this, &LoggingGadgetWidget::pauseReplay, scpPlugin, &ScopeGadgetFactory::stopPlotting);
connect(this, &LoggingGadgetWidget::pauseAndResetPosition, scpPlugin, &ScopeGadgetFactory::stopPlotting); connect(this, &LoggingGadgetWidget::pauseReplayAndResetPosition, scpPlugin, &ScopeGadgetFactory::stopPlotting);
// Feedback from logfile to GUI // Feedback from logfile to GUI
connect(loggingPlugin, &LoggingPlugin::stateChanged, this, &LoggingGadgetWidget::stateChanged); connect(loggingPlugin, &LoggingPlugin::stateChanged, this, &LoggingGadgetWidget::stateChanged);
connect(logFile, &LogFile::updateBeginAndEndTimes, this, &LoggingGadgetWidget::updateBeginAndEndTimes); connect(logFile, &LogFile::updateBeginAndEndTimes, this, &LoggingGadgetWidget::updateBeginAndEndTimes);
connect(logFile, &LogFile::playbackPosition, this, &LoggingGadgetWidget::playbackPosition); connect(logFile, &LogFile::setPlaybackPosition, this, &LoggingGadgetWidget::setPlaybackPosition);
connect(logFile, &LogFile::replayStarted, this, &LoggingGadgetWidget::enableButtons); connect(logFile, &LogFile::replayStarted, this, &LoggingGadgetWidget::enableButtons);
connect(logFile, &LogFile::replayFinished, this, &LoggingGadgetWidget::disableButtons); connect(logFile, &LogFile::replayFinished, this, &LoggingGadgetWidget::disableButtons);
@ -146,13 +147,13 @@ void LoggingGadgetWidget::setPlayPauseButtonToPause()
void LoggingGadgetWidget::playPauseButtonAction() void LoggingGadgetWidget::playPauseButtonAction()
{ {
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus(); ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
if (replayState == PLAYING) { if (replayState == PLAYING) {
emit pauseReplay(); emit pauseReplay();
setPlayPauseButtonToPlay(); setPlayPauseButtonToPlay();
} else { } else {
emit resumeReplay(m_logging->playBackPosition->value()); emit resumeReplay(m_logging->playbackPosition->value());
setPlayPauseButtonToPause(); setPlayPauseButtonToPause();
} }
m_logging->stopButton->setEnabled(true); m_logging->stopButton->setEnabled(true);
@ -160,18 +161,18 @@ void LoggingGadgetWidget::playPauseButtonAction()
void LoggingGadgetWidget::stopButtonAction() void LoggingGadgetWidget::stopButtonAction()
{ {
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus(); ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
if (replayState != STOPPED) { if (replayState != STOPPED) {
emit pauseAndResetPosition(); emit pauseReplayAndResetPosition();
} }
m_logging->stopButton->setEnabled(false); m_logging->stopButton->setEnabled(false);
setPlayPauseButtonToPlay(); setPlayPauseButtonToPlay();
// Block signals while setting the slider to the start position // Block signals while setting the slider to the start position
m_logging->playBackPosition->blockSignals(true); m_logging->playbackPosition->blockSignals(true);
m_logging->playBackPosition->setValue(m_logging->playBackPosition->minimum()); m_logging->playbackPosition->setValue(m_logging->playbackPosition->minimum());
m_logging->playBackPosition->blockSignals(false); m_logging->playbackPosition->blockSignals(false);
} }
void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state) void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state)
@ -182,7 +183,7 @@ void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state)
switch (state) { switch (state) {
case LoggingPlugin::IDLE: case LoggingPlugin::IDLE:
status = tr("Idle"); status = tr("Idle");
playbackPosition(0); setPlaybackPosition(0);
break; break;
case LoggingPlugin::LOGGING: case LoggingPlugin::LOGGING:
status = tr("Logging"); status = tr("Logging");
@ -219,23 +220,23 @@ void LoggingGadgetWidget::updateBeginAndEndTimes(quint32 startTimeStamp, quint32
m_logging->endTimeLabel->setText(QString("%1:%2").arg(endMin, 2, 10, QChar('0')).arg(endSec, 2, 10, QChar('0'))); m_logging->endTimeLabel->setText(QString("%1:%2").arg(endMin, 2, 10, QChar('0')).arg(endSec, 2, 10, QChar('0')));
// Update position bar // Update position bar
m_logging->playBackPosition->setMinimum(startTimeStamp); m_logging->playbackPosition->setMinimum(startTimeStamp);
m_logging->playBackPosition->setMaximum(endTimeStamp); m_logging->playbackPosition->setMaximum(endTimeStamp);
m_logging->playBackPosition->setSingleStep((endTimeStamp - startTimeStamp) / 100); m_logging->playbackPosition->setSingleStep((endTimeStamp - startTimeStamp) / 100);
m_logging->playBackPosition->setPageStep((endTimeStamp - startTimeStamp) / 10); m_logging->playbackPosition->setPageStep((endTimeStamp - startTimeStamp) / 10);
m_logging->playBackPosition->setTickInterval((endTimeStamp - startTimeStamp) / 10); m_logging->playbackPosition->setTickInterval((endTimeStamp - startTimeStamp) / 10);
m_logging->playBackPosition->setTickPosition(QSlider::TicksBothSides); m_logging->playbackPosition->setTickPosition(QSlider::TicksBothSides);
} }
void LoggingGadgetWidget::playbackPosition(quint32 positionTimeStamp) void LoggingGadgetWidget::setPlaybackPosition(quint32 positionTimeStamp)
{ {
// Update position bar, but only if the user is not updating the slider position // Update position bar, but only if the user is not updating the slider position
if (!m_logging->playBackPosition->isSliderDown() && !sliderActionDelay.isActive()) { if (!m_logging->playbackPosition->isSliderDown() && !sliderActionDelay.isActive()) {
// Block signals during slider position update: // Block signals during slider position update:
m_logging->playBackPosition->blockSignals(true); m_logging->playbackPosition->blockSignals(true);
m_logging->playBackPosition->setValue(positionTimeStamp); m_logging->playbackPosition->setValue(positionTimeStamp);
m_logging->playBackPosition->blockSignals(false); m_logging->playbackPosition->blockSignals(false);
// update position label // update position label
updatePositionLabel(positionTimeStamp); updatePositionLabel(positionTimeStamp);
@ -244,7 +245,7 @@ void LoggingGadgetWidget::playbackPosition(quint32 positionTimeStamp)
void LoggingGadgetWidget::enableButtons() void LoggingGadgetWidget::enableButtons()
{ {
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus(); ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
switch (replayState) { switch (replayState) {
case STOPPED: case STOPPED:
@ -263,7 +264,7 @@ void LoggingGadgetWidget::enableButtons()
break; break;
} }
m_logging->playPauseButton->setEnabled(true); m_logging->playPauseButton->setEnabled(true);
m_logging->playBackPosition->setEnabled(true); m_logging->playbackPosition->setEnabled(true);
} }
void LoggingGadgetWidget::disableButtons() void LoggingGadgetWidget::disableButtons()
@ -272,7 +273,7 @@ void LoggingGadgetWidget::disableButtons()
setPlayPauseButtonToPlay(); setPlayPauseButtonToPlay();
m_logging->stopButton->setEnabled(false); m_logging->stopButton->setEnabled(false);
m_logging->playBackPosition->setEnabled(false); m_logging->playbackPosition->setEnabled(false);
} }
void LoggingGadgetWidget::updateButtonAppearance() void LoggingGadgetWidget::updateButtonAppearance()
@ -283,7 +284,7 @@ void LoggingGadgetWidget::updateButtonAppearance()
// loggingPlugin has not been completely initialized: set to STOPPED state // loggingPlugin has not been completely initialized: set to STOPPED state
replayState = STOPPED; replayState = STOPPED;
} else { } else {
replayState = (loggingPlugin->getLogfile())->getReplayStatus(); replayState = loggingPlugin->getLogfile()->getReplayState();
} }
// Update playPause button appearance // Update playPause button appearance
@ -325,7 +326,7 @@ void LoggingGadgetWidget::sliderMoved(int position)
void LoggingGadgetWidget::sliderAction() void LoggingGadgetWidget::sliderAction()
{ {
emit resumeReplay(m_logging->playBackPosition->value()); emit resumeReplay(m_logging->playbackPosition->value());
} }

View File

@ -1,13 +1,14 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file GCSControlgadgetwidget.h * @file logginggadgetwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2018.
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins * @addtogroup GCSPlugins GCS Plugins
* @{ * @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin * @addtogroup LoggingGadgetPlugin Logging Gadget Plugin
* @{ * @{
* @brief A place holder gadget plugin * @brief A gadget to control playback of a GCS log.
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -50,7 +51,7 @@ public:
protected slots: protected slots:
void stateChanged(LoggingPlugin::State state); void stateChanged(LoggingPlugin::State state);
void updateBeginAndEndTimes(quint32 startTimeStamp, quint32 endTimeStamp); void updateBeginAndEndTimes(quint32 startTimeStamp, quint32 endTimeStamp);
void playbackPosition(quint32 positionTimeStamp); void setPlaybackPosition(quint32 positionTimeStamp);
void playPauseButtonAction(); void playPauseButtonAction();
void stopButtonAction(); void stopButtonAction();
void enableButtons(); void enableButtons();
@ -61,7 +62,7 @@ protected slots:
signals: signals:
void resumeReplay(quint32 positionTimeStamp); void resumeReplay(quint32 positionTimeStamp);
void pauseReplay(); void pauseReplay();
void pauseAndResetPosition(); void pauseReplayAndResetPosition();
private: private:
Ui_Logging *m_logging; Ui_Logging *m_logging;