Commit ac698650 authored by Michael Carpenter's avatar Michael Carpenter

Change so MainWindow handles its own deletion, and deletion of other UI...

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.
parent 5f536d0d
......@@ -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.
}
/**
......
......@@ -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;i<commsWidgetList.size();i++)
{
commsWidgetList[i]->deleteLater();
}
}
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)
{
......
......@@ -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<QGCToolBar> toolBar;
QPointer<QGCStatusBar> customStatusBar;
QPointer<DebugConsole> debugConsole;
QPointer<QDockWidget> mavlinkInspectorWidget;
QPointer<MAVLinkDecoder> mavlinkDecoder;
QPointer<QDockWidget> mavlinkSenderWidget;
......@@ -441,6 +445,7 @@ protected:
QTimer windowNameUpdateTimer;
private:
QList<QObject*> commsWidgetList;
QMap<QString,QString> customWidgetNameToFilenameMap;
QMap<QAction*,QString > menuToDockNameMap;
QMap<QDockWidget*,QWidget*> dockToTitleBarMap;
......
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