diff --git a/ground/gcs/src/libs/utils/logfile.cpp b/ground/gcs/src/libs/utils/logfile.cpp index 70a1060f1..547eb7f68 100644 --- a/ground/gcs/src/libs/utils/logfile.cpp +++ b/ground/gcs/src/libs/utils/logfile.cpp @@ -182,7 +182,7 @@ void LogFile::timerFired() qint64 dataSize; if (m_file.bytesAvailable() < (qint64)sizeof(dataSize)) { qDebug() << "LogFile replay - end of log file reached"; - stopReplay(); + resetReplay(); return; } m_file.read((char *)&dataSize, sizeof(dataSize)); @@ -197,7 +197,7 @@ void LogFile::timerFired() // read data if (m_file.bytesAvailable() < dataSize) { qDebug() << "LogFile replay - end of log file reached"; - stopReplay(); + resetReplay(); return; } QByteArray data = m_file.read(dataSize); @@ -216,7 +216,7 @@ void LogFile::timerFired() // read next timestamp if (m_file.bytesAvailable() < (qint64)sizeof(m_nextTimeStamp)) { qDebug() << "LogFile replay - end of log file reached"; - stopReplay(); + resetReplay(); return; } m_previousTimeStamp = m_nextTimeStamp; @@ -235,7 +235,7 @@ void LogFile::timerFired() } } else { qDebug() << "LogFile replay - end of log file reached"; - stopReplay(); + resetReplay(); } } @@ -319,6 +319,31 @@ bool LogFile::stopReplay() return true; } +/** + * FUNCTION: resetReplay() + * + * Stops replaying the logfile. + * Stops the timer: m_timer + * Resets playback position to the start of the logfile + * through the emission of a replayCompleted signal. + * + */ +bool LogFile::resetReplay() +{ + if (!m_file.isOpen()) { + return false; + } + if (m_timer.isActive()) { + m_timer.stop(); + } + + qDebug() << "LogFile - resetReplay"; + m_replayState = STOPPED; + + emit replayCompleted(); + return true; +} + /** * SLOT: resumeReplay() * diff --git a/ground/gcs/src/libs/utils/logfile.h b/ground/gcs/src/libs/utils/logfile.h index 7e19c02a0..055fdabe2 100644 --- a/ground/gcs/src/libs/utils/logfile.h +++ b/ground/gcs/src/libs/utils/logfile.h @@ -97,7 +97,8 @@ protected slots: signals: void replayStarted(); - void replayFinished(); + void replayFinished(); // Emitted on error during replay or when logfile disconnected + void replayCompleted(); // Emitted at the end of normal logfile playback void setPlaybackPosition(quint32); void setBeginAndEndTimes(quint32, quint32); @@ -127,6 +128,7 @@ private: QVector m_timeStampPositions; bool buildIndex(); + bool resetReplay(); }; #endif // LOGFILE_H diff --git a/ground/gcs/src/plugins/logging/logging.ui b/ground/gcs/src/plugins/logging/logging.ui index e9537c935..fff8804fc 100644 --- a/ground/gcs/src/plugins/logging/logging.ui +++ b/ground/gcs/src/plugins/logging/logging.ui @@ -32,7 +32,10 @@ 3 - + + + 4 + QLayout::SetNoConstraint @@ -50,13 +53,13 @@ 39 - 38 + 30 - + 39 - 38 + 30 @@ -88,7 +91,13 @@ 39 - 38 + 30 + + + + + 39 + 30 @@ -103,6 +112,22 @@ + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 4 + 20 + + + + @@ -114,7 +139,13 @@ 39 - 38 + 30 + + + + + 39 + 30 diff --git a/ground/gcs/src/plugins/logging/logginggadgetwidget.cpp b/ground/gcs/src/plugins/logging/logginggadgetwidget.cpp index 6a84b1179..42ae738a9 100644 --- a/ground/gcs/src/plugins/logging/logginggadgetwidget.cpp +++ b/ground/gcs/src/plugins/logging/logginggadgetwidget.cpp @@ -85,6 +85,7 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p) connect(logFile, &LogFile::setPlaybackPosition, this, &LoggingGadgetWidget::setPlaybackPosition); connect(logFile, &LogFile::replayStarted, this, &LoggingGadgetWidget::enableWidgets); connect(logFile, &LogFile::replayFinished, this, &LoggingGadgetWidget::disableWidgets); + connect(logFile, &LogFile::replayCompleted, this, &LoggingGadgetWidget::stopButtonAction); // Feedback from logfile to scope connect(logFile, &LogFile::replayFinished, scpPlugin, &ScopeGadgetFactory::stopPlotting); @@ -123,22 +124,15 @@ void LoggingGadgetWidget::pauseButtonAction() void LoggingGadgetWidget::stopButtonAction() { - ReplayState replayState = (loggingPlugin->getLogfile())->getReplayState(); - - if (replayState != STOPPED) { - emit pauseReplayAndResetPosition(); - } + emit pauseReplayAndResetPosition(); m_logging->playButton->setVisible(true); m_logging->pauseButton->setVisible(false); m_logging->stopButton->setEnabled(false); - // Block signals while setting the slider to the start position - m_logging->playbackPosition->blockSignals(true); - m_logging->playbackPosition->setValue(m_logging->playbackPosition->minimum()); - m_logging->playbackPosition->blockSignals(false); + setPlaybackPosition(0); - m_logging->statusLabel->setText(tr("Paused")); + m_logging->statusLabel->setText(tr("Stopped")); } void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state)