1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

LP-597 Don't disable playback when the end of the logfile has been reached.

- instead, do the same as the user pressing the stop button.
This commit is contained in:
Jan NIJS 2018-05-04 22:20:54 +02:00
parent 684849f33c
commit ba0869c2d2
4 changed files with 73 additions and 21 deletions

View File

@ -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()
*

View File

@ -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<qint64> m_timeStampPositions;
bool buildIndex();
bool resetReplay();
};
#endif // LOGFILE_H

View File

@ -32,7 +32,10 @@
<number>3</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,2,0,0,2,0,0">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,2,0,0,2,0,0">
<property name="spacing">
<number>4</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
@ -50,13 +53,13 @@
<property name="minimumSize">
<size>
<width>39</width>
<height>38</height>
<height>30</height>
</size>
</property>
<property name="baseSize">
<property name="maximumSize">
<size>
<width>39</width>
<height>38</height>
<height>30</height>
</size>
</property>
<property name="focusPolicy">
@ -88,7 +91,13 @@
<property name="minimumSize">
<size>
<width>39</width>
<height>38</height>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>39</width>
<height>30</height>
</size>
</property>
<property name="icon">
@ -103,6 +112,22 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>4</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="stopButton">
<property name="sizePolicy">
@ -114,7 +139,13 @@
<property name="minimumSize">
<size>
<width>39</width>
<height>38</height>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>39</width>
<height>30</height>
</size>
</property>
<property name="icon">

View File

@ -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)