diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index da85df9c87fb88868da0ca609592fe8a04ac1ab3..961775833d2f67634a22de040ff81d963df48ac7 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -329,53 +329,56 @@ void MainWindow::_showDockWidget(const QString& name, bool show) { // Create the inner widget if we need to if (!_mapName2DockWidget.contains(name)) { - _createInnerDockWidget(name); + if(!_createInnerDockWidget(name)) { + qWarning() << "Trying to load non existing widget:" << name; + return; + } } - Q_ASSERT(_mapName2DockWidget.contains(name)); QGCDockWidget* dockWidget = _mapName2DockWidget[name]; Q_ASSERT(dockWidget); - dockWidget->setVisible(show); - Q_ASSERT(_mapName2Action.contains(name)); _mapName2Action[name]->setChecked(show); } /// Creates the specified inner dock widget and adds to the QDockWidget -void MainWindow::_createInnerDockWidget(const QString& widgetName) +bool MainWindow::_createInnerDockWidget(const QString& widgetName) { QGCDockWidget* widget = NULL; QAction *action = _mapName2Action[widgetName]; - - switch(action->data().toInt()) { - case MAVLINK_INSPECTOR: - widget = new QGCMAVLinkInspector(widgetName, action, qgcApp()->toolbox()->mavlinkProtocol(),this); - break; - case CUSTOM_COMMAND: - widget = new CustomCommandWidget(widgetName, action, this); - break; - case ONBOARD_FILES: - widget = new QGCUASFileViewMulti(widgetName, action, this); - break; - case STATUS_DETAILS: - widget = new UASInfoWidget(widgetName, action, this); - break; - case HIL_CONFIG: - widget = new HILDockWidget(widgetName, action, this); - break; - case ANALYZE: - widget = new Linecharts(widgetName, action, mavlinkDecoder, this); - break; - case INFO_VIEW: - widget= new QGCTabbedInfoView(widgetName, action, this); - break; - } - - if(action->data().toInt() == INFO_VIEW) { - qobject_cast(widget)->addSource(mavlinkDecoder); + if(action) { + switch(action->data().toInt()) { + case MAVLINK_INSPECTOR: + widget = new QGCMAVLinkInspector(widgetName, action, qgcApp()->toolbox()->mavlinkProtocol(),this); + break; + case CUSTOM_COMMAND: + widget = new CustomCommandWidget(widgetName, action, this); + break; + case ONBOARD_FILES: + widget = new QGCUASFileViewMulti(widgetName, action, this); + break; + case STATUS_DETAILS: + widget = new UASInfoWidget(widgetName, action, this); + break; + case HIL_CONFIG: + widget = new HILDockWidget(widgetName, action, this); + break; + case ANALYZE: + widget = new Linecharts(widgetName, action, mavlinkDecoder, this); + break; + case INFO_VIEW: + widget= new QGCTabbedInfoView(widgetName, action, this); + break; + } + if(action->data().toInt() == INFO_VIEW) { + qobject_cast(widget)->addSource(mavlinkDecoder); + } + if(widget) { + _mapName2DockWidget[widgetName] = widget; + } } - _mapName2DockWidget[widgetName] = widget; + return widget != NULL; } void MainWindow::_hideAllDockWidgets(void) diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index a6e02b72b66131748d345b29ca1554f6e95ee7ff..ca0d4ef2fcd83416019703ac6f266a59d849a245 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -221,7 +221,7 @@ private: void _loadCurrentViewState(void); #ifndef __mobile__ - void _createInnerDockWidget(const QString& widgetName); + bool _createInnerDockWidget(const QString& widgetName); void _buildCommonWidgets(void); void _hideAllDockWidgets(void); void _showDockWidget(const QString &name, bool show);