Commit 10d9e376 authored by Don Gagne's avatar Don Gagne

Merge pull request #1088 from DonLakeFlyer/BugFixes

Bug fixes
parents c27191b0 fbe79303
......@@ -694,7 +694,11 @@ void MAVLinkProtocol::_startLogging(void)
void MAVLinkProtocol::_stopLogging(void)
{
if (_closeLogFile()) {
emit saveTempFlightDataLog(_tempLogFile.fileName());
if (qgcApp()->promptFlightDataSave()) {
emit saveTempFlightDataLog(_tempLogFile.fileName());
} else {
QFile::remove(_tempLogFile.fileName());
}
}
}
......
......@@ -28,6 +28,8 @@
#include "MainWindowTest.h"
#include "QGCToolBar.h"
#include "MockLink.h"
#include "QGCMessageBox.h"
UT_REGISTER_TEST(MainWindowTest)
......@@ -66,3 +68,28 @@ void MainWindowTest::_clickThrough_test(void)
}
}
void MainWindowTest::_connectWindowClose_test(void)
{
LinkManager* linkMgr = LinkManager::instance();
Q_CHECK_PTR(linkMgr);
MockLink* link = new MockLink();
Q_CHECK_PTR(link);
// FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work
_mainWindow->addLink(link);
linkMgr->connectLink(link);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through
// On MainWindow close we should get a message box telling the user to disconnect first
setExpectedMessageBox(QGCMessageBox::Ok);
_mainWindow->close();
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedMessageBox();
// We are going to disconnect the link which is going to pop a save file dialog
setExpectedFileDialog(getSaveFileName, QStringList());
linkMgr->disconnectLink(link);
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedFileDialog();
}
......@@ -44,6 +44,7 @@ private slots:
void cleanup(void);
void _clickThrough_test(void);
void _connectWindowClose_test(void);
private:
MainWindow* _mainWindow;
......
......@@ -170,32 +170,3 @@ void MavlinkLogTest::_connectLog_test(void)
QTest::qWait(1000); // Need to allow signals to move between threads to shutdown MainWindow
}
void MavlinkLogTest::_connectLogWindowClose_test(void)
{
MainWindow* mainWindow = MainWindow::_create(NULL, MainWindow::CUSTOM_MODE_PX4);
Q_CHECK_PTR(mainWindow);
LinkManager* linkMgr = LinkManager::instance();
Q_CHECK_PTR(linkMgr);
MockLink* link = new MockLink();
Q_CHECK_PTR(link);
// FIXME: LinkManager/MainWindow needs to be re-architected so that you don't have to addLink to MainWindow to get things to work
mainWindow->addLink(link);
linkMgr->connectLink(link);
QTest::qWait(5000); // Give enough time for UI to settle and heartbeats to go through
// On Disconnect: We should get a getSaveFileName dialog.
QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
QString logSaveFile(logSaveDir.filePath(_saveLogFilename));
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
// MainWindow deletes itself on close
mainWindow->close();
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedFileDialog();
// Make sure the file is there and delete it
QCOMPARE(logSaveDir.remove(_saveLogFilename), true);
}
......@@ -46,7 +46,6 @@ private slots:
void _bootLogDetectionSave_test(void);
void _bootLogDetectionZeroLength_test(void);
void _connectLog_test(void);
void _connectLogWindowClose_test(void);
private:
void _createTempLogFile(bool zeroLength);
......
......@@ -778,12 +778,32 @@ void MainWindow::showHILConfigurationWidget(UASInterface* uas)
void MainWindow::closeEvent(QCloseEvent *event)
{
// Disallow window close if there are active connections
bool foundConnections = false;
foreach(LinkInterface* link, LinkManager::instance()->getLinks()) {
if (link->isConnected()) {
foundConnections = true;
break;
}
}
if (foundConnections) {
QGCMessageBox::warning(tr("QGroundControl close"), tr("There are still active connections to vehicles. Please disconnect all connections before closing QGroundControl."));
event->ignore();
return;
}
// Should not be any active connections
foreach(LinkInterface* link, LinkManager::instance()->getLinks()) {
Q_UNUSED(link);
Q_ASSERT(!link->isConnected());
}
storeViewState();
storeSettings();
mavlink->storeSettings();
UASManager::instance()->storeSettings();
// FIXME: If connected links, should prompt before close
LinkManager::instance()->disconnectAll();
event->accept();
}
......@@ -1734,14 +1754,12 @@ bool MainWindow::dockWidgetTitleBarsEnabled() const
void MainWindow::_saveTempFlightDataLog(QString tempLogfile)
{
if (qgcApp()->promptFlightDataSave()) {
QString saveFilename = QGCFileDialog::getSaveFileName(this,
tr("Select file to save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(),
tr("Flight Data Log (*.mavlink)"));
if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename);
}
QString saveFilename = QGCFileDialog::getSaveFileName(this,
tr("Select file to save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(),
tr("Flight Data Log (*.mavlink)"));
if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename);
}
QFile::remove(tempLogfile);
}
......
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