Commit d33852c5 authored by dogmaphobic's avatar dogmaphobic

PX4FLOW Sensor Support.

parent a4742fdc
...@@ -271,7 +271,7 @@ HEADERS += \ ...@@ -271,7 +271,7 @@ HEADERS += \
src/ui/uas/UASMessageView.h \ src/ui/uas/UASMessageView.h \
src/MissionItem.h \ src/MissionItem.h \
src/AutoPilotPlugins/PX4/PX4AirframeLoader.h \ src/AutoPilotPlugins/PX4/PX4AirframeLoader.h \
src/QGCSettings.h src/QmlControls/QGCImageProvider.h \
WindowsBuild { WindowsBuild {
PRECOMPILED_HEADER += src/stable_headers.h PRECOMPILED_HEADER += src/stable_headers.h
...@@ -383,7 +383,7 @@ SOURCES += \ ...@@ -383,7 +383,7 @@ SOURCES += \
src/ui/uas/UASMessageView.cc \ src/ui/uas/UASMessageView.cc \
src/MissionItem.cc \ src/MissionItem.cc \
src/AutoPilotPlugins/PX4/PX4AirframeLoader.cc \ src/AutoPilotPlugins/PX4/PX4AirframeLoader.cc \
src/QGCSettings.cpp src/QmlControls/QGCImageProvider.cc \
!iOSBuild { !iOSBuild {
SOURCES += \ SOURCES += \
......
This diff is collapsed.
/*===================================================================== /*=====================================================================
QGroundControl Open Source Ground Control Station QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful, QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/ ======================================================================*/
/// @file /// @file
...@@ -30,7 +30,7 @@ QGCQmlWidgetHolder::QGCQmlWidgetHolder(const QString& title, QAction* action, QW ...@@ -30,7 +30,7 @@ QGCQmlWidgetHolder::QGCQmlWidgetHolder(const QString& title, QAction* action, QW
QGCDockWidget(title, action, parent) QGCDockWidget(title, action, parent)
{ {
_ui.setupUi(this); _ui.setupUi(this);
layout()->setContentsMargins(0,0,0,0); layout()->setContentsMargins(0,0,0,0);
if (action) { if (action) {
...@@ -69,6 +69,12 @@ QQuickItem* QGCQmlWidgetHolder::getRootObject(void) ...@@ -69,6 +69,12 @@ QQuickItem* QGCQmlWidgetHolder::getRootObject(void)
return _ui.qmlWidget->rootObject(); return _ui.qmlWidget->rootObject();
} }
QQmlEngine* QGCQmlWidgetHolder::getEngine()
{
return _ui.qmlWidget->engine();
}
void QGCQmlWidgetHolder::setResizeMode(QQuickWidget::ResizeMode resizeMode) void QGCQmlWidgetHolder::setResizeMode(QQuickWidget::ResizeMode resizeMode)
{ {
_ui.qmlWidget->setResizeMode(resizeMode); _ui.qmlWidget->setResizeMode(resizeMode);
......
/*===================================================================== /*=====================================================================
QGroundControl Open Source Ground Control Station QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful, QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/ ======================================================================*/
#ifndef QGCQmlWidgetHolder_h #ifndef QGCQmlWidgetHolder_h
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
// action = NULL // action = NULL
explicit QGCQmlWidgetHolder(const QString& title, QAction* action, QWidget *parent = 0); explicit QGCQmlWidgetHolder(const QString& title, QAction* action, QWidget *parent = 0);
~QGCQmlWidgetHolder(); ~QGCQmlWidgetHolder();
/// Sets the UAS into the widget which in turn will load facts into the context /// Sets the UAS into the widget which in turn will load facts into the context
void setAutoPilot(AutoPilotPlugin* autoPilot); void setAutoPilot(AutoPilotPlugin* autoPilot);
...@@ -58,13 +58,16 @@ public: ...@@ -58,13 +58,16 @@ public:
/// Get Root Object /// Get Root Object
QQuickItem* getRootObject(void); QQuickItem* getRootObject(void);
/// Get QML Engine
QQmlEngine* getEngine();
/// Sets the QML into the control. Will display errors message box if error occurs loading source. /// Sets the QML into the control. Will display errors message box if error occurs loading source.
/// @return true: source loaded, false: source not loaded, errors occured /// @return true: source loaded, false: source not loaded, errors occured
bool setSource(const QUrl& qmlUrl); bool setSource(const QUrl& qmlUrl);
void setContextPropertyObject(const QString& name, QObject* object); void setContextPropertyObject(const QString& name, QObject* object);
/// Sets the resize mode for the QQuickWidget container /// Sets the resize mode for the QQuickWidget container
void setResizeMode(QQuickWidget::ResizeMode resizeMode); void setResizeMode(QQuickWidget::ResizeMode resizeMode);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "AutoPilotPluginManager.h" #include "AutoPilotPluginManager.h"
#include "UASMessageHandler.h" #include "UASMessageHandler.h"
#include "FactSystem.h" #include "FactSystem.h"
#include "QGCImageProvider.h"
QGCToolbox::QGCToolbox(QGCApplication* app) QGCToolbox::QGCToolbox(QGCApplication* app)
: _firmwarePluginManager(NULL) : _firmwarePluginManager(NULL)
...@@ -45,6 +46,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app) ...@@ -45,6 +46,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app)
, _audioOutput(NULL) , _audioOutput(NULL)
, _uasMessageHandler(NULL) , _uasMessageHandler(NULL)
, _factSystem(NULL) , _factSystem(NULL)
, _imageProvider(NULL)
{ {
_firmwarePluginManager = new FirmwarePluginManager(app); _firmwarePluginManager = new FirmwarePluginManager(app);
_autopilotPluginManager = new AutoPilotPluginManager(app); _autopilotPluginManager = new AutoPilotPluginManager(app);
...@@ -57,6 +59,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app) ...@@ -57,6 +59,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app)
_joystickManager = new JoystickManager(app); _joystickManager = new JoystickManager(app);
_audioOutput = new GAudioOutput(app); _audioOutput = new GAudioOutput(app);
_uasMessageHandler = new UASMessageHandler(app); _uasMessageHandler = new UASMessageHandler(app);
_imageProvider = new QGCImageProvider(app);
_firmwarePluginManager->setToolbox(this); _firmwarePluginManager->setToolbox(this);
_autopilotPluginManager->setToolbox(this); _autopilotPluginManager->setToolbox(this);
...@@ -69,6 +72,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app) ...@@ -69,6 +72,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app)
_joystickManager->setToolbox(this); _joystickManager->setToolbox(this);
_audioOutput->setToolbox(this); _audioOutput->setToolbox(this);
_uasMessageHandler->setToolbox(this); _uasMessageHandler->setToolbox(this);
_imageProvider->setToolbox(this);
} }
QGCToolbox::~QGCToolbox() QGCToolbox::~QGCToolbox()
......
/*===================================================================== /*=====================================================================
QGroundControl Open Source Ground Control Station QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful, QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/ ======================================================================*/
#ifndef QGCToolbox_h #ifndef QGCToolbox_h
...@@ -38,6 +38,7 @@ class GAudioOutput; ...@@ -38,6 +38,7 @@ class GAudioOutput;
class FirmwarePluginManager; class FirmwarePluginManager;
class AutoPilotPluginManager; class AutoPilotPluginManager;
class FactSystem; class FactSystem;
class QGCImageProvider;
/// This is used to manage all of our top level services/tools /// This is used to manage all of our top level services/tools
class QGCToolbox { class QGCToolbox {
...@@ -46,29 +47,31 @@ public: ...@@ -46,29 +47,31 @@ public:
QGCToolbox(QGCApplication* app); QGCToolbox(QGCApplication* app);
~QGCToolbox(); ~QGCToolbox();
LinkManager* linkManager(void) { return _linkManager; } LinkManager* linkManager(void) { return _linkManager; }
MAVLinkProtocol* mavlinkProtocol(void) { return _mavlinkProtocol; } MAVLinkProtocol* mavlinkProtocol(void) { return _mavlinkProtocol; }
MultiVehicleManager* multiVehicleManager(void) { return _multiVehicleManager; } MultiVehicleManager* multiVehicleManager(void) { return _multiVehicleManager; }
JoystickManager* joystickManager(void) { return _joystickManager; } JoystickManager* joystickManager(void) { return _joystickManager; }
UASMessageHandler* uasMessageHandler(void) { return _uasMessageHandler; } UASMessageHandler* uasMessageHandler(void) { return _uasMessageHandler; }
HomePositionManager* homePositionManager(void) { return _homePositionManager; } HomePositionManager* homePositionManager(void) { return _homePositionManager; }
FlightMapSettings* flightMapSettings(void) { return _flightMapSettings; } FlightMapSettings* flightMapSettings(void) { return _flightMapSettings; }
GAudioOutput* audioOutput(void) { return _audioOutput; } GAudioOutput* audioOutput(void) { return _audioOutput; }
FirmwarePluginManager* firmwarePluginManager(void) { return _firmwarePluginManager; } FirmwarePluginManager* firmwarePluginManager(void) { return _firmwarePluginManager; }
AutoPilotPluginManager* autopilotPluginManager(void) { return _autopilotPluginManager; } AutoPilotPluginManager* autopilotPluginManager(void) { return _autopilotPluginManager; }
QGCImageProvider* imageProvider() { return _imageProvider; }
private: private:
FirmwarePluginManager* _firmwarePluginManager; FirmwarePluginManager* _firmwarePluginManager;
AutoPilotPluginManager* _autopilotPluginManager; AutoPilotPluginManager* _autopilotPluginManager;
LinkManager* _linkManager; LinkManager* _linkManager;
MultiVehicleManager* _multiVehicleManager; MultiVehicleManager* _multiVehicleManager;
MAVLinkProtocol* _mavlinkProtocol; MAVLinkProtocol* _mavlinkProtocol;
FlightMapSettings* _flightMapSettings; FlightMapSettings* _flightMapSettings;
HomePositionManager* _homePositionManager; HomePositionManager* _homePositionManager;
JoystickManager* _joystickManager; JoystickManager* _joystickManager;
GAudioOutput* _audioOutput; GAudioOutput* _audioOutput;
UASMessageHandler* _uasMessageHandler; UASMessageHandler* _uasMessageHandler;
FactSystem* _factSystem; FactSystem* _factSystem;
QGCImageProvider* _imageProvider;
}; };
/// This is the base class for all tools /// This is the base class for all tools
......
...@@ -23,17 +23,75 @@ along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,17 +23,75 @@ along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
/** /**
* @file * @file
* @brief Implementation of class QGCSettings * @brief Image Provider
* *
* @author Gus Grubba <mavlink@grubba.com> * @author Gus Grubba <mavlink@grubba.com>
* *
*/ */
#include "QGCSettings.h" #include "QGCImageProvider.h"
QGCSettings::QGCSettings(QObject *parent) : QObject(parent) #include <QPainter>
#include <qFont>
QGCImageProvider::QGCImageProvider(QGCApplication *app)
: QGCTool(app)
, QQuickImageProvider(QQmlImageProviderBase::Image)
{
}
QGCImageProvider::~QGCImageProvider()
{
}
void QGCImageProvider::setToolbox(QGCToolbox *toolbox)
{ {
QGCTool::setToolbox(toolbox);
//-- Dummy temporary image until something comes along
_pImage = QImage(320, 240, QImage::Format_RGBA8888);
_pImage.fill(Qt::black);
QPainter painter(&_pImage);
QFont f = painter.font();
f.setPixelSize(20);
painter.setFont(f);
painter.setPen(Qt::white);
painter.drawText(QRectF(0, 0, 320, 240), Qt::AlignCenter, "Waiting...");
}
QImage QGCImageProvider::requestImage(const QString & /* image url with vehicle id*/, QSize *, const QSize &)
{
/*
The QML side will request an image using a special URL, which we've registered as QGCImages.
The URL follows this format (or anything you want to make out of it after the "QGCImages" part):
"image://QGCImages/vvv/iii"
Where:
vvv: Some vehicle id
iii: An auto incremented index (which forces the Item to reload the image)
The image index is incremented each time a new image arrives. A signal is emitted and the QML side
updates its contents automatically.
Image {
source: "image://QGCImages/" + _activeVehicle.id + "/" + _activeVehicle.flowImageIndex
width: parent.width * 0.5
height: width * 0.75
cache: false
anchors.centerIn: parent
fillMode: Image.PreserveAspectFit
}
For now, we don't even look at the URL. This will have to be fixed if we're to support multiple
vehicles transmitting flow images.
*/
return _pImage;
}
void QGCImageProvider::setImage(QImage* pImage, int /* vehicle id*/)
{
_pImage = pImage->mirrored();
} }
...@@ -23,28 +23,37 @@ ...@@ -23,28 +23,37 @@
/** /**
* @file * @file
* @brief Definition of main class * @brief Image Provider
* *
* @author Gus Grubba <mavlink@grubba.com> * @author Gus Grubba <mavlink@grubba.com>
* *
*/ */
#ifndef QGCSETTINGS_H #ifndef QGCIMAGEPROVIDER_H
#define QGCSETTINGS_H #define QGCIMAGEPROVIDER_H
#include <QObject> #include <QObject>
#include <QQmlListProperty>
#include <QQuickImageProvider>
class QGCSettings : public QObject #include "QGCToolbox.h"
class QGCImageProvider : public QGCTool, public QQuickImageProvider
{ {
Q_OBJECT
public: public:
explicit QGCSettings(QObject *parent = 0); QGCImageProvider (QGCApplication* app);
~QGCImageProvider ();
signals: QImage requestImage (const QString & id, QSize * size, const QSize & requestedSize);
void setImage (QImage* pImage, int id = 0);
public slots: void setToolbox (QGCToolbox *toolbox);
private:
//-- TODO: For now this is holding a single image. If you happen to have two
// or more vehicles with flow, it will not work. To properly manage that condition
// this should be a map between each vehicle and its image. The URL provided
// for the image request would contain the vehicle identification.
QImage _pImage;
}; };
#endif // QGCSETTINGS_H
#endif // QGCIMAGEPROVIDER_H
...@@ -39,6 +39,7 @@ Button { ...@@ -39,6 +39,7 @@ Button {
verticalAlignment: TextEdit.AlignVCenter verticalAlignment: TextEdit.AlignVCenter
horizontalAlignment: TextEdit.AlignHCenter horizontalAlignment: TextEdit.AlignHCenter
color: showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText color: showHighlight ? qgcPal.buttonHighlightText : qgcPal.buttonText
font.pixelSize: ScreenTools.isMobile ? ScreenTools.defaultFontPixelSize * 0.65 : ScreenTools.defaultFontPixelSize
text: control.text text: control.text
Rectangle { Rectangle {
......
/*===================================================================== /*=====================================================================
QGroundControl Open Source Ground Control Station QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful, QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/ ======================================================================*/
/// @file /// @file
...@@ -56,6 +56,7 @@ void MultiVehicleManager::setToolbox(QGCToolbox *toolbox) ...@@ -56,6 +56,7 @@ void MultiVehicleManager::setToolbox(QGCToolbox *toolbox)
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
qmlRegisterUncreatableType<MultiVehicleManager>("QGroundControl.MultiVehicleManager", 1, 0, "MultiVehicleManager", "Reference only"); qmlRegisterUncreatableType<MultiVehicleManager>("QGroundControl.MultiVehicleManager", 1, 0, "MultiVehicleManager", "Reference only");
} }
bool MultiVehicleManager::notifyHeartbeatInfo(LinkInterface* link, int vehicleId, mavlink_heartbeat_t& heartbeat) bool MultiVehicleManager::notifyHeartbeatInfo(LinkInterface* link, int vehicleId, mavlink_heartbeat_t& heartbeat)
...@@ -64,7 +65,7 @@ bool MultiVehicleManager::notifyHeartbeatInfo(LinkInterface* link, int vehicleId ...@@ -64,7 +65,7 @@ bool MultiVehicleManager::notifyHeartbeatInfo(LinkInterface* link, int vehicleId
if (vehicleId == _mavlinkProtocol->getSystemId()) { if (vehicleId == _mavlinkProtocol->getSystemId()) {
_app->showToolBarMessage(QString("Warning: A vehicle is using the same system id as QGroundControl: %1").arg(vehicleId)); _app->showToolBarMessage(QString("Warning: A vehicle is using the same system id as QGroundControl: %1").arg(vehicleId));
} }
QSettings settings; QSettings settings;
bool mavlinkVersionCheck = settings.value("VERSION_CHECK_ENABLED", true).toBool(); bool mavlinkVersionCheck = settings.value("VERSION_CHECK_ENABLED", true).toBool();
if (mavlinkVersionCheck && heartbeat.mavlink_version != MAVLINK_VERSION) { if (mavlinkVersionCheck && heartbeat.mavlink_version != MAVLINK_VERSION) {
...@@ -74,24 +75,24 @@ bool MultiVehicleManager::notifyHeartbeatInfo(LinkInterface* link, int vehicleId ...@@ -74,24 +75,24 @@ bool MultiVehicleManager::notifyHeartbeatInfo(LinkInterface* link, int vehicleId
"QGroundControl therefore refuses to connect to vehicle #%1, which sends MAVLink version %2 (QGroundControl uses version %3).").arg(vehicleId).arg(heartbeat.mavlink_version).arg(MAVLINK_VERSION)); "QGroundControl therefore refuses to connect to vehicle #%1, which sends MAVLink version %2 (QGroundControl uses version %3).").arg(vehicleId).arg(heartbeat.mavlink_version).arg(MAVLINK_VERSION));
return false; return false;
} }
Vehicle* vehicle = new Vehicle(link, vehicleId, (MAV_AUTOPILOT)heartbeat.autopilot, (MAV_TYPE)heartbeat.type, _firmwarePluginManager, _autopilotPluginManager, _joystickManager); Vehicle* vehicle = new Vehicle(link, vehicleId, (MAV_AUTOPILOT)heartbeat.autopilot, (MAV_TYPE)heartbeat.type, _firmwarePluginManager, _autopilotPluginManager, _joystickManager);
if (!vehicle) { if (!vehicle) {
qWarning() << "New Vehicle allocation failed"; qWarning() << "New Vehicle allocation failed";
return false; return false;
} }
connect(vehicle, &Vehicle::allLinksDisconnected, this, &MultiVehicleManager::_deleteVehiclePhase1); connect(vehicle, &Vehicle::allLinksDisconnected, this, &MultiVehicleManager::_deleteVehiclePhase1);
connect(vehicle->autopilotPlugin(), &AutoPilotPlugin::parametersReadyChanged, this, &MultiVehicleManager::_autopilotParametersReadyChanged); connect(vehicle->autopilotPlugin(), &AutoPilotPlugin::parametersReadyChanged, this, &MultiVehicleManager::_autopilotParametersReadyChanged);
_vehicles.append(vehicle); _vehicles.append(vehicle);
emit vehicleAdded(vehicle); emit vehicleAdded(vehicle);
setActiveVehicle(vehicle); setActiveVehicle(vehicle);
} }
return true; return true;
} }
...@@ -115,17 +116,17 @@ void MultiVehicleManager::_deleteVehiclePhase1(Vehicle* vehicle) ...@@ -115,17 +116,17 @@ void MultiVehicleManager::_deleteVehiclePhase1(Vehicle* vehicle)
if (!found) { if (!found) {
qWarning() << "Vehicle not found in map!"; qWarning() << "Vehicle not found in map!";
} }
vehicle->setActive(false); vehicle->setActive(false);
vehicle->uas()->clearVehicle(); vehicle->uas()->clearVehicle();
// First we must signal that a vehicle is no longer available. // First we must signal that a vehicle is no longer available.
_activeVehicleAvailable = false; _activeVehicleAvailable = false;
_parameterReadyVehicleAvailable = false; _parameterReadyVehicleAvailable = false;
emit activeVehicleAvailableChanged(false); emit activeVehicleAvailableChanged(false);
emit parameterReadyVehicleAvailableChanged(false); emit parameterReadyVehicleAvailableChanged(false);
emit vehicleRemoved(vehicle); emit vehicleRemoved(vehicle);
// We must let the above signals flow through the system as well as get back to the main loop event queue // We must let the above signals flow through the system as well as get back to the main loop event queue
// before we can actually delete the Vehicle. The reason is that Qml may be holding on the references to it. // before we can actually delete the Vehicle. The reason is that Qml may be holding on the references to it.
// Even though the above signals should unload any Qml which has references, that Qml will not be destroyed // Even though the above signals should unload any Qml which has references, that Qml will not be destroyed
...@@ -141,15 +142,15 @@ void MultiVehicleManager::_deleteVehiclePhase2 (void) ...@@ -141,15 +142,15 @@ void MultiVehicleManager::_deleteVehiclePhase2 (void)
/// Qml has been notified of vehicle about to go away and should be disconnected from it by now. /// Qml has been notified of vehicle about to go away and should be disconnected from it by now.
/// This means we can now clear the active vehicle property and delete the Vehicle for real. /// This means we can now clear the active vehicle property and delete the Vehicle for real.
Vehicle* newActiveVehicle = NULL; Vehicle* newActiveVehicle = NULL;
if (_vehicles.count()) { if (_vehicles.count()) {
newActiveVehicle = qobject_cast<Vehicle*>(_vehicles[0]); newActiveVehicle = qobject_cast<Vehicle*>(_vehicles[0]);
} }
_activeVehicle = newActiveVehicle; _activeVehicle = newActiveVehicle;
emit activeVehicleChanged(newActiveVehicle); emit activeVehicleChanged(newActiveVehicle);
if (_activeVehicle) { if (_activeVehicle) {
_activeVehicle->setActive(true); _activeVehicle->setActive(true);
emit activeVehicleAvailableChanged(true); emit activeVehicleAvailableChanged(true);
...@@ -157,7 +158,7 @@ void MultiVehicleManager::_deleteVehiclePhase2 (void) ...@@ -157,7 +158,7 @@ void MultiVehicleManager::_deleteVehiclePhase2 (void)
emit parameterReadyVehicleAvailableChanged(true); emit parameterReadyVehicleAvailableChanged(true);
} }
} }
_vehicleBeingDeleted->deleteLater(); _vehicleBeingDeleted->deleteLater();
} }
...@@ -168,10 +169,10 @@ void MultiVehicleManager::setActiveVehicle(Vehicle* vehicle) ...@@ -168,10 +169,10 @@ void MultiVehicleManager::setActiveVehicle(Vehicle* vehicle)
if (vehicle != _activeVehicle) { if (vehicle != _activeVehicle) {
if (_activeVehicle) { if (_activeVehicle) {
_activeVehicle->setActive(false); _activeVehicle->setActive(false);
// The sequence of signals is very important in order to not leave Qml elements connected // The sequence of signals is very important in order to not leave Qml elements connected
// to a non-existent vehicle. // to a non-existent vehicle.
// First we must signal that there is no active vehicle available. This will disconnect // First we must signal that there is no active vehicle available. This will disconnect
// any existing ui from the currently active vehicle. // any existing ui from the currently active vehicle.
_activeVehicleAvailable = false; _activeVehicleAvailable = false;
...@@ -179,7 +180,7 @@ void MultiVehicleManager::setActiveVehicle(Vehicle* vehicle) ...@@ -179,7 +180,7 @@ void MultiVehicleManager::setActiveVehicle(Vehicle* vehicle)
emit activeVehicleAvailableChanged(false); emit activeVehicleAvailableChanged(false);
emit parameterReadyVehicleAvailableChanged(false); emit parameterReadyVehicleAvailableChanged(false);
} }
// See explanation in _deleteVehiclePhase1 // See explanation in _deleteVehiclePhase1
_vehicleBeingSetActive = vehicle; _vehicleBeingSetActive = vehicle;
QTimer::singleShot(20, this, &MultiVehicleManager::_setActiveVehiclePhase2); QTimer::singleShot(20, this, &MultiVehicleManager::_setActiveVehiclePhase2);
...@@ -193,13 +194,13 @@ void MultiVehicleManager::_setActiveVehiclePhase2(void) ...@@ -193,13 +194,13 @@ void MultiVehicleManager::_setActiveVehiclePhase2(void)
// Now we signal the new active vehicle // Now we signal the new active vehicle
_activeVehicle = _vehicleBeingSetActive; _activeVehicle = _vehicleBeingSetActive;
emit activeVehicleChanged(_activeVehicle); emit activeVehicleChanged(_activeVehicle);
// And finally vehicle availability // And finally vehicle availability
if (_activeVehicle) { if (_activeVehicle) {
_activeVehicle->setActive(true); _activeVehicle->setActive(true);
_activeVehicleAvailable = true; _activeVehicleAvailable = true;