diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index d6743ff71ba977f73a8adfadf67606389d60b513..3b583080c7f7c7f7e1f382d42dcd77ff7f36a159 100644 --- a/src/comm/MAVLinkProtocol.cc +++ b/src/comm/MAVLinkProtocol.cc @@ -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()); + } } } diff --git a/src/qgcunittest/MainWindowTest.cc b/src/qgcunittest/MainWindowTest.cc index 0ddb90868df81e396f8204c8723dfc0fbe89606d..408e95d870e695ec0dd530dc2b53161b4536bdb5 100644 --- a/src/qgcunittest/MainWindowTest.cc +++ b/src/qgcunittest/MainWindowTest.cc @@ -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(); +} diff --git a/src/qgcunittest/MainWindowTest.h b/src/qgcunittest/MainWindowTest.h index 47c9c20d6abdc4f01c2bd070bb47d636be77c395..87eb8270eafde5d5b2e59799ca00af8b23b11dac 100644 --- a/src/qgcunittest/MainWindowTest.h +++ b/src/qgcunittest/MainWindowTest.h @@ -44,6 +44,7 @@ private slots: void cleanup(void); void _clickThrough_test(void); + void _connectWindowClose_test(void); private: MainWindow* _mainWindow; diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc index d23fbc0b9dc7e0ad8f512a4d97e9dc854cf46fd2..18cab63132ed3eb3feb185f979edfa853ab8f0d8 100644 --- a/src/qgcunittest/MavlinkLogTest.cc +++ b/src/qgcunittest/MavlinkLogTest.cc @@ -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); -} diff --git a/src/qgcunittest/MavlinkLogTest.h b/src/qgcunittest/MavlinkLogTest.h index 21cde409faf864484e9c65989861196f73984e27..b2a53a416404765c9ffef1de6afced2d6f3accf4 100644 --- a/src/qgcunittest/MavlinkLogTest.h +++ b/src/qgcunittest/MavlinkLogTest.h @@ -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); diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 8ed2ee9712ab650fb8a972fa6a0a1bbcfe7f4d5b..d43ec0750043b71ced897500f4b541366c36c5aa 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -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); }