Commit e1bbb9f4 authored by pixhawk's avatar pixhawk

Improved log replaying substantially

parent 1c4982e5
......@@ -165,11 +165,18 @@ bool QGCMAVLinkLogPlayer::reset(int packetIndex)
}
}
void QGCMAVLinkLogPlayer::selectLogFile()
bool QGCMAVLinkLogPlayer::selectLogFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Specify MAVLink log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("MAVLink or Binary Logfile (*.mavlink *.bin *.log)"));
QString fileName = QFileDialog::getOpenFileName(this, tr("Specify MAVLink log file name to replay"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("MAVLink or Binary Logfile (*.mavlink *.bin *.log)"));
loadLogFile(fileName);
if (fileName == "")
{
return false;
}
else
{
return loadLogFile(fileName);
}
}
/**
......@@ -207,7 +214,7 @@ void QGCMAVLinkLogPlayer::setAccelerationFactorInt(int factor)
ui->speedLabel->setText(tr("Speed: %1X").arg(accelerationFactor, 5, 'f', 2, '0'));
}
void QGCMAVLinkLogPlayer::loadLogFile(const QString& file)
bool QGCMAVLinkLogPlayer::loadLogFile(const QString& file)
{
// Check if logging is still enabled
if (mavlink->loggingEnabled())
......@@ -228,6 +235,7 @@ void QGCMAVLinkLogPlayer::loadLogFile(const QString& file)
{
MainWindow::instance()->showCriticalMessage(tr("The selected logfile is unreadable"), tr("Please make sure that the file %1 is readable or select a different file").arg(file));
logFile.setFileName("");
return false;
}
else
{
......@@ -294,6 +302,7 @@ void QGCMAVLinkLogPlayer::loadLogFile(const QString& file)
QString timelabel = tr("%1h:%2m:%3s").arg(hours, 2).arg(minutes, 2).arg(seconds, 2);
ui->logStatsLabel->setText(tr("%2 MB, %4 at %5 KB/s").arg(logFileInfo.size()/1000000.0f, 0, 'f', 2).arg(timelabel).arg(binaryBaudRate/10.0f/1024.0f, 0, 'f', 2));
}
return true;
}
}
......
......@@ -27,6 +27,15 @@ class QGCMAVLinkLogPlayer : public QWidget
public:
explicit QGCMAVLinkLogPlayer(MAVLinkProtocol* mavlink, QWidget *parent = 0);
~QGCMAVLinkLogPlayer();
bool isPlayingLogFile()
{
return isPlaying;
}
bool isLogFileSelected()
{
return logFile.isOpen();
}
public slots:
/** @brief Toggle between play and pause */
......@@ -40,9 +49,9 @@ public slots:
/** @brief Reset the logfile */
bool reset(int packetIndex=0);
/** @brief Select logfile */
void selectLogFile();
bool selectLogFile();
/** @brief Load log file */
void loadLogFile(const QString& file);
bool loadLogFile(const QString& file);
/** @brief Jump to a position in the logfile */
void jumpToSliderVal(int slidervalue);
/** @brief The logging mainloop */
......
......@@ -31,7 +31,8 @@ QGCToolBar::QGCToolBar(QWidget *parent) :
QToolBar(parent),
toggleLoggingAction(NULL),
logReplayAction(NULL),
mav(NULL)
mav(NULL),
player(NULL)
{
setObjectName("QGC_TOOLBAR");
......@@ -51,11 +52,11 @@ QGCToolBar::QGCToolBar(QWidget *parent) :
symbolButton = new QToolButton(this);
toolBarNameLabel = new QLabel("------", this);
toolBarModeLabel = new QLabel("------", this);
toolBarModeLabel->setStyleSheet("QLabel { margin: 0px 4px; font: 14px; color: #3C7B9E; }");
toolBarModeLabel->setStyleSheet("QLabel { margin: 0px 2px; font: 14px; color: #3C7B9E; }");
toolBarStateLabel = new QLabel("------", this);
toolBarStateLabel->setStyleSheet("QLabel { margin: 0px 4px; font: 14px; color: #FEC654; }");
toolBarStateLabel->setStyleSheet("QLabel { margin: 0px 2px; font: 14px; color: #FEC654; }");
toolBarWpLabel = new QLabel("WP--", this);
toolBarWpLabel->setStyleSheet("QLabel { margin: 0px 4px; font: 18px; color: #3C7B9E; }");
toolBarWpLabel->setStyleSheet("QLabel { margin: 0px 2px; font: 18px; color: #3C7B9E; }");
toolBarDistLabel = new QLabel("--- ---- m", this);
toolBarMessageLabel = new QLabel("No system messages.", this);
toolBarMessageLabel->setStyleSheet("QLabel { margin: 0px 4px; font: 12px; font-style: italic; color: #3C7B9E; }");
......@@ -63,9 +64,10 @@ QGCToolBar::QGCToolBar(QWidget *parent) :
toolBarBatteryBar->setStyleSheet("QProgressBar:horizontal { margin: 0px 4px 0px 0px; border: 1px solid #4A4A4F; border-radius: 4px; text-align: center; padding: 2px; color: #111111; background-color: #111118; height: 10px; } QProgressBar:horizontal QLabel { font-size: 9px; color: #111111; } QProgressBar::chunk { background-color: green; }");
toolBarBatteryBar->setMinimum(0);
toolBarBatteryBar->setMaximum(100);
toolBarBatteryBar->setMinimumWidth(200);
toolBarBatteryBar->setMaximumWidth(200);
toolBarBatteryVoltageLabel = new QLabel("xx.x V");
toolBarBatteryVoltageLabel->setStyleSheet(QString("QLabel { margin: 0px 2px 0px 4px; font: 14px; color: %1; }").arg(QColor(Qt::green).name()));
toolBarBatteryVoltageLabel->setStyleSheet(QString("QLabel { margin: 0px 0px 0px 4px; font: 14px; color: %1; }").arg(QColor(Qt::green).name()));
//symbolButton->setIcon(":");
symbolButton->setStyleSheet("QWidget { background-color: #050508; color: #DDDDDF; background-clip: border; } QToolButton { font-weight: bold; font-size: 12px; border: 0px solid #999999; border-radius: 5px; min-width:22px; max-width: 22px; min-height: 22px; max-height: 22px; padding: 0px; margin: 0px 0px 0px 20px; background-color: none; }");
addWidget(symbolButton);
......@@ -87,17 +89,42 @@ QGCToolBar::QGCToolBar(QWidget *parent) :
void QGCToolBar::setLogPlayer(QGCMAVLinkLogPlayer* player)
{
connect(toggleLoggingAction, SIGNAL(triggered(bool)), player, SLOT(playPause(bool)));
this->player = player;
connect(toggleLoggingAction, SIGNAL(triggered(bool)), this, SLOT(playLogFile(bool)));
connect(logReplayAction, SIGNAL(triggered(bool)), this, SLOT(logging(bool)));
}
void QGCToolBar::playLogFile(bool enabled)
{
// Check if player exists
if (player)
{
// If a logfile is already replayed, stop the replay
// and select a new logfile
if (player->isPlayingLogFile())
{
player->playPause(false);
if (enabled)
{
if (!player->selectLogFile()) return;
}
}
// If no replaying happens already, start it
else
{
if (!player->selectLogFile()) return;
}
player->playPause(enabled);
}
}
void QGCToolBar::logging(bool enabled)
{
// Stop logging in any case
MainWindow::instance()->getMAVLink()->enableLogging(false);
if (enabled)
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Specify MAVLink log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("MAVLink Logfile (*.mavlink *.log *.bin);;"));
QString fileName = QFileDialog::getSaveFileName(this, tr("Specify MAVLink log file to save to"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("MAVLink Logfile (*.mavlink *.log *.bin);;"));
if (!fileName.endsWith(".mavlink"))
{
......@@ -167,8 +194,6 @@ void QGCToolBar::setActiveUAS(UASInterface* active)
toolBarNameLabel->setText(mav->getUASName());
toolBarNameLabel->setStyleSheet(QString("QLabel { font: bold 16px; color: %1; }").arg(mav->getColor().name()));
symbolButton->setStyleSheet(QString("QWidget { background-color: %1; color: #DDDDDF; background-clip: border; } QToolButton { font-weight: bold; font-size: 12px; border: 0px solid #999999; border-radius: 5px; min-width:22px; max-width: 22px; min-height: 22px; max-height: 22px; padding: 0px; margin: 0px 4px 0px 20px; background-color: none; }").arg(mav->getColor().name()));
// toolBarModeLabel->setStyleSheet("QLabel { font: 16px; color: #3C7B9E; }");
// toolBarStateLabel->setStyleSheet("QLabel { font: 16px; color: #FEC654; }");
toolBarModeLabel->setText(mav->getShortMode());
toolBarStateLabel->setText(mav->getShortState());
setSystemType(mav, mav->getSystemType());
......
......@@ -56,6 +56,8 @@ public slots:
void receiveTextMessage(int uasid, int componentid, int severity, QString text);
/** @brief Start / stop logging */
void logging(bool enabled);
/** @brief Start playing logfile */
void playLogFile(bool enabled);
/** @brief Set log playing component */
void setLogPlayer(QGCMAVLinkLogPlayer* player);
/** @brief Update battery charge state */
......@@ -80,6 +82,7 @@ protected:
QLabel* toolBarMessageLabel;
QProgressBar* toolBarBatteryBar;
QLabel* toolBarBatteryVoltageLabel;
QGCMAVLinkLogPlayer* player;
};
#endif // QGCTOOLBAR_H
......@@ -88,13 +88,15 @@ void UASListWidget::changeEvent(QEvent *e)
void UASListWidget::addUAS(UASInterface* uas)
{
if (uasViews.isEmpty()) {
if (uasViews.isEmpty())
{
listLayout->removeWidget(uWidget);
delete uWidget;
uWidget = NULL;
}
if (!uasViews.contains(uas)) {
if (!uasViews.contains(uas))
{
uasViews.insert(uas, new UASView(uas, this));
listLayout->addWidget(uasViews.value(uas));
//connect(uas, SIGNAL(destroyed(QObject*)), this, SLOT(removeUAS(QObject*)));
......@@ -111,6 +113,7 @@ void UASListWidget::activeUAS(UASInterface* uas)
void UASListWidget::removeUAS(UASInterface* uas)
{
uasViews.remove(uas);
listLayout->removeWidget(uasViews.value(uas));
uasViews.value(uas)->deleteLater();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment