From 55966675da70d6beb8f63afc7efaaf88eca33944 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 11 Oct 2015 16:24:20 -0700 Subject: [PATCH] Make HIL Dock Widget a normal widget --- QGCApplication.pro | 5 ++ src/ui/HILDockWidget.cc | 41 ++++++++++ src/ui/HILDockWidget.h | 42 ++++++++++ src/ui/MainWindow.cc | 128 ++++--------------------------- src/ui/MainWindow.h | 12 +-- src/ui/MainWindow.ui | 24 +----- src/ui/MultiVehicleDockWidget.cc | 85 ++++++++++++++++++++ src/ui/MultiVehicleDockWidget.h | 67 ++++++++++++++++ src/ui/MultiVehicleDockWidget.ui | 27 +++++++ src/ui/QGCHilConfiguration.cc | 51 ++++++++---- src/ui/QGCHilConfiguration.h | 33 ++++++-- 11 files changed, 351 insertions(+), 164 deletions(-) create mode 100644 src/ui/HILDockWidget.cc create mode 100644 src/ui/HILDockWidget.h create mode 100644 src/ui/MultiVehicleDockWidget.cc create mode 100644 src/ui/MultiVehicleDockWidget.h create mode 100644 src/ui/MultiVehicleDockWidget.ui diff --git a/QGCApplication.pro b/QGCApplication.pro index 476e679b3..c9d94598f 100644 --- a/QGCApplication.pro +++ b/QGCApplication.pro @@ -168,6 +168,7 @@ FORMS += \ src/ui/MainWindow.ui \ src/ui/mavlink/QGCMAVLinkMessageSender.ui \ src/ui/MAVLinkSettingsWidget.ui \ + src/ui/MultiVehicleDockWidget.ui \ src/ui/QGCCommConfiguration.ui \ src/ui/QGCDataPlot2D.ui \ src/ui/QGCLinkConfiguration.ui \ @@ -265,6 +266,7 @@ HEADERS += \ src/ui/mavlink/QGCMAVLinkMessageSender.h \ src/ui/MAVLinkDecoder.h \ src/ui/MAVLinkSettingsWidget.h \ + src/ui/MultiVehicleDockWidget.h \ src/ui/QGCCommConfiguration.h \ src/ui/QGCDataPlot2D.h \ src/ui/QGCLinkConfiguration.h \ @@ -308,6 +310,7 @@ HEADERS += \ src/comm/QGCJSBSimLink.h \ src/comm/QGCXPlaneLink.h \ src/ui/CameraView.h \ + src/ui/HILDockWidget.h \ src/ui/QGCHilConfiguration.h \ src/ui/QGCHilFlightGearConfiguration.h \ src/ui/QGCHilJSBSimConfiguration.h \ @@ -370,6 +373,7 @@ SOURCES += \ src/ui/mavlink/QGCMAVLinkMessageSender.cc \ src/ui/MAVLinkDecoder.cc \ src/ui/MAVLinkSettingsWidget.cc \ + src/ui/MultiVehicleDockWidget.cc \ src/ui/QGCCommConfiguration.cc \ src/ui/QGCDataPlot2D.cc \ src/ui/QGCLinkConfiguration.cc \ @@ -412,6 +416,7 @@ SOURCES += \ src/comm/QGCJSBSimLink.cc \ src/comm/QGCXPlaneLink.cc \ src/ui/CameraView.cc \ + src/ui/HILDockWidget.cc \ src/ui/QGCHilConfiguration.cc \ src/ui/QGCHilFlightGearConfiguration.cc \ src/ui/QGCHilJSBSimConfiguration.cc \ diff --git a/src/ui/HILDockWidget.cc b/src/ui/HILDockWidget.cc new file mode 100644 index 000000000..e10ee208e --- /dev/null +++ b/src/ui/HILDockWidget.cc @@ -0,0 +1,41 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include "HILDockWidget.h" +#include "QGCHilConfiguration.h" + +HILDockWidget::HILDockWidget(QWidget *parent) + : MultiVehicleDockWidget(parent) +{ + init(); +} + +HILDockWidget::~HILDockWidget() +{ + +} + +QWidget* HILDockWidget::_newVehicleWidget(Vehicle* vehicle, QWidget* parent) +{ + return new QGCHilConfiguration(vehicle, parent); +} diff --git a/src/ui/HILDockWidget.h b/src/ui/HILDockWidget.h new file mode 100644 index 000000000..d8e8073ac --- /dev/null +++ b/src/ui/HILDockWidget.h @@ -0,0 +1,42 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#ifndef HILDockWidget_H +#define HILDockWidget_H + +#include "MultiVehicleDockWidget.h" + +class HILDockWidget : public MultiVehicleDockWidget +{ + Q_OBJECT + +public: + explicit HILDockWidget(QWidget *parent = 0); + ~HILDockWidget(); + +protected: + // Override from MultiVehicleDockWidget + virtual QWidget* _newVehicleWidget(Vehicle* vehicle, QWidget* parent); +}; + +#endif diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 255c9d45f..d06efdee4 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -33,20 +33,13 @@ This file is part of the QGROUNDCONTROL project #include #include #include -#ifndef __mobile__ -#include -#include -#include -#endif + #include #include #include #include #include "QGC.h" -#ifndef __ios__ -#include "SerialLink.h" -#endif #include "MAVLinkProtocol.h" #include "MainWindow.h" #include "GAudioOutput.h" @@ -71,6 +64,15 @@ This file is part of the QGROUNDCONTROL project #include "CustomCommandWidget.h" #include "HomePositionManager.h" #include "MissionEditor.h" +#include "LogCompressor.h" + +#ifndef __mobile__ +#include "HILDockWidget.h" +#endif + +#ifndef __ios__ +#include "SerialLink.h" +#endif #ifdef UNITTEST_BUILD #include "QmlControls/QmlTestWidget.h" @@ -80,7 +82,6 @@ This file is part of the QGROUNDCONTROL project #include "Q3DWidgetFactory.h" #endif -#include "LogCompressor.h" /// The key under which the Main Window settings are saved const char* MAIN_SETTINGS_GROUP = "QGC_MAINWINDOW"; @@ -92,6 +93,7 @@ const char* MainWindow::_uasStatusDetailsDockWidgetName = "UAS_STATUS_DETAILS_DO const char* MainWindow::_mapViewDockWidgetName = "MAP_VIEW_DOCKWIDGET"; const char* MainWindow::_pfdDockWidgetName = "PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET"; const char* MainWindow::_uasInfoViewDockWidgetName = "UAS_INFO_INFOVIEW_DOCKWIDGET"; +const char* MainWindow::_hilDockWidgetName = "HIL_DOCKWIDGET"; static MainWindow* _instance = NULL; ///< @brief MainWindow singleton @@ -163,7 +165,7 @@ MainWindow::MainWindow(QSplashScreen* splashScreen) #ifdef UNITTEST_BUILD QAction* qmlTestAction = new QAction("Test QML palette and controls", NULL); connect(qmlTestAction, &QAction::triggered, this, &MainWindow::_showQmlTestWidget); - _ui.menuTools->addAction(qmlTestAction); + _ui.menuWidgets->addAction(qmlTestAction); #endif // Load QML Toolbar @@ -267,14 +269,12 @@ MainWindow::MainWindow(QSplashScreen* splashScreen) _ui.actionPlan->setShortcut(QApplication::translate("MainWindow", "Meta+2", 0)); _ui.actionFlight->setShortcut(QApplication::translate("MainWindow", "Meta+3", 0)); _ui.actionAnalyze->setShortcut(QApplication::translate("MainWindow", "Meta+4", 0)); - _ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Meta+5", 0)); _ui.actionFullscreen->setShortcut(QApplication::translate("MainWindow", "Meta+Return", 0)); #else _ui.actionSetup->setShortcut(QApplication::translate("MainWindow", "Ctrl+1", 0)); _ui.actionPlan->setShortcut(QApplication::translate("MainWindow", "Ctrl+2", 0)); _ui.actionFlight->setShortcut(QApplication::translate("MainWindow", "Ctrl+3", 0)); _ui.actionAnalyze->setShortcut(QApplication::translate("MainWindow", "Ctrl+4", 0)); - _ui.actionSimulationView->setShortcut(QApplication::translate("MainWindow", "Ctrl+5", 0)); _ui.actionFullscreen->setShortcut(QApplication::translate("MainWindow", "Ctrl+Return", 0)); #endif @@ -341,7 +341,7 @@ void MainWindow::_createDockWidget(const QString& title, const QString& name, Qt action->setCheckable(true); action->setData(name); connect(action, &QAction::triggered, this, &MainWindow::_showDockWidgetAction); - _ui.menuTools->addAction(action); + _ui.menuWidgets->addAction(action); // Create widget QGCDockWidget* dockWidget = new QGCDockWidget(title, action, this); @@ -391,6 +391,7 @@ void MainWindow::_buildCommonWidgets(void) { _mapViewDockWidgetName, "Map view", Qt::RightDockWidgetArea }, { _pfdDockWidgetName, "Primary Flight Display", Qt::RightDockWidgetArea }, { _uasInfoViewDockWidgetName, "Info View", Qt::LeftDockWidgetArea }, + { _hilDockWidgetName, "HIL Config", Qt::LeftDockWidgetArea }, }; static const size_t cDockWidgetInfo = sizeof(rgDockWidgetInfo) / sizeof(rgDockWidgetInfo[0]); @@ -482,6 +483,8 @@ void MainWindow::_createInnerDockWidget(const QString& widgetName) widget = new UASInfoWidget(this); } else if (widgetName == _pfdDockWidgetName) { widget = new FlightDisplayWidget(this); + } else if (widgetName == _hilDockWidgetName) { + widget = new HILDockWidget(this); } else if (widgetName == _uasInfoViewDockWidgetName) { QGCTabbedInfoView* pInfoView = new QGCTabbedInfoView(this); pInfoView->addSource(mavlinkDecoder); @@ -498,48 +501,6 @@ void MainWindow::_createInnerDockWidget(const QString& widgetName) } } -#ifndef __mobile__ -void MainWindow::_showHILConfigurationWidgets(void) -{ - Vehicle* vehicle = MultiVehicleManager::instance()->activeVehicle(); - - if (!vehicle) { - return; - } - - UAS* mav = vehicle->uas(); - Q_ASSERT(mav); - - int uasId = mav->getUASID(); - - if (!_mapUasId2HilDockWidget.contains(uasId)) { - - // Create QDockWidget - QGCDockWidget* dockWidget = new QGCDockWidget(tr("HIL Config %1").arg(uasId), NULL, this); - Q_CHECK_PTR(dockWidget); - dockWidget->setObjectName(tr("HIL_CONFIG_%1").arg(uasId)); - dockWidget->setVisible (false); - - // Create inner widget and set it - QWidget* widget = new QGCHilConfiguration(mav, dockWidget); - - widget->setParent(dockWidget); - dockWidget->setWidget(widget); - - _mapUasId2HilDockWidget[uasId] = dockWidget; - - addDockWidget(Qt::LeftDockWidgetArea, dockWidget); - } - - if (_currentView == VIEW_SIMULATION) { - // HIL dock widgets only show up on simulation view - foreach (QDockWidget* dockWidget, _mapUasId2HilDockWidget) { - dockWidget->setVisible(true); - } - } -} -#endif - void MainWindow::fullScreenActionItemCallback(bool) { _ui.actionNormal->setChecked(false); @@ -650,7 +611,6 @@ void MainWindow::connectCommonActions() QActionGroup* perspectives = new QActionGroup(_ui.menuPerspectives); perspectives->addAction(_ui.actionAnalyze); perspectives->addAction(_ui.actionFlight); - perspectives->addAction(_ui.actionSimulationView); perspectives->addAction(_ui.actionPlan); perspectives->addAction(_ui.actionSetup); perspectives->setExclusive(true); @@ -666,11 +626,6 @@ void MainWindow::connectCommonActions() _ui.actionFlight->setChecked(true); _ui.actionFlight->activate(QAction::Trigger); } - if (_currentView == VIEW_SIMULATION) - { - _ui.actionSimulationView->setChecked(true); - _ui.actionSimulationView->activate(QAction::Trigger); - } if (_currentView == VIEW_MISSIONEDITOR) { _ui.actionPlan->setChecked(true); @@ -687,11 +642,9 @@ void MainWindow::connectCommonActions() // Connect internal actions connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &MainWindow::_vehicleAdded); - connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleRemoved, this, &MainWindow::_vehicleRemoved); // Views actions connect(_ui.actionFlight, SIGNAL(triggered()), this, SLOT(loadFlightView())); - connect(_ui.actionSimulationView, SIGNAL(triggered()), this, SLOT(loadSimulationView())); connect(_ui.actionAnalyze, SIGNAL(triggered()), this, SLOT(loadAnalyzeView())); connect(_ui.actionPlan, SIGNAL(triggered()), this, SLOT(loadPlanView())); @@ -763,11 +716,6 @@ void MainWindow::_vehicleAdded(Vehicle* vehicle) { connect(vehicle->uas(), SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), this, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64))); - // HIL -#ifndef __mobile__ - _showHILConfigurationWidgets(); -#endif - if (!linechartWidget) { linechartWidget = new Linecharts(this); @@ -781,22 +729,9 @@ void MainWindow::_vehicleAdded(Vehicle* vehicle) } } -void MainWindow::_vehicleRemoved(Vehicle* vehicle) -{ - int vehicleId = vehicle->id(); - - if (_mapUasId2HilDockWidget.contains(vehicleId)) { - _mapUasId2HilDockWidget[vehicleId]->deleteLater(); - _mapUasId2HilDockWidget.remove(vehicleId); - } -} - /// Stores the state of the toolbar, status bar and widgets associated with the current view void MainWindow::_storeCurrentViewState(void) { - // HIL dock widgets are dynamic and are not part of the saved state - _hideAllHilDockWidgets(); - #ifndef __mobile__ // Save list of visible widgets bool firstWidget = true; @@ -845,12 +780,6 @@ void MainWindow::_loadCurrentViewState(void) centerView = _missionEditorView; break; - case VIEW_SIMULATION: - _buildSimView(); - centerView = _simView; - defaultWidgets = "WAYPOINT_LIST_DOCKWIDGET,PARAMETER_INTERFACE_DOCKWIDGET,PRIMARY_FLIGHT_DISPLAY_DOCKWIDGET"; - break; - default: Q_ASSERT(false); break; @@ -893,30 +822,16 @@ void MainWindow::_loadCurrentViewState(void) restoreState(settings.value(_getWindowStateKey()).toByteArray()); } - // HIL dock widget are dynamic and don't take part in the saved window state, so this - // need to happen after we restore state -#ifndef __mobile__ - _showHILConfigurationWidgets(); -#endif - // There is a bug in Qt where a Canvas element inside a QQuickWidget does not // receive update requests. Here we emit a signal for them to get repainted. emit repaintCanvas(); } -void MainWindow::_hideAllHilDockWidgets(void) -{ - foreach(QDockWidget* dockWidget, _mapUasId2HilDockWidget) { - dockWidget->setVisible(false); - } -} - void MainWindow::_hideAllDockWidgets(void) { foreach(QDockWidget* dockWidget, _mapName2DockWidget) { dockWidget->setVisible(false); } - _hideAllHilDockWidgets(); } void MainWindow::_showDockWidgetAction(bool show) @@ -971,17 +886,6 @@ void MainWindow::loadFlightView() } } -void MainWindow::loadSimulationView() -{ - if (_currentView != VIEW_SIMULATION) - { - _storeCurrentViewState(); - _currentView = VIEW_SIMULATION; - _ui.actionSimulationView->setChecked(true); - _loadCurrentViewState(); - } -} - /// @brief Hides the spash screen if it is currently being shown void MainWindow::hideSplashScreen(void) { diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index b6151b626..fb83aed8b 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -124,7 +124,6 @@ public slots: void loadSetupView(); void loadFlightView(); - void loadSimulationView(); void loadAnalyzeView(); void loadPlanView(); @@ -193,7 +192,7 @@ protected: VIEW_ANALYZE, // Engineering/Analyze view mode. Used for analyzing data and modifying onboard parameters VIEW_UNUSED3, // Unused (don't remove, or it will screw up saved settigns indices) VIEW_FLIGHT, // Flight/Fly/Operate view mode. Used for 1st-person observation of the vehicle. - VIEW_SIMULATION, // HIL Simulation view. Useful overview of the entire system when doing hardware-in-the-loop simulations. + VIEW_UNUSED4, // Unused (don't remove, or it will screw up saved settigns indices) VIEW_SETUP, // Setup view. Used for initializing the system for operation. VIEW_UNUSED1, // Unused (don't remove, or it will screw up saved settigns indices) VIEW_UNUSED2, // Unused (don't remove, or it will screw up saved settigns indices) @@ -261,7 +260,6 @@ private slots: private slots: void _vehicleAdded(Vehicle* vehicle); - void _vehicleRemoved(Vehicle* vehicle); private: /// Constructor is private since all creation should be through MainWindow::_create @@ -279,8 +277,6 @@ private: QPointer _missionEditorView; // Dock widget names - static const char* _uasControlDockWidgetName; - static const char* _uasListDockWidgetName; static const char* _mavlinkDockWidgetName; static const char* _customCommandWidgetName; static const char* _filesDockWidgetName; @@ -288,9 +284,9 @@ private: static const char* _mapViewDockWidgetName; static const char* _pfdDockWidgetName; static const char* _uasInfoViewDockWidgetName; + static const char* _hilDockWidgetName; QMap _mapName2DockWidget; - QMap _mapUasId2HilDockWidget; QMap _mapDockWidget2Action; void _buildPlanView(void); @@ -307,12 +303,8 @@ private: void _createDockWidget(const QString& title, const QString& name, Qt::DockWidgetArea area, QWidget* innerWidget); void _createInnerDockWidget(const QString& widgetName); void _buildCommonWidgets(void); - void _hideAllHilDockWidgets(void); void _hideAllDockWidgets(void); void _showDockWidget(const QString &name, bool show); -#ifndef __mobile__ - void _showHILConfigurationWidgets(void); -#endif bool _autoReconnect; bool _lowPowerMode; ///< If enabled, QGC reduces the update rates of all widgets diff --git a/src/ui/MainWindow.ui b/src/ui/MainWindow.ui index 5b22ce583..7ef494381 100644 --- a/src/ui/MainWindow.ui +++ b/src/ui/MainWindow.ui @@ -87,24 +87,14 @@ - + - Advanced + Widgets - - - Tool Widgets - - - - - - - - + @@ -226,14 +216,6 @@ Advanced Mode - - - true - - - HIL Simulation - - true diff --git a/src/ui/MultiVehicleDockWidget.cc b/src/ui/MultiVehicleDockWidget.cc new file mode 100644 index 000000000..6d788e44c --- /dev/null +++ b/src/ui/MultiVehicleDockWidget.cc @@ -0,0 +1,85 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#include "MultiVehicleDockWidget.h" +#include "ui_MultiVehicleDockWidget.h" +#include "MultiVehicleManager.h" + +MultiVehicleDockWidget::MultiVehicleDockWidget(QWidget *parent) + : QWidget(parent) + , _ui(new Ui::MultiVehicleDockWidget) +{ + _ui->setupUi(this); + + connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &MultiVehicleDockWidget::_activeVehicleChanged); + connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &MultiVehicleDockWidget::_vehicleAdded); + connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleRemoved, this, &MultiVehicleDockWidget::_vehicleRemoved); +} + +void MultiVehicleDockWidget::init(void) +{ + if (MultiVehicleManager::instance()->activeVehicle()) { + _vehicleAdded(MultiVehicleManager::instance()->activeVehicle()); + _activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle()); + } +} + +MultiVehicleDockWidget::~MultiVehicleDockWidget() +{ + delete _ui; +} + +void MultiVehicleDockWidget::_vehicleRemoved(Vehicle* vehicle) +{ + int id = vehicle->id(); + + if (_vehicleWidgets.contains(id)) { + _vehicleWidgets[id]->deleteLater(); + _vehicleWidgets.remove(id); + } +} + +void MultiVehicleDockWidget::_vehicleAdded(Vehicle* vehicle) +{ + int id = vehicle->id(); + + if (!_vehicleWidgets.contains(id)) { + QWidget* vehicleWidget = _newVehicleWidget(vehicle, _ui->stackedWidget); + _vehicleWidgets[id] = vehicleWidget; + _ui->stackedWidget->addWidget(vehicleWidget); + } +} + +void MultiVehicleDockWidget::_activeVehicleChanged(Vehicle* vehicle) +{ + if (vehicle) { + int id = vehicle->id(); + + if (!_vehicleWidgets.contains(id)) { + _vehicleAdded(vehicle); + } + + QWidget* vehicleWidget = _vehicleWidgets[id]; + _ui->stackedWidget->setCurrentWidget(vehicleWidget); + } +} diff --git a/src/ui/MultiVehicleDockWidget.h b/src/ui/MultiVehicleDockWidget.h new file mode 100644 index 000000000..a78be28a6 --- /dev/null +++ b/src/ui/MultiVehicleDockWidget.h @@ -0,0 +1,67 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + +#ifndef MultiVehicleDockWidget_H +#define MultiVehicleDockWidget_H + +#include +#include + +#include "Vehicle.h" + +namespace Ui +{ + class MultiVehicleDockWidget; +} + +/// Provides a base class for a dock widget which automatically handles +/// Vehicles coming and going. It does this by using a stacked widget which +/// holds individual Vehicle specific widgets. +class MultiVehicleDockWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MultiVehicleDockWidget(QWidget *parent = 0); + ~MultiVehicleDockWidget(); + + /// Must be called in the derived class contructor to initialize the base class + void init(void); + +protected: + /// Derived class must implement this to create the QWidget for the + /// specified Vehicle. + virtual QWidget* _newVehicleWidget(Vehicle* vehicle, QWidget* parent) = 0; + +private slots: + void _vehicleAdded(Vehicle* vehicle); + void _vehicleRemoved(Vehicle* vehicle); + void _activeVehicleChanged(Vehicle* vehicle); + +private: + QMap _vehicleWidgets; + + Ui::MultiVehicleDockWidget* _ui; +}; + +#endif diff --git a/src/ui/MultiVehicleDockWidget.ui b/src/ui/MultiVehicleDockWidget.ui new file mode 100644 index 000000000..64ae45242 --- /dev/null +++ b/src/ui/MultiVehicleDockWidget.ui @@ -0,0 +1,27 @@ + + + MultiVehicleDockWidget + + + + 0 + 0 + 200 + 300 + + + + Form + + + + 0 + + + + + + + + + diff --git a/src/ui/QGCHilConfiguration.cc b/src/ui/QGCHilConfiguration.cc index 58bca7e14..85a30b162 100644 --- a/src/ui/QGCHilConfiguration.cc +++ b/src/ui/QGCHilConfiguration.cc @@ -1,3 +1,26 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + #include #include "QGCHilConfiguration.h" @@ -7,10 +30,10 @@ #include "QGCHilJSBSimConfiguration.h" #include "QGCHilXPlaneConfiguration.h" -QGCHilConfiguration::QGCHilConfiguration(UAS *mav, QWidget *parent) : - QWidget(parent), - mav(mav), - ui(new Ui::QGCHilConfiguration) +QGCHilConfiguration::QGCHilConfiguration(Vehicle* vehicle, QWidget *parent) + : QWidget(parent) + , _vehicle(vehicle) + , ui(new Ui::QGCHilConfiguration) { ui->setupUi(this); @@ -29,8 +52,6 @@ QGCHilConfiguration::QGCHilConfiguration(UAS *mav, QWidget *parent) : } settings.endGroup(); - - connect(mav, SIGNAL(destroyed()), this, SLOT(deleteLater())); } void QGCHilConfiguration::receiveStatusMessage(const QString& message) @@ -65,11 +86,11 @@ void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index) if(1 == index) { // Ensure the sim exists and is disabled - mav->enableHilFlightGear(false, "", true, this); - QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(mav, this); + _vehicle->uas()->enableHilFlightGear(false, "", true, this); + QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(_vehicle->uas(), this); hfgconf->show(); ui->simulatorConfigurationLayout->addWidget(hfgconf); - QGCFlightGearLink* fg = dynamic_cast(mav->getHILSimulation()); + QGCFlightGearLink* fg = dynamic_cast(_vehicle->uas()->getHILSimulation()); if (fg) { connect(fg, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString))); @@ -79,13 +100,13 @@ void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index) else if (2 == index || 3 == index) { // Ensure the sim exists and is disabled - mav->enableHilXPlane(false); - QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(mav->getHILSimulation(), this); + _vehicle->uas()->enableHilXPlane(false); + QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(_vehicle->uas()->getHILSimulation(), this); hxpconf->show(); ui->simulatorConfigurationLayout->addWidget(hxpconf); // Select correct version of XPlane - QGCXPlaneLink* xplane = dynamic_cast(mav->getHILSimulation()); + QGCXPlaneLink* xplane = dynamic_cast(_vehicle->uas()->getHILSimulation()); if (xplane) { xplane->setVersion((index == 2) ? 10 : 9); @@ -95,11 +116,11 @@ void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index) else if (4) { // Ensure the sim exists and is disabled - mav->enableHilJSBSim(false, ""); - QGCHilJSBSimConfiguration* hfgconf = new QGCHilJSBSimConfiguration(mav, this); + _vehicle->uas()->enableHilJSBSim(false, ""); + QGCHilJSBSimConfiguration* hfgconf = new QGCHilJSBSimConfiguration(_vehicle->uas(), this); hfgconf->show(); ui->simulatorConfigurationLayout->addWidget(hfgconf); - QGCJSBSimLink* jsb = dynamic_cast(mav->getHILSimulation()); + QGCJSBSimLink* jsb = dynamic_cast(_vehicle->uas()->getHILSimulation()); if (jsb) { connect(jsb, SIGNAL(statusMessage(QString)), ui->statusLabel, SLOT(setText(QString))); diff --git a/src/ui/QGCHilConfiguration.h b/src/ui/QGCHilConfiguration.h index 025c913ae..bd82ce7f5 100644 --- a/src/ui/QGCHilConfiguration.h +++ b/src/ui/QGCHilConfiguration.h @@ -1,10 +1,32 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + + ======================================================================*/ + #ifndef QGCHILCONFIGURATION_H #define QGCHILCONFIGURATION_H #include -#include "QGCHilLink.h" -#include "UAS.h" +#include "Vehicle.h" namespace Ui { class QGCHilConfiguration; @@ -15,7 +37,7 @@ class QGCHilConfiguration : public QWidget Q_OBJECT public: - QGCHilConfiguration(UAS* mav, QWidget *parent = 0); + QGCHilConfiguration(Vehicle* vehicle, QWidget *parent = 0); ~QGCHilConfiguration(); public slots: @@ -23,13 +45,12 @@ public slots: void receiveStatusMessage(const QString& message); void setVersion(QString version); -protected: - UAS* mav; - private slots: void on_simComboBox_currentIndexChanged(int index); private: + Vehicle* _vehicle; + Ui::QGCHilConfiguration *ui; }; -- 2.22.0