From 9b7b32b7535ed8cd9312997eb8c5e85d9450ffa2 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 8 Dec 2014 15:57:29 -0800 Subject: [PATCH 1/5] Check the log save settings before emitting save log signal --- src/comm/MAVLinkProtocol.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/comm/MAVLinkProtocol.cc b/src/comm/MAVLinkProtocol.cc index d6743ff..3b58308 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()); + } } } From 125f125aca8b9a76865da23ce3552957b098799a Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 8 Dec 2014 15:58:08 -0800 Subject: [PATCH 2/5] Disallow close if active connections Also moved log file settings save check to mavlink protocol --- src/ui/MainWindow.cc | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 8ed2ee9..b327d10 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -778,12 +778,31 @@ 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_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 +1753,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); } From cac402bba6db3171e2f1528ca1e43262c1ebb9cd Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 8 Dec 2014 15:58:25 -0800 Subject: [PATCH 3/5] Test disallow of close if active connections --- src/qgcunittest/MainWindowTest.cc | 27 +++++++++++++++++++++++++++ src/qgcunittest/MainWindowTest.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/qgcunittest/MainWindowTest.cc b/src/qgcunittest/MainWindowTest.cc index 0ddb908..408e95d 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 47c9c20..87eb827 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; From 1fb6b144a9cb326cc8bc5ee569c6a62a795fbda0 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 8 Dec 2014 15:58:59 -0800 Subject: [PATCH 4/5] MainWindow now disallows close if active connections So no need for connect window close test here --- src/qgcunittest/MavlinkLogTest.cc | 29 ----------------------------- src/qgcunittest/MavlinkLogTest.h | 1 - 2 files changed, 30 deletions(-) diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc index d23fbc0..18cab63 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 21cde40..b2a53a4 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); From fbe79303f420b749c445087089c6af0dbb12788b Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 8 Dec 2014 16:16:58 -0800 Subject: [PATCH 5/5] Fix unused variable warning --- src/ui/MainWindow.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index b327d10..d43ec07 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -796,6 +796,7 @@ void MainWindow::closeEvent(QCloseEvent *event) // Should not be any active connections foreach(LinkInterface* link, LinkManager::instance()->getLinks()) { + Q_UNUSED(link); Q_ASSERT(!link->isConnected()); }