Commit e3134f6a authored by Don Gagne's avatar Don Gagne

Change window close sequence to prompt user from Qml side

parent 4105a169
...@@ -425,24 +425,20 @@ void MainWindow::showStatusBarCallback(bool checked) ...@@ -425,24 +425,20 @@ void MainWindow::showStatusBarCallback(bool checked)
checked ? statusBar()->show() : statusBar()->hide(); checked ? statusBar()->show() : statusBar()->hide();
} }
void MainWindow::acceptWindowClose(void)
{
qgcApp()->toolbox()->linkManager()->shutdown();
// The above shutdown causes a flurry of activity as the vehicle components are removed. This in turn
// causes the Windows Version of Qt to crash if you allow the close event to be accepted. In order to prevent
// the crash, we ignore the close event and setup a delayed timer to close the window after things settle down.
QTimer::singleShot(1500, this, &MainWindow::_closeWindow);
}
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
// Disallow window close if there are active connections // Disallow window close if there are active connections
if (qgcApp()->toolbox()->multiVehicleManager()->vehicles()->count()) { if (qgcApp()->toolbox()->multiVehicleManager()->vehicles()->count()) {
QGCMessageBox::StandardButton button = emit showWindowCloseMessage();
QGCMessageBox::warning(
tr("QGroundControl close"),
tr("There are still active connections to vehicles. Do you want to disconnect these before closing?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
if (button == QMessageBox::Yes) {
qgcApp()->toolbox()->linkManager()->shutdown();
// The above disconnect causes a flurry of activity as the vehicle components are removed. This in turn
// causes the Windows Version of Qt to crash if you allow the close event to be accepted. In order to prevent
// the crash, we ignore the close event and setup a delayed timer to close the window after things settle down.
QTimer::singleShot(1500, this, &MainWindow::_closeWindow);
}
event->ignore(); event->ignore();
return; return;
} }
......
...@@ -91,6 +91,9 @@ public: ...@@ -91,6 +91,9 @@ public:
/// @brief Saves the last used connection /// @brief Saves the last used connection
void saveLastUsedConnection(const QString connection); void saveLastUsedConnection(const QString connection);
// Called from MainWindow.qml when the user accepts the window close dialog
Q_INVOKABLE void acceptWindowClose(void);
public slots: public slots:
/** @brief Show the application settings */ /** @brief Show the application settings */
void showSettings(); void showSettings();
...@@ -132,6 +135,7 @@ protected slots: ...@@ -132,6 +135,7 @@ protected slots:
* this incoherent. * this incoherent.
*/ */
void handleActiveViewActionState(bool triggered); void handleActiveViewActionState(bool triggered);
signals: signals:
// Signals the Qml to show the specified view // Signals the Qml to show the specified view
void showFlyView(void); void showFlyView(void);
...@@ -139,6 +143,7 @@ signals: ...@@ -139,6 +143,7 @@ signals:
void showSetupView(void); void showSetupView(void);
void showToolbarMessage(const QString& message); void showToolbarMessage(const QString& message);
void showWindowCloseMessage(void);
// These are used for unit testing // These are used for unit testing
void showSetupFirmware(void); void showSetupFirmware(void);
......
...@@ -23,6 +23,7 @@ along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,6 +23,7 @@ along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
import QtQuick 2.5 import QtQuick 2.5
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import QtPositioning 5.2 import QtPositioning 5.2
import QGroundControl 1.0 import QGroundControl 1.0
...@@ -95,6 +96,8 @@ Item { ...@@ -95,6 +96,8 @@ Item {
onShowToolbarMessage: toolBar.showToolbarMessage(message) onShowToolbarMessage: toolBar.showToolbarMessage(message)
onShowWindowCloseMessage: windowCloseDialog.open()
// The following are use for unit testing only // The following are use for unit testing only
onShowSetupFirmware: setupViewLoader.item.showFirmwarePanel() onShowSetupFirmware: setupViewLoader.item.showFirmwarePanel()
...@@ -173,13 +176,24 @@ Item { ...@@ -173,13 +176,24 @@ Item {
function showPopUp(dropItem, centerX) { function showPopUp(dropItem, centerX) {
if(currentPopUp) { if(currentPopUp) {
currentPopUp.close() currentPopUp.close()
} }
indicatorDropdown.centerX = centerX indicatorDropdown.centerX = centerX
indicatorDropdown.sourceComponent = dropItem indicatorDropdown.sourceComponent = dropItem
indicatorDropdown.visible = true indicatorDropdown.visible = true
currentPopUp = indicatorDropdown currentPopUp = indicatorDropdown
} }
MessageDialog {
id: windowCloseDialog
title: "QGroundControl close"
text: "There are still active connections to vehicles. Do you want to disconnect these before closing?"
standardButtons: StandardButton.Yes | StandardButton.Cancel
modality: Qt.ApplicationModal
visible: false
onYes: controller.acceptWindowClose()
}
//-- Left Settings Menu //-- Left Settings Menu
Loader { Loader {
id: leftPanel id: leftPanel
......
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