From ac69865011a78eee213d9923f0dc0a3e91e77ad3 Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Tue, 4 Jun 2013 11:43:49 -0400 Subject: [PATCH] Change so MainWindow handles its own deletion, and deletion of other UI objects to allow for closing when the MainWindow is closed, regardless of if other windows are open. --- src/QGCCore.cc | 5 +++-- src/ui/MainWindow.cc | 39 ++++++++++++++++++++++++++++++++++----- src/ui/MainWindow.h | 5 +++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/QGCCore.cc b/src/QGCCore.cc index bee9f2026..d6d7e512a 100644 --- a/src/QGCCore.cc +++ b/src/QGCCore.cc @@ -203,7 +203,7 @@ QGCCore::QGCCore(int &argc, char* argv[]) : QApplication(argc, argv) QGCCore::~QGCCore() { //mainWindow->storeSettings(); - mainWindow->close(); + //mainWindow->close(); //mainWindow->deleteLater(); // Delete singletons // First systems @@ -211,7 +211,8 @@ QGCCore::~QGCCore() // then links delete LinkManager::instance(); // Finally the main window - delete MainWindow::instance(); + //delete MainWindow::instance(); + //The main window now autodeletes on close. } /** diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 3eb6a3336..abddfc644 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -106,6 +106,7 @@ MainWindow::MainWindow(QWidget *parent): autoReconnect(false), lowPowerMode(false) { + this->setAttribute(Qt::WA_DeleteOnClose); hide(); dockWidgetTitleBarEnabled = true; isAdvancedMode = false; @@ -323,6 +324,16 @@ MainWindow::~MainWindow() } } // Delete all UAS objects + + + if (debugConsole) + { + delete debugConsole; + } + for (int i=0;ideleteLater(); + } } void MainWindow::resizeEvent(QResizeEvent * event) @@ -523,10 +534,17 @@ void MainWindow::buildCommonWidgets() connect(tempAction,SIGNAL(triggered(bool)),this, SLOT(showTool(bool))); } { - QAction* tempAction = ui.menuTools->addAction(tr("Communication Console")); - menuToDockNameMap[tempAction] = "COMMUNICATION_DEBUG_CONSOLE_DOCKWIDGET"; - tempAction->setCheckable(true); - connect(tempAction,SIGNAL(triggered(bool)),this, SLOT(showTool(bool))); + if (!debugConsole) + { + debugConsole = new DebugConsole(); + debugConsole->setWindowTitle("Communications Console"); + debugConsole->show(); + QAction* tempAction = ui.menuTools->addAction(tr("Communication Console")); + //menuToDockNameMap[tempAction] = "COMMUNICATION_DEBUG_CONSOLE_DOCKWIDGET"; + tempAction->setCheckable(true); + connect(tempAction,SIGNAL(triggered(bool)),debugConsole,SLOT(setShown(bool))); + + } } createDockWidget(simView,new HSIDisplay(this),tr("Horizontal Situation"),"HORIZONTAL_SITUATION_INDICATOR_DOCKWIDGET",VIEW_SIMULATION,Qt::BottomDockWidgetArea); @@ -772,7 +790,9 @@ void MainWindow::loadDockWidget(QString name) } else if (name == "COMMUNICATION_DEBUG_CONSOLE_DOCKWIDGET") { - createDockWidget(centerStack->currentWidget(),new DebugConsole(this),tr("Communication Console"),"COMMUNICATION_DEBUG_CONSOLE_DOCKWIDGET",currentView,Qt::BottomDockWidgetArea); + //This is now a permanently detached window. + //centralWidgetToDockWidgetsMap[currentView][name] = console; + //createDockWidget(centerStack->currentWidget(),new DebugConsole(this),tr("Communication Console"),"COMMUNICATION_DEBUG_CONSOLE_DOCKWIDGET",currentView,Qt::BottomDockWidgetArea); } else if (name == "HORIZONTAL_SITUATION_INDICATOR_DOCKWIDGET") { @@ -1614,6 +1634,8 @@ void MainWindow::addLink(LinkInterface *link) if (!found) { // || udp CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this); + commsWidgetList.append(commWidget); + connect(commWidget,SIGNAL(destroyed(QObject*)),this,SLOT(commsWidgetDestroyed(QObject*))); QAction* action = commWidget->getAction(); ui.menuNetwork->addAction(action); @@ -1627,6 +1649,13 @@ void MainWindow::addLink(LinkInterface *link) } } } +void MainWindow::commsWidgetDestroyed(QObject *obj) +{ + if (commsWidgetList.contains(obj)) + { + commsWidgetList.removeOne(obj); + } +} void MainWindow::setActiveUAS(UASInterface* uas) { diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 4794f86ad..f9b322961 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -250,6 +250,8 @@ public slots: /** @brief Update the window name */ void configureWindowName(); + void commsWidgetDestroyed(QObject *obj); + signals: void initStatusChanged(const QString& message); #ifdef MOUSE_ENABLED_LINUX @@ -397,6 +399,8 @@ protected: QPointer toolBar; QPointer customStatusBar; + QPointer debugConsole; + QPointer mavlinkInspectorWidget; QPointer mavlinkDecoder; QPointer mavlinkSenderWidget; @@ -441,6 +445,7 @@ protected: QTimer windowNameUpdateTimer; private: + QList commsWidgetList; QMap customWidgetNameToFilenameMap; QMap menuToDockNameMap; QMap dockToTitleBarMap; -- 2.22.0