Browse Source

Added image logging functionality

QGC4.4
Lorenz Meier 13 years ago
parent
commit
0607c32c16
  1. 50
      src/ui/HUD.cc
  2. 5
      src/ui/HUD.h

50
src/ui/HUD.cc

@ -123,7 +123,8 @@ HUD::HUD(int width, int height, QWidget* parent)
videoEnabled(false), videoEnabled(false),
xImageFactor(1.0), xImageFactor(1.0),
yImageFactor(1.0), yImageFactor(1.0),
imageRequested(false) imageRequested(false),
imageLoggingEnabled(false)
{ {
// Set auto fill to false // Set auto fill to false
setAutoFillBackground(false); setAutoFillBackground(false);
@ -224,7 +225,7 @@ void HUD::contextMenuEvent (QContextMenuEvent* event)
//menu.addAction(selectHUDColorAction); //menu.addAction(selectHUDColorAction);
menu.addAction(enableVideoAction); menu.addAction(enableVideoAction);
menu.addAction(selectOfflineDirectoryAction); menu.addAction(selectOfflineDirectoryAction);
//menu.addAction(selectVideoChannelAction); menu.addAction(selectSaveDirectoryAction);
menu.exec(event->globalPos()); menu.exec(event->globalPos());
} }
@ -242,9 +243,14 @@ void HUD::createActions()
enableVideoAction->setChecked(videoEnabled); enableVideoAction->setChecked(videoEnabled);
connect(enableVideoAction, SIGNAL(triggered(bool)), this, SLOT(enableVideo(bool))); connect(enableVideoAction, SIGNAL(triggered(bool)), this, SLOT(enableVideo(bool)));
selectOfflineDirectoryAction = new QAction(tr("Select image log"), this); selectOfflineDirectoryAction = new QAction(tr("Load image log"), this);
selectOfflineDirectoryAction->setStatusTip(tr("Load previously logged images into simulation / replay")); selectOfflineDirectoryAction->setStatusTip(tr("Load previously logged images into simulation / replay"));
connect(selectOfflineDirectoryAction, SIGNAL(triggered()), this, SLOT(selectOfflineDirectory())); connect(selectOfflineDirectoryAction, SIGNAL(triggered()), this, SLOT(selectOfflineDirectory()));
selectSaveDirectoryAction = new QAction(tr("Save images to directory"), this);
selectSaveDirectoryAction->setStatusTip(tr("Save images from image stream to a directory"));
selectSaveDirectoryAction->setCheckable(true);
connect(selectSaveDirectoryAction, SIGNAL(triggered(bool)), this, SLOT(saveImages(bool)));
} }
/** /**
@ -1484,5 +1490,43 @@ void HUD::copyImage()
{ {
this->glImage = QGLWidget::convertToGLFormat(u->getImage()); this->glImage = QGLWidget::convertToGLFormat(u->getImage());
} }
// Save to directory if logging is enabled
if (imageLoggingEnabled)
{
u->getImage().save(QString("%1/%2.png").arg(imageLogDirectory).arg(imageLogCounter));
imageLogCounter++;
}
} }
} }
void HUD::saveImages(bool save)
{
if (save)
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::DirectoryOnly);
QString imageLogDirectory = QFileDialog::getExistingDirectory(this, tr("Select image log directory"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
qDebug() << "Logging to:" << imageLogDirectory;
if (imageLogDirectory != "")
{
imageLogCounter = 0;
imageLoggingEnabled = true;
qDebug() << "Logging on";
}
else
{
imageLoggingEnabled = false;
selectSaveDirectoryAction->setChecked(false);
}
}
else
{
imageLoggingEnabled = false;
selectSaveDirectoryAction->setChecked(false);
}
}

5
src/ui/HUD.h

@ -86,6 +86,7 @@ public slots:
void finishImage(); void finishImage();
void saveImage(); void saveImage();
void saveImage(QString fileName); void saveImage(QString fileName);
void saveImages(bool save);
/** @brief Select directory where to load the offline files from */ /** @brief Select directory where to load the offline files from */
void selectOfflineDirectory(); void selectOfflineDirectory();
/** @brief Enable the HUD instruments */ /** @brief Enable the HUD instruments */
@ -220,14 +221,18 @@ protected:
bool hudInstrumentsEnabled; bool hudInstrumentsEnabled;
bool videoEnabled; bool videoEnabled;
bool dataStreamEnabled; bool dataStreamEnabled;
bool imageLoggingEnabled;
float xImageFactor; float xImageFactor;
float yImageFactor; float yImageFactor;
QAction* enableHUDAction; QAction* enableHUDAction;
QAction* enableVideoAction; QAction* enableVideoAction;
QAction* selectOfflineDirectoryAction; QAction* selectOfflineDirectoryAction;
QAction* selectVideoChannelAction; QAction* selectVideoChannelAction;
QAction* selectSaveDirectoryAction;
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
bool imageRequested; bool imageRequested;
QString imageLogDirectory;
unsigned int imageLogCounter;
}; };
#endif // HUD_H #endif // HUD_H

Loading…
Cancel
Save