Commit 3433b541 authored by Don Gagne's avatar Don Gagne

Remove as many Singletons as possible

Instead us a Toolbox concept which hangs off of QGCApplication
parent ec1e8c2f
...@@ -242,6 +242,7 @@ HEADERS += \ ...@@ -242,6 +242,7 @@ HEADERS += \
src/QGCQuickWidget.h \ src/QGCQuickWidget.h \
src/QGCSingleton.h \ src/QGCSingleton.h \
src/QGCTemporaryFile.h \ src/QGCTemporaryFile.h \
src/QGCToolbox.h \
src/QmlControls/CoordinateVector.h \ src/QmlControls/CoordinateVector.h \
src/QmlControls/MavlinkQmlSingleton.h \ src/QmlControls/MavlinkQmlSingleton.h \
src/QmlControls/ParameterEditorController.h \ src/QmlControls/ParameterEditorController.h \
...@@ -356,6 +357,7 @@ SOURCES += \ ...@@ -356,6 +357,7 @@ SOURCES += \
src/QGCQuickWidget.cc \ src/QGCQuickWidget.cc \
src/QGCSingleton.cc \ src/QGCSingleton.cc \
src/QGCTemporaryFile.cc \ src/QGCTemporaryFile.cc \
src/QGCToolbox.cc \
src/QGCGeo.cc \ src/QGCGeo.cc \
src/QmlControls/CoordinateVector.cc \ src/QmlControls/CoordinateVector.cc \
src/QmlControls/ParameterEditorController.cc \ src/QmlControls/ParameterEditorController.cc \
......
...@@ -101,7 +101,7 @@ bool AutoPilotPlugin::setupComplete(void) ...@@ -101,7 +101,7 @@ bool AutoPilotPlugin::setupComplete(void)
void AutoPilotPlugin::resetAllParametersToDefaults(void) void AutoPilotPlugin::resetAllParametersToDefaults(void)
{ {
mavlink_message_t msg; mavlink_message_t msg;
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance(); MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol();
mavlink_msg_command_long_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, _vehicle->uas()->getUASID(), 0, MAV_CMD_PREFLIGHT_STORAGE, 0, 2, -1, 0, 0, 0, 0, 0); mavlink_msg_command_long_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, _vehicle->uas()->getUASID(), 0, MAV_CMD_PREFLIGHT_STORAGE, 0, 2, -1, 0, 0, 0, 0, 0);
_vehicle->sendMessage(msg); _vehicle->sendMessage(msg);
......
...@@ -29,14 +29,6 @@ ...@@ -29,14 +29,6 @@
#include "APM/APMAutoPilotPlugin.h" #include "APM/APMAutoPilotPlugin.h"
#include "Generic/GenericAutoPilotPlugin.h" #include "Generic/GenericAutoPilotPlugin.h"
IMPLEMENT_QGC_SINGLETON(AutoPilotPluginManager, AutoPilotPluginManager)
AutoPilotPluginManager::AutoPilotPluginManager(QObject* parent) :
QGCSingleton(parent)
{
}
AutoPilotPlugin* AutoPilotPluginManager::newAutopilotPluginForVehicle(Vehicle* vehicle) AutoPilotPlugin* AutoPilotPluginManager::newAutopilotPluginForVehicle(Vehicle* vehicle)
{ {
switch (vehicle->firmwareType()) { switch (vehicle->firmwareType()) {
......
...@@ -32,23 +32,19 @@ ...@@ -32,23 +32,19 @@
#include <QString> #include <QString>
#include "AutoPilotPlugin.h" #include "AutoPilotPlugin.h"
#include "QGCSingleton.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "QGCToolbox.h"
/// AutoPilotPlugin manager is a singleton which maintains the list of AutoPilotPlugin objects. class QGCApplication;
class AutoPilotPluginManager : public QGCSingleton class AutoPilotPluginManager : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(AutoPilotPluginManager, AutoPilotPluginManager)
public: public:
AutoPilotPluginManager(QGCApplication* app) : QGCTool(app) { }
AutoPilotPlugin* newAutopilotPluginForVehicle(Vehicle* vehicle); AutoPilotPlugin* newAutopilotPluginForVehicle(Vehicle* vehicle);
private:
/// All access to singleton is through AutoPilotPluginManager::instance
AutoPilotPluginManager(QObject* parent = NULL);
}; };
#endif #endif
...@@ -98,7 +98,7 @@ AirframeComponentController::~AirframeComponentController() ...@@ -98,7 +98,7 @@ AirframeComponentController::~AirframeComponentController()
void AirframeComponentController::changeAutostart(void) void AirframeComponentController::changeAutostart(void)
{ {
if (MultiVehicleManager::instance()->vehicles().count() > 1) { if (qgcApp()->toolbox()->multiVehicleManager()->vehicles().count() > 1) {
QGCMessageBox::warning("Airframe Config", "You cannot change airframe configuration while connected to multiple vehicles."); QGCMessageBox::warning("Airframe Config", "You cannot change airframe configuration while connected to multiple vehicles.");
return; return;
} }
...@@ -139,7 +139,7 @@ void AirframeComponentController::_rebootAfterStackUnwind(void) ...@@ -139,7 +139,7 @@ void AirframeComponentController::_rebootAfterStackUnwind(void)
QGC::SLEEP::usleep(500); QGC::SLEEP::usleep(500);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents); qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
} }
LinkManager::instance()->disconnectAll(); qgcApp()->toolbox()->linkManager()->disconnectAll();
qgcApp()->restoreOverrideCursor(); qgcApp()->restoreOverrideCursor();
} }
......
...@@ -135,7 +135,6 @@ QString Fact::valueString(void) const ...@@ -135,7 +135,6 @@ QString Fact::valueString(void) const
switch (type()) { switch (type()) {
case FactMetaData::valueTypeFloat: case FactMetaData::valueTypeFloat:
qDebug() << name() << value() << decimalPlaces();
valueString = QString("%1").arg(value().toFloat(), 0, 'g', decimalPlaces()); valueString = QString("%1").arg(value().toFloat(), 0, 'g', decimalPlaces());
break; break;
case FactMetaData::valueTypeDouble: case FactMetaData::valueTypeDouble:
......
...@@ -36,7 +36,7 @@ QGC_LOGGING_CATEGORY(FactPanelControllerLog, "FactPanelControllerLog") ...@@ -36,7 +36,7 @@ QGC_LOGGING_CATEGORY(FactPanelControllerLog, "FactPanelControllerLog")
FactPanelController::FactPanelController(void) : FactPanelController::FactPanelController(void) :
_factPanel(NULL) _factPanel(NULL)
{ {
_vehicle = MultiVehicleManager::instance()->activeVehicle(); _vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
Q_ASSERT(_vehicle); Q_ASSERT(_vehicle);
_uas = _vehicle->uas(); _uas = _vehicle->uas();
......
...@@ -29,19 +29,18 @@ ...@@ -29,19 +29,18 @@
#include <QtQml> #include <QtQml>
IMPLEMENT_QGC_SINGLETON(FactSystem, FactSystem)
const char* FactSystem::_factSystemQmlUri = "QGroundControl.FactSystem"; const char* FactSystem::_factSystemQmlUri = "QGroundControl.FactSystem";
FactSystem::FactSystem(QObject* parent) : FactSystem::FactSystem(QGCApplication* app)
QGCSingleton(parent) : QGCTool(app)
{ {
qmlRegisterType<Fact>(_factSystemQmlUri, 1, 0, "Fact");
qmlRegisterType<FactPanelController>(_factSystemQmlUri, 1, 0, "FactPanelController");
} }
FactSystem::~FactSystem() void FactSystem::setToolbox(QGCToolbox *toolbox)
{ {
QGCTool::setToolbox(toolbox);
qmlRegisterType<Fact>(_factSystemQmlUri, 1, 0, "Fact");
qmlRegisterType<FactPanelController>(_factSystemQmlUri, 1, 0, "FactPanelController");
} }
...@@ -29,10 +29,8 @@ ...@@ -29,10 +29,8 @@
#include "Fact.h" #include "Fact.h"
#include "FactMetaData.h" #include "FactMetaData.h"
#include "QGCSingleton.h" #include "QGCToolbox.h"
/// FactSystem is a singleton which provides access to the Facts in the system
///
/// The components of the FactSystem are a Fact which holds an individual value. FactMetaData holds /// The components of the FactSystem are a Fact which holds an individual value. FactMetaData holds
/// additional meta data associated with a Fact such as description, min/max ranges and so forth. /// additional meta data associated with a Fact such as description, min/max ranges and so forth.
/// The FactValidator object is a QML validator which validates input according to the FactMetaData /// The FactValidator object is a QML validator which validates input according to the FactMetaData
...@@ -40,13 +38,17 @@ ...@@ -40,13 +38,17 @@
/// of this is the PX4ParameterMetaData onbject which is part of the PX4 AutoPilot plugin. It exposes /// of this is the PX4ParameterMetaData onbject which is part of the PX4 AutoPilot plugin. It exposes
/// the firmware parameters to QML such that you can bind QML ui elements directly to parameters. /// the firmware parameters to QML such that you can bind QML ui elements directly to parameters.
class FactSystem : public QGCSingleton class FactSystem : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(FactSystem, FactSystem)
public: public:
/// All access to FactSystem is through FactSystem::instance, so constructor is private
FactSystem(QGCApplication* app);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
typedef enum { typedef enum {
ParameterProvider, ParameterProvider,
} Provider_t; } Provider_t;
...@@ -54,10 +56,6 @@ public: ...@@ -54,10 +56,6 @@ public:
static const int defaultComponentId = -1; static const int defaultComponentId = -1;
private: private:
/// All access to FactSystem is through FactSystem::instance, so constructor is private
FactSystem(QObject* parent = NULL);
~FactSystem();
static const char* _factSystemQmlUri; ///< URI for FactSystem QML imports static const char* _factSystemQmlUri; ///< URI for FactSystem QML imports
}; };
......
...@@ -44,19 +44,9 @@ void FactSystemTestBase::_init(MAV_AUTOPILOT autopilot) ...@@ -44,19 +44,9 @@ void FactSystemTestBase::_init(MAV_AUTOPILOT autopilot)
{ {
UnitTest::init(); UnitTest::init();
MockLink* link = new MockLink(); _connectMockLink(autopilot);
link->setFirmwareType(autopilot);
LinkManager::instance()->_addLink(link);
LinkManager::instance()->connectLink(link); _plugin = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->autopilotPlugin();
// Wait for the Vehicle to get created
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
QCOMPARE(spyVehicle.wait(5000), true);
QVERIFY(MultiVehicleManager::instance()->parameterReadyVehicleAvailable());
QVERIFY(MultiVehicleManager::instance()->activeVehicle());
_plugin = MultiVehicleManager::instance()->activeVehicle()->autopilotPlugin();
Q_ASSERT(_plugin); Q_ASSERT(_plugin);
} }
......
...@@ -50,7 +50,7 @@ ParameterLoader::ParameterLoader(AutoPilotPlugin* autopilot, Vehicle* vehicle, Q ...@@ -50,7 +50,7 @@ ParameterLoader::ParameterLoader(AutoPilotPlugin* autopilot, Vehicle* vehicle, Q
QObject(parent), QObject(parent),
_autopilot(autopilot), _autopilot(autopilot),
_vehicle(vehicle), _vehicle(vehicle),
_mavlink(MAVLinkProtocol::instance()), _mavlink(qgcApp()->toolbox()->mavlinkProtocol()),
_parametersReady(false), _parametersReady(false),
_initialLoadComplete(false), _initialLoadComplete(false),
_defaultComponentId(FactSystem::defaultComponentId), _defaultComponentId(FactSystem::defaultComponentId),
...@@ -308,7 +308,7 @@ void ParameterLoader::refreshAllParameters(void) ...@@ -308,7 +308,7 @@ void ParameterLoader::refreshAllParameters(void)
_dataMutex.unlock(); _dataMutex.unlock();
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance(); MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol();
Q_ASSERT(mavlink); Q_ASSERT(mavlink);
mavlink_message_t msg; mavlink_message_t msg;
...@@ -501,7 +501,7 @@ void ParameterLoader::_tryCacheLookup() ...@@ -501,7 +501,7 @@ void ParameterLoader::_tryCacheLookup()
/* Start waiting for 2.5 seconds to get a cache hit and avoid loading all params over the radio */ /* Start waiting for 2.5 seconds to get a cache hit and avoid loading all params over the radio */
_cacheTimeoutTimer.start(); _cacheTimeoutTimer.start();
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance(); MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol();
Q_ASSERT(mavlink); Q_ASSERT(mavlink);
mavlink_message_t msg; mavlink_message_t msg;
...@@ -825,7 +825,7 @@ void ParameterLoader::_checkInitialLoadComplete(void) ...@@ -825,7 +825,7 @@ void ParameterLoader::_checkInitialLoadComplete(void)
// Check for any errors during vehicle boot // Check for any errors during vehicle boot
UASMessageHandler* msgHandler = UASMessageHandler::instance(); UASMessageHandler* msgHandler = qgcApp()->toolbox()->uasMessageHandler();
if (msgHandler->getErrorCountTotal()) { if (msgHandler->getErrorCountTotal()) {
QString errors; QString errors;
bool firstError = true; bool firstError = true;
......
...@@ -139,8 +139,7 @@ QString APMCustomMode::modeString() const ...@@ -139,8 +139,7 @@ QString APMCustomMode::modeString() const
return mode; return mode;
} }
APMFirmwarePlugin::APMFirmwarePlugin(QObject* parent) APMFirmwarePlugin::APMFirmwarePlugin(void)
: FirmwarePlugin(parent)
{ {
_textSeverityAdjustmentNeeded = false; _textSeverityAdjustmentNeeded = false;
} }
......
...@@ -94,7 +94,7 @@ public: ...@@ -94,7 +94,7 @@ public:
protected: protected:
/// All access to singleton is through stack specific implementation /// All access to singleton is through stack specific implementation
APMFirmwarePlugin(QObject* parent = NULL); APMFirmwarePlugin(void);
void setSupportedModes(QList<APMCustomMode> supportedModes); void setSupportedModes(QList<APMCustomMode> supportedModes);
private: private:
......
...@@ -53,8 +53,7 @@ APMCopterMode::APMCopterMode(uint32_t mode, bool settable) : APMCustomMode(mode, ...@@ -53,8 +53,7 @@ APMCopterMode::APMCopterMode(uint32_t mode, bool settable) : APMCustomMode(mode,
setEnumToStringMapping(enumToString); setEnumToStringMapping(enumToString);
} }
ArduCopterFirmwarePlugin::ArduCopterFirmwarePlugin(QObject* parent) : ArduCopterFirmwarePlugin::ArduCopterFirmwarePlugin(void)
APMFirmwarePlugin(parent)
{ {
QList<APMCustomMode> supportedFlightModes; QList<APMCustomMode> supportedFlightModes;
supportedFlightModes << APMCopterMode(APMCopterMode::STABILIZE ,true); supportedFlightModes << APMCopterMode(APMCopterMode::STABILIZE ,true);
......
...@@ -68,7 +68,7 @@ public: ...@@ -68,7 +68,7 @@ public:
protected: protected:
/// All access to singleton is through instance() /// All access to singleton is through instance()
ArduCopterFirmwarePlugin(QObject* parent = NULL); ArduCopterFirmwarePlugin(void);
private: private:
}; };
......
...@@ -50,8 +50,7 @@ APMPlaneMode::APMPlaneMode(uint32_t mode, bool settable) : APMCustomMode(mode, s ...@@ -50,8 +50,7 @@ APMPlaneMode::APMPlaneMode(uint32_t mode, bool settable) : APMCustomMode(mode, s
setEnumToStringMapping(enumToString); setEnumToStringMapping(enumToString);
} }
ArduPlaneFirmwarePlugin::ArduPlaneFirmwarePlugin(QObject* parent) : ArduPlaneFirmwarePlugin::ArduPlaneFirmwarePlugin(void)
APMFirmwarePlugin(parent)
{ {
QList<APMCustomMode> supportedFlightModes; QList<APMCustomMode> supportedFlightModes;
supportedFlightModes << APMPlaneMode(APMPlaneMode::MANUAL ,true); supportedFlightModes << APMPlaneMode(APMPlaneMode::MANUAL ,true);
......
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
protected: protected:
/// All access to singleton is through instance() /// All access to singleton is through instance()
ArduPlaneFirmwarePlugin(QObject* parent = NULL); ArduPlaneFirmwarePlugin(void);
private: private:
}; };
......
...@@ -44,8 +44,7 @@ APMRoverMode::APMRoverMode(uint32_t mode, bool settable) : APMCustomMode(mode, s ...@@ -44,8 +44,7 @@ APMRoverMode::APMRoverMode(uint32_t mode, bool settable) : APMCustomMode(mode, s
setEnumToStringMapping(enumToString); setEnumToStringMapping(enumToString);
} }
ArduRoverFirmwarePlugin::ArduRoverFirmwarePlugin(QObject* parent) : ArduRoverFirmwarePlugin::ArduRoverFirmwarePlugin(void)
APMFirmwarePlugin(parent)
{ {
QList<APMCustomMode> supportedFlightModes; QList<APMCustomMode> supportedFlightModes;
supportedFlightModes << APMRoverMode(APMRoverMode::MANUAL ,true); supportedFlightModes << APMRoverMode(APMRoverMode::MANUAL ,true);
......
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
protected: protected:
/// All access to singleton is through instance() /// All access to singleton is through instance()
ArduRoverFirmwarePlugin(QObject* parent = NULL); ArduRoverFirmwarePlugin(void);
private: private:
}; };
......
...@@ -112,7 +112,7 @@ public: ...@@ -112,7 +112,7 @@ public:
virtual void addMetaDataToFact(Fact* fact) = 0; virtual void addMetaDataToFact(Fact* fact) = 0;
protected: protected:
FirmwarePlugin(QObject* parent = NULL) : QGCSingleton(parent) { } FirmwarePlugin(void) { };
}; };
#endif #endif
...@@ -31,19 +31,6 @@ ...@@ -31,19 +31,6 @@
#include "APM/ArduRoverFirmwarePlugin.h" #include "APM/ArduRoverFirmwarePlugin.h"
#include "PX4/PX4FirmwarePlugin.h" #include "PX4/PX4FirmwarePlugin.h"
IMPLEMENT_QGC_SINGLETON(FirmwarePluginManager, FirmwarePluginManager)
FirmwarePluginManager::FirmwarePluginManager(QObject* parent) :
QGCSingleton(parent)
{
}
FirmwarePluginManager::~FirmwarePluginManager()
{
}
FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType) FirmwarePlugin* FirmwarePluginManager::firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType)
{ {
switch (autopilotType) { switch (autopilotType) {
......
...@@ -29,29 +29,26 @@ ...@@ -29,29 +29,26 @@
#include <QObject> #include <QObject>
#include "QGCSingleton.h"
#include "FirmwarePlugin.h" #include "FirmwarePlugin.h"
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QGCToolbox.h"
class QGCApplication;
/// FirmwarePluginManager is a singleton which is used to return the correct FirmwarePlugin for a MAV_AUTOPILOT type. /// FirmwarePluginManager is a singleton which is used to return the correct FirmwarePlugin for a MAV_AUTOPILOT type.
class FirmwarePluginManager : public QGCSingleton class FirmwarePluginManager : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(FirmwarePluginManager, FirmwarePluginManager)
public: public:
FirmwarePluginManager(QGCApplication* app) : QGCTool(app) { }
/// Returns appropriate plugin for autopilot type. /// Returns appropriate plugin for autopilot type.
/// @param autopilotType Type of autopilot to return plugin for. /// @param autopilotType Type of autopilot to return plugin for.
/// @param vehicleType Vehicle type of autopilot to return plugin for. /// @param vehicleType Vehicle type of autopilot to return plugin for.
/// @return Singleton FirmwarePlugin instance for the specified MAV_AUTOPILOT. /// @return Singleton FirmwarePlugin instance for the specified MAV_AUTOPILOT.
FirmwarePlugin* firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType); FirmwarePlugin* firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType);
private:
/// All access to singleton is through FirmwarePluginManager::instance
FirmwarePluginManager(QObject* parent = NULL);
~FirmwarePluginManager();
}; };
#endif #endif
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
IMPLEMENT_QGC_SINGLETON(GenericFirmwarePlugin, FirmwarePlugin) IMPLEMENT_QGC_SINGLETON(GenericFirmwarePlugin, FirmwarePlugin)
GenericFirmwarePlugin::GenericFirmwarePlugin(QObject* parent) GenericFirmwarePlugin::GenericFirmwarePlugin(void)
: FirmwarePlugin(parent)
{ {
} }
......
...@@ -51,8 +51,7 @@ public: ...@@ -51,8 +51,7 @@ public:
virtual QString getDefaultComponentIdParam(void) const { return QString(); } virtual QString getDefaultComponentIdParam(void) const { return QString(); }
private: private:
/// All access to singleton is through AutoPilotPluginManager::instance GenericFirmwarePlugin(void);
GenericFirmwarePlugin(QObject* parent = NULL);
}; };
#endif #endif
...@@ -88,8 +88,7 @@ static const struct Modes2Name rgModes2Name[] = { ...@@ -88,8 +88,7 @@ static const struct Modes2Name rgModes2Name[] = {
}; };
PX4FirmwarePlugin::PX4FirmwarePlugin(QObject* parent) PX4FirmwarePlugin::PX4FirmwarePlugin(void)
: FirmwarePlugin(parent)
{ {
} }
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
private: private:
/// All access to singleton is through AutoPilotPluginManager::instance /// All access to singleton is through AutoPilotPluginManager::instance
PX4FirmwarePlugin(QObject* parent = NULL); PX4FirmwarePlugin(void);
PX4ParameterMetaData _parameterMetaData; PX4ParameterMetaData _parameterMetaData;
}; };
......
...@@ -26,27 +26,26 @@ ...@@ -26,27 +26,26 @@
#include <QSettings> #include <QSettings>
#include <QtQml> #include <QtQml>
IMPLEMENT_QGC_SINGLETON(FlightMapSettings, FlightMapSettings)
const char* FlightMapSettings::_defaultMapProvider = "Bing"; // Bing is default since it support full street/satellite/hybrid set const char* FlightMapSettings::_defaultMapProvider = "Bing"; // Bing is default since it support full street/satellite/hybrid set
const char* FlightMapSettings::_settingsGroup = "FlightMapSettings"; const char* FlightMapSettings::_settingsGroup = "FlightMapSettings";
const char* FlightMapSettings::_mapProviderKey = "MapProvider"; const char* FlightMapSettings::_mapProviderKey = "MapProvider";
const char* FlightMapSettings::_mapTypeKey = "MapType"; const char* FlightMapSettings::_mapTypeKey = "MapType";
FlightMapSettings::FlightMapSettings(QObject* parent) FlightMapSettings::FlightMapSettings(QGCApplication* app)
: QObject(parent) : QGCTool(app)
, _mapProvider(_defaultMapProvider) , _mapProvider(_defaultMapProvider)
{ {
qmlRegisterUncreatableType<FlightMapSettings> ("QGroundControl", 1, 0, "FlightMapSetting", "Reference only");
_supportedMapProviders << "Bing" << "Google" << "Open";
_loadSettings();
} }
FlightMapSettings::~FlightMapSettings() void FlightMapSettings::setToolbox(QGCToolbox *toolbox)
{ {
QGCTool::setToolbox(toolbox);
qmlRegisterUncreatableType<FlightMapSettings> ("QGroundControl", 1, 0, "FlightMapSetting", "Reference only");
_supportedMapProviders << "Bing" << "Google" << "Open";
_loadSettings();
} }
void FlightMapSettings::_storeSettings(void) void FlightMapSettings::_storeSettings(void)
......
...@@ -24,17 +24,18 @@ This file is part of the QGROUNDCONTROL project ...@@ -24,17 +24,18 @@ This file is part of the QGROUNDCONTROL project
#ifndef FlightMapSettings_H #ifndef FlightMapSettings_H
#define FlightMapSettings_H #define FlightMapSettings_H
#include "QGCSingleton.h" #include "QGCToolbox.h"
#include <QObject>
#include <QStringList> #include <QStringList>
class FlightMapSettings : public QObject class FlightMapSettings : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(FlightMapSettings, FlightMapSettings)
public: public:
FlightMapSettings(QGCApplication* app);
/// mapProvider is either Bing, Google or Open to specify to set of maps available /// mapProvider is either Bing, Google or Open to specify to set of maps available
Q_PROPERTY(QString mapProvider READ mapProvider WRITE setMapProvider NOTIFY mapProviderChanged) Q_PROPERTY(QString mapProvider READ mapProvider WRITE setMapProvider NOTIFY mapProviderChanged)
...@@ -54,15 +55,14 @@ public: ...@@ -54,15 +55,14 @@ public:
QString mapProvider(void); QString mapProvider(void);
void setMapProvider(const QString& mapProvider); void setMapProvider(const QString& mapProvider);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
signals: signals:
void mapProviderChanged(const QString& mapProvider); void mapProviderChanged(const QString& mapProvider);
void mapTypesChanged(const QStringList& mapTypes); void mapTypesChanged(const QStringList& mapTypes);
private: private:
/// @brief All access to FlightMapSettings singleton is through FlightMapSettings::instance
FlightMapSettings(QObject* parent = NULL);
~FlightMapSettings();
void _storeSettings(void); void _storeSettings(void);
void _loadSettings(void); void _loadSettings(void);
......
...@@ -43,12 +43,10 @@ This file is part of the QGROUNDCONTROL project ...@@ -43,12 +43,10 @@ This file is part of the QGROUNDCONTROL project
#include <QtAndroidExtras/QAndroidJniObject> #include <QtAndroidExtras/QAndroidJniObject>
#endif #endif
IMPLEMENT_QGC_SINGLETON(GAudioOutput, GAudioOutput)
const char* GAudioOutput::_mutedKey = "AudioMuted"; const char* GAudioOutput::_mutedKey = "AudioMuted";
GAudioOutput::GAudioOutput(QObject *parent) GAudioOutput::GAudioOutput(QGCApplication* app)
: QGCSingleton(parent) : QGCTool(app)
, muted(false) , muted(false)
#ifndef __android__ #ifndef __android__
, thread(new QThread()) , thread(new QThread())
...@@ -57,7 +55,7 @@ GAudioOutput::GAudioOutput(QObject *parent) ...@@ -57,7 +55,7 @@ GAudioOutput::GAudioOutput(QObject *parent)
{ {
QSettings settings; QSettings settings;
muted = settings.value(_mutedKey, false).toBool(); muted = settings.value(_mutedKey, false).toBool();
muted |= qgcApp()->runningUnitTests(); muted |= app->runningUnitTests();
#ifndef __android__ #ifndef __android__
worker->moveToThread(thread); worker->moveToThread(thread);
connect(this, &GAudioOutput::textToSpeak, worker, &QGCAudioWorker::say); connect(this, &GAudioOutput::textToSpeak, worker, &QGCAudioWorker::say);
......
...@@ -38,20 +38,23 @@ This file is part of the PIXHAWK project ...@@ -38,20 +38,23 @@ This file is part of the PIXHAWK project
#include <QStringList> #include <QStringList>
#include "QGCAudioWorker.h" #include "QGCAudioWorker.h"
#include "QGCSingleton.h" #include "QGCToolbox.h"
class QGCApplication;
/** /**
* @brief Audio Output (speech synthesizer and "beep" output) * @brief Audio Output (speech synthesizer and "beep" output)
* This class follows the singleton design pattern * This class follows the singleton design pattern
* @see http://en.wikipedia.org/wiki/Singleton_pattern * @see http://en.wikipedia.org/wiki/Singleton_pattern
*/ */
class GAudioOutput : public QGCSingleton class GAudioOutput : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(GAudioOutput, GAudioOutput)
public: public:
GAudioOutput(QGCApplication* app);
~GAudioOutput();
/** @brief List available voices */ /** @brief List available voices */
QStringList listVoices(void); QStringList listVoices(void);
enum enum
...@@ -95,9 +98,6 @@ protected: ...@@ -95,9 +98,6 @@ protected:
#endif #endif
private: private:
GAudioOutput(QObject *parent = NULL);
~GAudioOutput();
static const char* _mutedKey; static const char* _mutedKey;
}; };
......
...@@ -39,27 +39,27 @@ ...@@ -39,27 +39,27 @@
#define MEAN_EARTH_DIAMETER 12756274.0 #define MEAN_EARTH_DIAMETER 12756274.0
#define UMR 0.017453292519943295769236907684886 #define UMR 0.017453292519943295769236907684886
IMPLEMENT_QGC_SINGLETON(HomePositionManager, HomePositionManager)
const char* HomePositionManager::_settingsGroup = "HomePositionManager"; const char* HomePositionManager::_settingsGroup = "HomePositionManager";
const char* HomePositionManager::_latitudeKey = "Latitude"; const char* HomePositionManager::_latitudeKey = "Latitude";
const char* HomePositionManager::_longitudeKey = "Longitude"; const char* HomePositionManager::_longitudeKey = "Longitude";
const char* HomePositionManager::_altitudeKey = "Altitude"; const char* HomePositionManager::_altitudeKey = "Altitude";
HomePositionManager::HomePositionManager(QObject* parent) HomePositionManager::HomePositionManager(QGCApplication* app)
: QObject(parent) : QGCTool(app)
, homeLat(47.3769) , homeLat(47.3769)
, homeLon(8.549444) , homeLon(8.549444)
, homeAlt(470.0) , homeAlt(470.0)
{ {
qmlRegisterUncreatableType<HomePositionManager> ("QGroundControl", 1, 0, "HomePositionManager", "Reference only");
_loadSettings();
} }
HomePositionManager::~HomePositionManager() void HomePositionManager::setToolbox(QGCToolbox *toolbox)
{ {
QGCTool::setToolbox(toolbox);
qmlRegisterUncreatableType<HomePositionManager> ("QGroundControl", 1, 0, "HomePositionManager", "Reference only");
_loadSettings();
} }
void HomePositionManager::_storeSettings(void) void HomePositionManager::_storeSettings(void)
...@@ -116,7 +116,7 @@ void HomePositionManager::_loadSettings(void) ...@@ -116,7 +116,7 @@ void HomePositionManager::_loadSettings(void)
settings.endGroup(); settings.endGroup();
if (_homePositions.count() == 0) { if (_homePositions.count() == 0) {
_homePositions.append(new HomePosition("ETH Campus", QGeoCoordinate(47.3769, 8.549444, 470.0))); _homePositions.append(new HomePosition("ETH Campus", QGeoCoordinate(47.3769, 8.549444, 470.0), this));
} }
// Deprecated settings for old editor // Deprecated settings for old editor
...@@ -169,7 +169,7 @@ bool HomePositionManager::setHomePositionAndNotify(double lat, double lon, doubl ...@@ -169,7 +169,7 @@ bool HomePositionManager::setHomePositionAndNotify(double lat, double lon, doubl
bool changed = setHomePosition(lat, lon, alt); bool changed = setHomePosition(lat, lon, alt);
if (changed) { if (changed) {
MultiVehicleManager::instance()->setHomePositionForAllVehicles(homeLat, homeLon, homeAlt); qgcApp()->toolbox()->multiVehicleManager()->setHomePositionForAllVehicles(homeLat, homeLon, homeAlt);
} }
return changed; return changed;
...@@ -218,9 +218,10 @@ void HomePositionManager::deleteHomePosition(const QString& name) ...@@ -218,9 +218,10 @@ void HomePositionManager::deleteHomePosition(const QString& name)
_storeSettings(); _storeSettings();
} }
HomePosition::HomePosition(const QString& name, const QGeoCoordinate& coordinate, QObject* parent) HomePosition::HomePosition(const QString& name, const QGeoCoordinate& coordinate, HomePositionManager* homePositionManager, QObject* parent)
: QObject(parent) : QObject(parent)
, _coordinate(coordinate) , _coordinate(coordinate)
, _homePositionManager(homePositionManager)
{ {
setObjectName(name); setObjectName(name);
} }
...@@ -238,7 +239,7 @@ QString HomePosition::name(void) ...@@ -238,7 +239,7 @@ QString HomePosition::name(void)
void HomePosition::setName(const QString& name) void HomePosition::setName(const QString& name)
{ {
setObjectName(name); setObjectName(name);
HomePositionManager::instance()->_storeSettings(); _homePositionManager->_storeSettings();
emit nameChanged(name); emit nameChanged(name);
} }
...@@ -250,6 +251,6 @@ QGeoCoordinate HomePosition::coordinate(void) ...@@ -250,6 +251,6 @@ QGeoCoordinate HomePosition::coordinate(void)
void HomePosition::setCoordinate(const QGeoCoordinate& coordinate) void HomePosition::setCoordinate(const QGeoCoordinate& coordinate)
{ {
_coordinate = coordinate; _coordinate = coordinate;
HomePositionManager::instance()->_storeSettings(); _homePositionManager->_storeSettings();
emit coordinateChanged(coordinate); emit coordinateChanged(coordinate);
} }
...@@ -24,17 +24,19 @@ This file is part of the QGROUNDCONTROL project ...@@ -24,17 +24,19 @@ This file is part of the QGROUNDCONTROL project
#ifndef HomePositionManager_H #ifndef HomePositionManager_H
#define HomePositionManager_H #define HomePositionManager_H
#include "QGCSingleton.h"
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "QGCToolbox.h"
#include <QGeoCoordinate> #include <QGeoCoordinate>
class HomePositionManager;
class HomePosition : public QObject class HomePosition : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
HomePosition(const QString& name, const QGeoCoordinate& coordinate, QObject* parent = NULL); HomePosition(const QString& name, const QGeoCoordinate& coordinate, HomePositionManager* homePositionManager, QObject* parent = NULL);
~HomePosition(); ~HomePosition();
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
...@@ -47,22 +49,23 @@ public: ...@@ -47,22 +49,23 @@ public:
QGeoCoordinate coordinate(void); QGeoCoordinate coordinate(void);
void setCoordinate(const QGeoCoordinate& coordinate); void setCoordinate(const QGeoCoordinate& coordinate);
signals: signals:
void nameChanged(const QString& name); void nameChanged(const QString& name);
void coordinateChanged(const QGeoCoordinate& coordinate); void coordinateChanged(const QGeoCoordinate& coordinate);
private: private:
QGeoCoordinate _coordinate; QGeoCoordinate _coordinate;
HomePositionManager* _homePositionManager;
}; };
class HomePositionManager : public QObject class HomePositionManager : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(HomePositionManager, HomePositionManager)
public: public:
HomePositionManager(QGCApplication* app);
Q_PROPERTY(QmlObjectListModel* homePositions READ homePositions CONSTANT) Q_PROPERTY(QmlObjectListModel* homePositions READ homePositions CONSTANT)
/// If name is not already a home position a new one will be added, otherwise the existing /// If name is not already a home position a new one will be added, otherwise the existing
...@@ -78,14 +81,13 @@ public: ...@@ -78,14 +81,13 @@ public:
// Should only be called by HomePosition // Should only be called by HomePosition
void _storeSettings(void); void _storeSettings(void);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
private: private:
/// @brief All access to HomePositionManager singleton is through HomePositionManager::instance
HomePositionManager(QObject* parent = NULL);
~HomePositionManager();
void _loadSettings(void); void _loadSettings(void);
QmlObjectListModel _homePositions; QmlObjectListModel _homePositions;
static const char* _settingsGroup; static const char* _settingsGroup;
static const char* _latitudeKey; static const char* _latitudeKey;
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "Joystick.h" #include "Joystick.h"
#include "QGC.h" #include "QGC.h"
#include "MultiVehicleManager.h"
#include "AutoPilotPlugin.h" #include "AutoPilotPlugin.h"
#include "UAS.h" #include "UAS.h"
...@@ -52,7 +51,7 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = { ...@@ -52,7 +51,7 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"ThrottleAxis" "ThrottleAxis"
}; };
Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlIndex) Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlIndex, MultiVehicleManager* multiVehicleManager)
#ifndef __mobile__ #ifndef __mobile__
: _sdlIndex(sdlIndex) : _sdlIndex(sdlIndex)
, _exitThread(false) , _exitThread(false)
...@@ -68,6 +67,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI ...@@ -68,6 +67,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
, _throttleMode(ThrottleModeCenterZero) , _throttleMode(ThrottleModeCenterZero)
, _activeVehicle(NULL) , _activeVehicle(NULL)
, _pollingStartedForCalibration(false) , _pollingStartedForCalibration(false)
, _multiVehicleManager(multiVehicleManager)
#endif // __mobile__ #endif // __mobile__
{ {
#ifdef __mobile__ #ifdef __mobile__
...@@ -520,7 +520,7 @@ void Joystick::startCalibrationMode(CalibrationMode_t mode) ...@@ -520,7 +520,7 @@ void Joystick::startCalibrationMode(CalibrationMode_t mode)
if (!isRunning()) { if (!isRunning()) {
_pollingStartedForCalibration = true; _pollingStartedForCalibration = true;
startPolling(MultiVehicleManager::instance()->activeVehicle()); startPolling(_multiVehicleManager->activeVehicle());
} }
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "MultiVehicleManager.h"
Q_DECLARE_LOGGING_CATEGORY(JoystickLog) Q_DECLARE_LOGGING_CATEGORY(JoystickLog)
Q_DECLARE_LOGGING_CATEGORY(JoystickValuesLog) Q_DECLARE_LOGGING_CATEGORY(JoystickValuesLog)
...@@ -38,7 +39,7 @@ class Joystick : public QThread ...@@ -38,7 +39,7 @@ class Joystick : public QThread
Q_OBJECT Q_OBJECT
public: public:
Joystick(const QString& name, int axisCount, int buttonCount, int sdlIndex); Joystick(const QString& name, int axisCount, int buttonCount, int sdlIndex, MultiVehicleManager* multiVehicleManager);
~Joystick(); ~Joystick();
typedef struct { typedef struct {
...@@ -171,6 +172,8 @@ private: ...@@ -171,6 +172,8 @@ private:
Vehicle* _activeVehicle; Vehicle* _activeVehicle;
bool _pollingStartedForCalibration; bool _pollingStartedForCalibration;
MultiVehicleManager* _multiVehicleManager;
#endif // __mobile__ #endif // __mobile__
private: private:
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
======================================================================*/ ======================================================================*/
#include "JoystickManager.h" #include "JoystickManager.h"
#include "QGCApplication.h"
#include <QQmlEngine> #include <QQmlEngine>
...@@ -35,58 +36,62 @@ ...@@ -35,58 +36,62 @@
QGC_LOGGING_CATEGORY(JoystickManagerLog, "JoystickManagerLog") QGC_LOGGING_CATEGORY(JoystickManagerLog, "JoystickManagerLog")
IMPLEMENT_QGC_SINGLETON(JoystickManager, JoystickManager)
const char * JoystickManager::_settingsGroup = "JoystickManager"; const char * JoystickManager::_settingsGroup = "JoystickManager";
const char * JoystickManager::_settingsKeyActiveJoystick = "ActiveJoystick"; const char * JoystickManager::_settingsKeyActiveJoystick = "ActiveJoystick";
JoystickManager::JoystickManager(QObject* parent) JoystickManager::JoystickManager(QGCApplication* app)
: QGCSingleton(parent) : QGCTool(app)
, _activeJoystick(NULL) , _activeJoystick(NULL)
, _multiVehicleManager(NULL)
{ {
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
}
void JoystickManager::setToolbox(QGCToolbox *toolbox)
{
QGCTool::setToolbox(toolbox);
_multiVehicleManager = _toolbox->multiVehicleManager();
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
#ifndef __mobile__ #ifndef __mobile__
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) { if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0) {
qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError(); qWarning() << "Couldn't initialize SimpleDirectMediaLayer:" << SDL_GetError();
return; return;
} }
// Load available joysticks // Load available joysticks
qCDebug(JoystickManagerLog) << "Available joysticks"; qCDebug(JoystickManagerLog) << "Available joysticks";
for (int i=0; i<SDL_NumJoysticks(); i++) { for (int i=0; i<SDL_NumJoysticks(); i++) {
QString name = SDL_JoystickName(i); QString name = SDL_JoystickName(i);
if (!_name2JoystickMap.contains(name)) { if (!_name2JoystickMap.contains(name)) {
int axisCount, buttonCount; int axisCount, buttonCount;
SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i); SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i);
axisCount = SDL_JoystickNumAxes(sdlJoystick); axisCount = SDL_JoystickNumAxes(sdlJoystick);
buttonCount = SDL_JoystickNumButtons(sdlJoystick); buttonCount = SDL_JoystickNumButtons(sdlJoystick);
SDL_JoystickClose(sdlJoystick); SDL_JoystickClose(sdlJoystick);
qCDebug(JoystickManagerLog) << "\t" << name << "axes:" << axisCount << "buttons:" << buttonCount; qCDebug(JoystickManagerLog) << "\t" << name << "axes:" << axisCount << "buttons:" << buttonCount;
_name2JoystickMap[name] = new Joystick(name, axisCount, buttonCount, i); _name2JoystickMap[name] = new Joystick(name, axisCount, buttonCount, i, _multiVehicleManager);
} else { } else {
qCDebug(JoystickManagerLog) << "\tSkipping duplicate" << name; qCDebug(JoystickManagerLog) << "\tSkipping duplicate" << name;
} }
} }
#endif #endif
if (!_name2JoystickMap.count()) { if (!_name2JoystickMap.count()) {
qCDebug(JoystickManagerLog) << "\tnone found"; qCDebug(JoystickManagerLog) << "\tnone found";
return; return;
} }
_setActiveJoystickFromSettings(); _setActiveJoystickFromSettings();
} }
JoystickManager::~JoystickManager()
{
}
void JoystickManager::_setActiveJoystickFromSettings(void) void JoystickManager::_setActiveJoystickFromSettings(void)
{ {
......
...@@ -24,21 +24,24 @@ ...@@ -24,21 +24,24 @@
#ifndef JoystickManager_H #ifndef JoystickManager_H
#define JoystickManager_H #define JoystickManager_H
#include "QGCSingleton.h"
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "Joystick.h" #include "Joystick.h"
#include "MultiVehicleManager.h"
#include "QGCToolbox.h"
#include <QVariantList> #include <QVariantList>
Q_DECLARE_LOGGING_CATEGORY(JoystickManagerLog) Q_DECLARE_LOGGING_CATEGORY(JoystickManagerLog)
class JoystickManager : public QGCSingleton class QGCApplicaiton;
class JoystickManager : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(JoystickManager, JoystickManager)
public: public:
JoystickManager(QGCApplication* app);
/// List of available joysticks /// List of available joysticks
Q_PROPERTY(QVariantList joysticks READ joysticks CONSTANT) Q_PROPERTY(QVariantList joysticks READ joysticks CONSTANT)
Q_PROPERTY(QStringList joystickNames READ joystickNames CONSTANT) Q_PROPERTY(QStringList joystickNames READ joystickNames CONSTANT)
...@@ -56,6 +59,9 @@ public: ...@@ -56,6 +59,9 @@ public:
QString activeJoystickName(void); QString activeJoystickName(void);
void setActiveJoystickName(const QString& name); void setActiveJoystickName(const QString& name);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
signals: signals:
void activeJoystickChanged(Joystick* joystick); void activeJoystickChanged(Joystick* joystick);
void activeJoystickNameChanged(const QString& name); void activeJoystickNameChanged(const QString& name);
...@@ -63,16 +69,12 @@ signals: ...@@ -63,16 +69,12 @@ signals:
private slots: private slots:
private: private:
/// All access to singleton is through JoystickManager::instance
JoystickManager(QObject* parent = NULL);
~JoystickManager();
void _setActiveJoystickFromSettings(void); void _setActiveJoystickFromSettings(void);
private: private:
Joystick* _activeJoystick; Joystick* _activeJoystick;
QMap<QString, Joystick*> _name2JoystickMap; QMap<QString, Joystick*> _name2JoystickMap;
MultiVehicleManager* _multiVehicleManager;
static const char * _settingsGroup; static const char * _settingsGroup;
static const char * _settingsKeyActiveJoystick; static const char * _settingsKeyActiveJoystick;
......
...@@ -62,7 +62,7 @@ void MissionController::start(bool editMode) ...@@ -62,7 +62,7 @@ void MissionController::start(bool editMode)
_editMode = editMode; _editMode = editMode;
MultiVehicleManager* multiVehicleMgr = MultiVehicleManager::instance(); MultiVehicleManager* multiVehicleMgr = qgcApp()->toolbox()->multiVehicleManager();
connect(multiVehicleMgr, &MultiVehicleManager::activeVehicleChanged, this, &MissionController::_activeVehicleChanged); connect(multiVehicleMgr, &MultiVehicleManager::activeVehicleChanged, this, &MissionController::_activeVehicleChanged);
...@@ -143,7 +143,7 @@ void MissionController::_setupMissionItems(bool loadFromVehicle, bool forceLoad) ...@@ -143,7 +143,7 @@ void MissionController::_setupMissionItems(bool loadFromVehicle, bool forceLoad)
void MissionController::getMissionItems(void) void MissionController::getMissionItems(void)
{ {
Vehicle* activeVehicle = MultiVehicleManager::instance()->activeVehicle(); Vehicle* activeVehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
if (activeVehicle) { if (activeVehicle) {
_missionItemsRequested = true; _missionItemsRequested = true;
...@@ -153,7 +153,7 @@ void MissionController::getMissionItems(void) ...@@ -153,7 +153,7 @@ void MissionController::getMissionItems(void)
void MissionController::sendMissionItems(void) void MissionController::sendMissionItems(void)
{ {
Vehicle* activeVehicle = MultiVehicleManager::instance()->activeVehicle(); Vehicle* activeVehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
if (activeVehicle) { if (activeVehicle) {
activeVehicle->missionManager()->writeMissionItems(*_missionItems); activeVehicle->missionManager()->writeMissionItems(*_missionItems);
...@@ -576,7 +576,7 @@ void MissionController::setAutoSync(bool autoSync) ...@@ -576,7 +576,7 @@ void MissionController::setAutoSync(bool autoSync)
void MissionController::_dirtyChanged(bool dirty) void MissionController::_dirtyChanged(bool dirty)
{ {
if (dirty && _autoSync) { if (dirty && _autoSync) {
Vehicle* activeVehicle = MultiVehicleManager::instance()->activeVehicle(); Vehicle* activeVehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
if (activeVehicle && !activeVehicle->armed()) { if (activeVehicle && !activeVehicle->armed()) {
if (_activeVehicle->missionManager()->inProgress()) { if (_activeVehicle->missionManager()->inProgress()) {
......
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
#include "MissionControllerManagerTest.h" #include "MissionControllerManagerTest.h"
#include "LinkManager.h" #include "LinkManager.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "QGCApplication.h"
MissionControllerManagerTest::MissionControllerManagerTest(void) MissionControllerManagerTest::MissionControllerManagerTest(void)
: _mockLink(NULL)
{ {
} }
...@@ -36,33 +36,16 @@ void MissionControllerManagerTest::cleanup(void) ...@@ -36,33 +36,16 @@ void MissionControllerManagerTest::cleanup(void)
delete _multiSpyMissionManager; delete _multiSpyMissionManager;
_multiSpyMissionManager = NULL; _multiSpyMissionManager = NULL;
LinkManager::instance()->disconnectLink(_mockLink);
_mockLink = NULL;
QTest::qWait(1000); // Need to allow signals to move between threads
UnitTest::cleanup(); UnitTest::cleanup();
} }
void MissionControllerManagerTest::_initForFirmwareType(MAV_AUTOPILOT firmwareType) void MissionControllerManagerTest::_initForFirmwareType(MAV_AUTOPILOT firmwareType)
{ {
LinkManager* linkMgr = LinkManager::instance(); _connectMockLink(firmwareType);
Q_CHECK_PTR(linkMgr);
_mockLink = new MockLink();
Q_CHECK_PTR(_mockLink);
_mockLink->setFirmwareType(firmwareType);
LinkManager::instance()->_addLink(_mockLink);
linkMgr->connectLink(_mockLink);
// Wait for the Vehicle to work it's way through the various threads
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(activeVehicleChanged(Vehicle*)));
QCOMPARE(spyVehicle.wait(5000), true);
// Wait for the Mission Manager to finish it's initial load // Wait for the Mission Manager to finish it's initial load
_missionManager = MultiVehicleManager::instance()->activeVehicle()->missionManager(); _missionManager = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->missionManager();
QVERIFY(_missionManager); QVERIFY(_missionManager);
_rgMissionManagerSignals[canEditChangedSignalIndex] = SIGNAL(canEditChanged(bool)); _rgMissionManagerSignals[canEditChangedSignalIndex] = SIGNAL(canEditChanged(bool));
......
...@@ -46,7 +46,6 @@ protected: ...@@ -46,7 +46,6 @@ protected:
void _initForFirmwareType(MAV_AUTOPILOT firmwareType); void _initForFirmwareType(MAV_AUTOPILOT firmwareType);
void _checkInProgressValues(bool inProgress); void _checkInProgressValues(bool inProgress);
MockLink* _mockLink;
MissionManager* _missionManager; MissionManager* _missionManager;
typedef struct { typedef struct {
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "Vehicle.h" #include "Vehicle.h"
#include "FirmwarePlugin.h" #include "FirmwarePlugin.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "QGCApplication.h"
QGC_LOGGING_CATEGORY(MissionManagerLog, "MissionManagerLog") QGC_LOGGING_CATEGORY(MissionManagerLog, "MissionManagerLog")
...@@ -92,7 +93,7 @@ void MissionManager::writeMissionItems(const QmlObjectListModel& missionItems) ...@@ -92,7 +93,7 @@ void MissionManager::writeMissionItems(const QmlObjectListModel& missionItems)
missionCount.target_component = MAV_COMP_ID_MISSIONPLANNER; missionCount.target_component = MAV_COMP_ID_MISSIONPLANNER;
missionCount.count = _missionItems.count(); missionCount.count = _missionItems.count();
mavlink_msg_mission_count_encode(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::instance()->getComponentId(), &message, &missionCount); mavlink_msg_mission_count_encode(qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), &message, &missionCount);
_vehicle->sendMessage(message); _vehicle->sendMessage(message);
_startAckTimeout(AckMissionRequest); _startAckTimeout(AckMissionRequest);
...@@ -112,7 +113,7 @@ void MissionManager::_retryWrite(void) ...@@ -112,7 +113,7 @@ void MissionManager::_retryWrite(void)
missionCount.target_component = MAV_COMP_ID_MISSIONPLANNER; missionCount.target_component = MAV_COMP_ID_MISSIONPLANNER;
missionCount.count = _missionItems.count(); missionCount.count = _missionItems.count();
mavlink_msg_mission_count_encode(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::instance()->getComponentId(), &message, &missionCount); mavlink_msg_mission_count_encode(qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), &message, &missionCount);
_vehicle->sendMessage(message); _vehicle->sendMessage(message);
_startAckTimeout(AckMissionRequest); _startAckTimeout(AckMissionRequest);
...@@ -131,7 +132,7 @@ void MissionManager::requestMissionItems(void) ...@@ -131,7 +132,7 @@ void MissionManager::requestMissionItems(void)
request.target_system = _vehicle->id(); request.target_system = _vehicle->id();
request.target_component = MAV_COMP_ID_MISSIONPLANNER; request.target_component = MAV_COMP_ID_MISSIONPLANNER;
mavlink_msg_mission_request_list_encode(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::instance()->getComponentId(), &message, &request); mavlink_msg_mission_request_list_encode(qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), &message, &request);
_vehicle->sendMessage(message); _vehicle->sendMessage(message);
_startAckTimeout(AckMissionCount); _startAckTimeout(AckMissionCount);
...@@ -150,7 +151,7 @@ void MissionManager::_retryRead(void) ...@@ -150,7 +151,7 @@ void MissionManager::_retryRead(void)
request.target_system = _vehicle->id(); request.target_system = _vehicle->id();
request.target_component = MAV_COMP_ID_MISSIONPLANNER; request.target_component = MAV_COMP_ID_MISSIONPLANNER;
mavlink_msg_mission_request_list_encode(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::instance()->getComponentId(), &message, &request); mavlink_msg_mission_request_list_encode(qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), &message, &request);
_vehicle->sendMessage(message); _vehicle->sendMessage(message);
_startAckTimeout(AckMissionCount); _startAckTimeout(AckMissionCount);
...@@ -214,7 +215,7 @@ void MissionManager::_readTransactionComplete(void) ...@@ -214,7 +215,7 @@ void MissionManager::_readTransactionComplete(void)
missionAck.target_component = MAV_COMP_ID_MISSIONPLANNER; missionAck.target_component = MAV_COMP_ID_MISSIONPLANNER;
missionAck.type = MAV_MISSION_ACCEPTED; missionAck.type = MAV_MISSION_ACCEPTED;
mavlink_msg_mission_ack_encode(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::instance()->getComponentId(), &message, &missionAck); mavlink_msg_mission_ack_encode(qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), &message, &missionAck);
_vehicle->sendMessage(message); _vehicle->sendMessage(message);
...@@ -260,7 +261,7 @@ void MissionManager::_requestNextMissionItem(int sequenceNumber) ...@@ -260,7 +261,7 @@ void MissionManager::_requestNextMissionItem(int sequenceNumber)
missionRequest.seq = sequenceNumber; missionRequest.seq = sequenceNumber;
_expectedSequenceNumber = sequenceNumber; _expectedSequenceNumber = sequenceNumber;
mavlink_msg_mission_request_encode(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::instance()->getComponentId(), &message, &missionRequest); mavlink_msg_mission_request_encode(qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), &message, &missionRequest);
_vehicle->sendMessage(message); _vehicle->sendMessage(message);
_startAckTimeout(AckMissionItem); _startAckTimeout(AckMissionItem);
...@@ -361,7 +362,7 @@ void MissionManager::_handleMissionRequest(const mavlink_message_t& message) ...@@ -361,7 +362,7 @@ void MissionManager::_handleMissionRequest(const mavlink_message_t& message)
missionItem.current = missionRequest.seq == 0; missionItem.current = missionRequest.seq == 0;
missionItem.autocontinue = item->autoContinue(); missionItem.autocontinue = item->autoContinue();
mavlink_msg_mission_item_encode(MAVLinkProtocol::instance()->getSystemId(), MAVLinkProtocol::instance()->getComponentId(), &messageOut, &missionItem); mavlink_msg_mission_item_encode(qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), &messageOut, &missionItem);
_vehicle->sendMessage(messageOut); _vehicle->sendMessage(messageOut);
_startAckTimeout(AckMissionRequest); _startAckTimeout(AckMissionRequest);
......
...@@ -137,7 +137,7 @@ static QObject* mavlinkQmlSingletonFactory(QQmlEngine*, QJSEngine*) ...@@ -137,7 +137,7 @@ static QObject* mavlinkQmlSingletonFactory(QQmlEngine*, QJSEngine*)
static QObject* qgroundcontrolQmlGlobalSingletonFactory(QQmlEngine*, QJSEngine*) static QObject* qgroundcontrolQmlGlobalSingletonFactory(QQmlEngine*, QJSEngine*)
{ {
return new QGroundControlQmlGlobal; return new QGroundControlQmlGlobal(qgcApp()->toolbox());
} }
#if defined(QGC_GST_STREAMING) #if defined(QGC_GST_STREAMING)
...@@ -172,6 +172,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -172,6 +172,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
#ifdef QT_DEBUG #ifdef QT_DEBUG
, _testHighDPI(false) , _testHighDPI(false)
#endif #endif
, _toolbox(NULL)
{ {
Q_ASSERT(_app == NULL); Q_ASSERT(_app == NULL);
_app = this; _app = this;
...@@ -315,12 +316,15 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -315,12 +316,15 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
// Initialize Video Streaming // Initialize Video Streaming
initializeVideoStreaming(argc, argv); initializeVideoStreaming(argc, argv);
_toolbox = new QGCToolbox(this);
} }
QGCApplication::~QGCApplication() QGCApplication::~QGCApplication()
{ {
_destroySingletons(); _destroySingletons();
shutdownVideoStreaming(); shutdownVideoStreaming();
delete _toolbox;
} }
void QGCApplication::_initCommon(void) void QGCApplication::_initCommon(void)
...@@ -458,12 +462,12 @@ bool QGCApplication::_initForNormalAppBoot(void) ...@@ -458,12 +462,12 @@ bool QGCApplication::_initForNormalAppBoot(void)
#ifndef __mobile__ #ifndef __mobile__
// Now that main window is up check for lost log files // Now that main window is up check for lost log files
connect(this, &QGCApplication::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles); connect(this, &QGCApplication::checkForLostLogFiles, toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles(); emit checkForLostLogFiles();
#endif #endif
// Load known link configurations // Load known link configurations
LinkManager::instance()->loadLinkConfigurationList(); toolbox()->linkManager()->loadLinkConfigurationList();
return true; return true;
} }
...@@ -574,18 +578,6 @@ QGCApplication* qgcApp(void) ...@@ -574,18 +578,6 @@ QGCApplication* qgcApp(void)
/// up being creating on something other than the main thread. /// up being creating on something other than the main thread.
void QGCApplication::_createSingletons(void) void QGCApplication::_createSingletons(void)
{ {
// The order here is important since the singletons reference each other
// No dependencies
FlightMapSettings* flightMapSettings = FlightMapSettings::_createSingleton();
Q_UNUSED(flightMapSettings);
Q_ASSERT(flightMapSettings);
// No dependencies
HomePositionManager* homePositionManager = HomePositionManager::_createSingleton();
Q_UNUSED(homePositionManager);
Q_ASSERT(homePositionManager);
// No dependencies // No dependencies
FirmwarePlugin* firmwarePlugin = GenericFirmwarePlugin::_createSingleton(); FirmwarePlugin* firmwarePlugin = GenericFirmwarePlugin::_createSingleton();
Q_UNUSED(firmwarePlugin); Q_UNUSED(firmwarePlugin);
...@@ -596,52 +588,6 @@ void QGCApplication::_createSingletons(void) ...@@ -596,52 +588,6 @@ void QGCApplication::_createSingletons(void)
firmwarePlugin = ArduCopterFirmwarePlugin::_createSingleton(); firmwarePlugin = ArduCopterFirmwarePlugin::_createSingleton();
firmwarePlugin = ArduPlaneFirmwarePlugin::_createSingleton(); firmwarePlugin = ArduPlaneFirmwarePlugin::_createSingleton();
firmwarePlugin = ArduRoverFirmwarePlugin::_createSingleton(); firmwarePlugin = ArduRoverFirmwarePlugin::_createSingleton();
// No dependencies
FirmwarePluginManager* firmwarePluginManager = FirmwarePluginManager::_createSingleton();
Q_UNUSED(firmwarePluginManager);
Q_ASSERT(firmwarePluginManager);
// No dependencies
MultiVehicleManager* multiVehicleManager = MultiVehicleManager::_createSingleton();
Q_UNUSED(multiVehicleManager);
Q_ASSERT(multiVehicleManager);
// No dependencies
JoystickManager* joystickManager = JoystickManager::_createSingleton();
Q_UNUSED(joystickManager);
Q_ASSERT(joystickManager);
// No dependencies
GAudioOutput* audio = GAudioOutput::_createSingleton();
Q_UNUSED(audio);
Q_ASSERT(audio);
// No dependencies
LinkManager* linkManager = LinkManager::_createSingleton();
Q_UNUSED(linkManager);
Q_ASSERT(linkManager);
// Need MultiVehicleManager
AutoPilotPluginManager* pluginManager = AutoPilotPluginManager::_createSingleton();
Q_UNUSED(pluginManager);
Q_ASSERT(pluginManager);
// Need MultiVehicleManager
UASMessageHandler* messageHandler = UASMessageHandler::_createSingleton();
Q_UNUSED(messageHandler);
Q_ASSERT(messageHandler);
// Needs MultiVehicleManager
FactSystem* factSystem = FactSystem::_createSingleton();
Q_UNUSED(factSystem);
Q_ASSERT(factSystem);
// Needs everything!
MAVLinkProtocol* mavlink = MAVLinkProtocol::_createSingleton();
Q_UNUSED(mavlink);
Q_ASSERT(mavlink);
} }
void QGCApplication::_destroySingletons(void) void QGCApplication::_destroySingletons(void)
...@@ -651,32 +597,11 @@ void QGCApplication::_destroySingletons(void) ...@@ -651,32 +597,11 @@ void QGCApplication::_destroySingletons(void)
delete mainWindow; delete mainWindow;
} }
if (LinkManager::instance(true /* nullOk */)) {
// This will close/delete all connections
LinkManager::instance()->_shutdown();
}
// Let the signals flow through the main thread
processEvents(QEventLoop::ExcludeUserInputEvents);
// Take down singletons in reverse order of creation
MAVLinkProtocol::_deleteSingleton();
FactSystem::_deleteSingleton();
UASMessageHandler::_deleteSingleton();
AutoPilotPluginManager::_deleteSingleton();
LinkManager::_deleteSingleton();
GAudioOutput::_deleteSingleton();
JoystickManager::_deleteSingleton();
MultiVehicleManager::_deleteSingleton();
FirmwarePluginManager::_deleteSingleton();
GenericFirmwarePlugin::_deleteSingleton(); GenericFirmwarePlugin::_deleteSingleton();
PX4FirmwarePlugin::_deleteSingleton(); PX4FirmwarePlugin::_deleteSingleton();
ArduCopterFirmwarePlugin::_deleteSingleton(); ArduCopterFirmwarePlugin::_deleteSingleton();
ArduPlaneFirmwarePlugin::_deleteSingleton(); ArduPlaneFirmwarePlugin::_deleteSingleton();
ArduRoverFirmwarePlugin::_deleteSingleton(); ArduRoverFirmwarePlugin::_deleteSingleton();
HomePositionManager::_deleteSingleton();
FlightMapSettings::_deleteSingleton();
} }
void QGCApplication::informationMessageBoxOnMainThread(const QString& title, const QString& msg) void QGCApplication::informationMessageBoxOnMainThread(const QString& title, const QString& msg)
......
...@@ -36,6 +36,17 @@ ...@@ -36,6 +36,17 @@
#include <QTimer> #include <QTimer>
#include "LinkConfiguration.h" #include "LinkConfiguration.h"
#include "LinkManager.h"
#include "MAVLinkProtocol.h"
#include "FlightMapSettings.h"
#include "HomePositionManager.h"
#include "FirmwarePluginManager.h"
#include "MultiVehicleManager.h"
#include "JoystickManager.h"
#include "GAudioOutput.h"
#include "AutoPilotPluginManager.h"
#include "UASMessageHandler.h"
#include "FactSystem.h"
#ifdef QGC_RTLAB_ENABLED #ifdef QGC_RTLAB_ENABLED
#include "OpalLink.h" #include "OpalLink.h"
...@@ -44,6 +55,7 @@ ...@@ -44,6 +55,7 @@
// Work around circular header includes // Work around circular header includes
class QGCSingleton; class QGCSingleton;
class MainWindow; class MainWindow;
class QGCToolbox;
/** /**
* @brief The main application and management class. * @brief The main application and management class.
...@@ -109,6 +121,9 @@ public: ...@@ -109,6 +121,9 @@ public:
#ifdef QT_DEBUG #ifdef QT_DEBUG
bool testHighDPI(void) { return _testHighDPI; } bool testHighDPI(void) { return _testHighDPI; }
#endif #endif
// Still working on getting rid of this and using dependency injection instead for everything
QGCToolbox* toolbox(void) { return _toolbox; }
public slots: public slots:
/// You can connect to this slot to show an information message box from a different thread. /// You can connect to this slot to show an information message box from a different thread.
...@@ -122,7 +137,7 @@ public slots: ...@@ -122,7 +137,7 @@ public slots:
/// Save the specified Flight Data Log /// Save the specified Flight Data Log
void saveTempFlightDataLogOnMainThread(QString tempLogfile); void saveTempFlightDataLogOnMainThread(QString tempLogfile);
signals: signals:
/// Signals that the style has changed /// Signals that the style has changed
/// @param darkStyle true: dark style, false: light style /// @param darkStyle true: dark style, false: light style
...@@ -166,7 +181,7 @@ private: ...@@ -166,7 +181,7 @@ private:
static const char* _defaultSavedFileDirectoryName; ///< Default name for user visible save file directory static const char* _defaultSavedFileDirectoryName; ///< Default name for user visible save file directory
static const char* _savedFileMavlinkLogDirectoryName; ///< Name of mavlink log subdirectory static const char* _savedFileMavlinkLogDirectoryName; ///< Name of mavlink log subdirectory
static const char* _savedFileParameterDirectoryName; ///< Name of parameter subdirectory static const char* _savedFileParameterDirectoryName; ///< Name of parameter subdirectory
bool _runningUnitTests; ///< true: running unit tests, false: normal app bool _runningUnitTests; ///< true: running unit tests, false: normal app
static const char* _darkStyleFile; static const char* _darkStyleFile;
...@@ -183,6 +198,8 @@ private: ...@@ -183,6 +198,8 @@ private:
bool _testHighDPI; ///< true: double fonts sizes for simulating high dpi devices bool _testHighDPI; ///< true: double fonts sizes for simulating high dpi devices
#endif #endif
QGCToolbox* _toolbox;
/// Unit Test have access to creating and destroying singletons /// Unit Test have access to creating and destroying singletons
friend class UnitTest; friend class UnitTest;
}; };
......
...@@ -40,8 +40,8 @@ QGCQuickWidget::QGCQuickWidget(QWidget* parent) : ...@@ -40,8 +40,8 @@ QGCQuickWidget::QGCQuickWidget(QWidget* parent) :
QQuickWidget(parent) QQuickWidget(parent)
{ {
rootContext()->engine()->addImportPath("qrc:/qml"); rootContext()->engine()->addImportPath("qrc:/qml");
rootContext()->setContextProperty("multiVehicleManager", MultiVehicleManager::instance()); rootContext()->setContextProperty("multiVehicleManager", qgcApp()->toolbox()->multiVehicleManager());
rootContext()->setContextProperty("joystickManager", JoystickManager::instance()); rootContext()->setContextProperty("joystickManager", qgcApp()->toolbox()->joystickManager());
} }
void QGCQuickWidget::setAutoPilot(AutoPilotPlugin* autoPilot) void QGCQuickWidget::setAutoPilot(AutoPilotPlugin* autoPilot)
......
...@@ -29,8 +29,3 @@ ...@@ -29,8 +29,3 @@
#include "QGCSingleton.h" #include "QGCSingleton.h"
#include "QGCApplication.h" #include "QGCApplication.h"
QGCSingleton::QGCSingleton(QObject* parent) :
QObject(parent)
{
}
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#ifndef QGCSINGLETON_H #ifndef QGCSINGLETON_H
#define QGCSINGLETON_H #define QGCSINGLETON_H
#include "QGCApplication.h"
#include <QObject> #include <QObject>
#include <QMutex> #include <QMutex>
...@@ -40,14 +38,12 @@ ...@@ -40,14 +38,12 @@
public: \ public: \
static interfaceName* instance(bool nullOk = false); \ static interfaceName* instance(bool nullOk = false); \
static void setMockInstance(interfaceName* mock); \ static void setMockInstance(interfaceName* mock); \
private: \
static interfaceName* _createSingleton(void); \ static interfaceName* _createSingleton(void); \
static void _deleteSingleton(void); \ static void _deleteSingleton(void); \
private: \
static interfaceName* _instance; \ static interfaceName* _instance; \
static interfaceName* _mockInstance; \ static interfaceName* _mockInstance; \
static interfaceName* _realInstance; \ static interfaceName* _realInstance; \
friend class QGCApplication; \
friend class UnitTest; \
/// @def IMPLEMENT_QGC_SINGLETON /// @def IMPLEMENT_QGC_SINGLETON
/// Include this macro in your Derived Class implementation /// Include this macro in your Derived Class implementation
...@@ -61,7 +57,7 @@ ...@@ -61,7 +57,7 @@
interfaceName* className::_createSingleton(void) \ interfaceName* className::_createSingleton(void) \
{ \ { \
Q_ASSERT(_instance == NULL); \ Q_ASSERT(_instance == NULL); \
_instance = new className(qgcApp()); \ _instance = new className; \
return _instance; \ return _instance; \
} \ } \
\ \
...@@ -151,10 +147,6 @@ class QGCSingleton : public QObject ...@@ -151,10 +147,6 @@ class QGCSingleton : public QObject
{ {
Q_OBJECT Q_OBJECT
protected:
/// Constructor is private since all creation is done through _createInstance
/// @param parent Parent object
QGCSingleton(QObject* parent = NULL);
}; };
#endif #endif
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
#include "LinkManager.h"
#include "MAVLinkProtocol.h"
#include "FlightMapSettings.h"
#include "HomePositionManager.h"
#include "FirmwarePluginManager.h"
#include "MultiVehicleManager.h"
#include "JoystickManager.h"
#include "GAudioOutput.h"
#include "AutoPilotPluginManager.h"
#include "UASMessageHandler.h"
#include "FactSystem.h"
QGCToolbox::QGCToolbox(QGCApplication* app)
: _firmwarePluginManager(NULL)
, _autopilotPluginManager(NULL)
, _linkManager(NULL)
, _multiVehicleManager(NULL)
, _mavlinkProtocol(NULL)
, _flightMapSettings(NULL)
, _homePositionManager(NULL)
, _joystickManager(NULL)
, _audioOutput(NULL)
, _uasMessageHandler(NULL)
, _factSystem(NULL)
{
_firmwarePluginManager = new FirmwarePluginManager(app);
_autopilotPluginManager = new AutoPilotPluginManager(app);
_flightMapSettings = new FlightMapSettings(app);
_homePositionManager = new HomePositionManager(app);
_factSystem = new FactSystem(app);
_linkManager = new LinkManager(app);
_multiVehicleManager = new MultiVehicleManager(app);
_mavlinkProtocol = new MAVLinkProtocol(app);
_joystickManager = new JoystickManager(app);
_audioOutput = new GAudioOutput(app);
_uasMessageHandler = new UASMessageHandler(app);
_firmwarePluginManager->setToolbox(this);
_autopilotPluginManager->setToolbox(this);
_flightMapSettings->setToolbox(this);
_homePositionManager->setToolbox(this);
_factSystem->setToolbox(this);
_linkManager->setToolbox(this);
_multiVehicleManager->setToolbox(this);
_mavlinkProtocol->setToolbox(this);
_joystickManager->setToolbox(this);
_audioOutput->setToolbox(this);
_uasMessageHandler->setToolbox(this);
}
QGCToolbox::~QGCToolbox()
{
delete _firmwarePluginManager;
delete _autopilotPluginManager;
delete _linkManager;
delete _multiVehicleManager;
delete _mavlinkProtocol;
delete _flightMapSettings;
delete _homePositionManager;
delete _joystickManager;
delete _audioOutput;
delete _uasMessageHandler;
delete _factSystem;
}
QGCTool::QGCTool(QGCApplication* app)
: QObject((QObject*)app)
, _app(app)
, _toolbox(NULL)
{
}
void QGCTool::setToolbox(QGCToolbox* toolbox)
{
_toolbox = toolbox;
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
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 <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef QGCToolbox_h
#define QGCToolbox_h
#include <QObject>
class QGCApplication;
class LinkManager;
class MAVLinkProtocol;
class MultiVehicleManager;
class JoystickManager;
class UASMessageHandler;
class HomePositionManager;
class FlightMapSettings;
class GAudioOutput;
class FirmwarePluginManager;
class AutoPilotPluginManager;
class FactSystem;
/// This is used to manage all of our top level services/tools
class QGCToolbox {
public:
QGCToolbox(QGCApplication* app);
~QGCToolbox();
LinkManager* linkManager(void) { return _linkManager; }
MAVLinkProtocol* mavlinkProtocol(void) { return _mavlinkProtocol; }
MultiVehicleManager* multiVehicleManager(void) { return _multiVehicleManager; }
JoystickManager* joystickManager(void) { return _joystickManager; }
UASMessageHandler* uasMessageHandler(void) { return _uasMessageHandler; }
HomePositionManager* homePositionManager(void) { return _homePositionManager; }
FlightMapSettings* flightMapSettings(void) { return _flightMapSettings; }
GAudioOutput* audioOutput(void) { return _audioOutput; }
FirmwarePluginManager* firmwarePluginManager(void) { return _firmwarePluginManager; }
AutoPilotPluginManager* autopilotPluginManager(void) { return _autopilotPluginManager; }
private:
FirmwarePluginManager* _firmwarePluginManager;
AutoPilotPluginManager* _autopilotPluginManager;
LinkManager* _linkManager;
MultiVehicleManager* _multiVehicleManager;
MAVLinkProtocol* _mavlinkProtocol;
FlightMapSettings* _flightMapSettings;
HomePositionManager* _homePositionManager;
JoystickManager* _joystickManager;
GAudioOutput* _audioOutput;
UASMessageHandler* _uasMessageHandler;
FactSystem* _factSystem;
};
/// This is the base class for all tools
class QGCTool : public QObject {
Q_OBJECT
public:
// All tools are parented to QGCAppliation and go through a two phase creation. First all tools are newed,
// and then setToolbox is called on all tools. The prevents creating an circular dependencies at constructor
// time.
QGCTool(QGCApplication* app);
virtual void setToolbox(QGCToolbox* toolbox);
protected:
QGCApplication* _app;
QGCToolbox* _toolbox;
};
#endif
...@@ -158,6 +158,6 @@ void ParameterEditorController::resetAllToDefaults(void) ...@@ -158,6 +158,6 @@ void ParameterEditorController::resetAllToDefaults(void)
void ParameterEditorController::setRCToParam(const QString& paramName) void ParameterEditorController::setRCToParam(const QString& paramName)
{ {
Q_ASSERT(_uas); Q_ASSERT(_uas);
QGCMapRCToParamDialog * d = new QGCMapRCToParamDialog(paramName, _uas, MainWindow::instance()); QGCMapRCToParamDialog * d = new QGCMapRCToParamDialog(paramName, _uas, qgcApp()->toolbox()->multiVehicleManager(), MainWindow::instance());
d->exec(); d->exec();
} }
...@@ -25,18 +25,16 @@ ...@@ -25,18 +25,16 @@
/// @author Don Gagne <don@thegagnes.com> /// @author Don Gagne <don@thegagnes.com>
#include "QGroundControlQmlGlobal.h" #include "QGroundControlQmlGlobal.h"
#include "QGCApplication.h"
#include <QSettings>
static const char* kQmlGlobalKeyName = "QGCQml"; static const char* kQmlGlobalKeyName = "QGCQml";
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QObject* parent) QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCToolbox* toolbox, QObject* parent)
: QObject(parent) : QObject(parent)
, _homePositionManager(HomePositionManager::instance()) , _homePositionManager(toolbox->homePositionManager())
, _flightMapSettings(FlightMapSettings::instance()) , _flightMapSettings(toolbox->flightMapSettings())
{
}
QGroundControlQmlGlobal::~QGroundControlQmlGlobal()
{ {
} }
......
...@@ -32,13 +32,14 @@ ...@@ -32,13 +32,14 @@
#include "HomePositionManager.h" #include "HomePositionManager.h"
#include "FlightMapSettings.h" #include "FlightMapSettings.h"
class QGCToolbox;
class QGroundControlQmlGlobal : public QObject class QGroundControlQmlGlobal : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
QGroundControlQmlGlobal(QObject* parent = NULL); QGroundControlQmlGlobal(QGCToolbox* toolbox, QObject* parent = NULL);
~QGroundControlQmlGlobal();
Q_PROPERTY(HomePositionManager* homePositionManager READ homePositionManager CONSTANT) Q_PROPERTY(HomePositionManager* homePositionManager READ homePositionManager CONSTANT)
Q_PROPERTY(FlightMapSettings* flightMapSettings READ flightMapSettings CONSTANT) Q_PROPERTY(FlightMapSettings* flightMapSettings READ flightMapSettings CONSTANT)
......
...@@ -28,42 +28,52 @@ ...@@ -28,42 +28,52 @@
#include "AutoPilotPlugin.h" #include "AutoPilotPlugin.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "UAS.h" #include "UAS.h"
#include "QGCApplication.h"
IMPLEMENT_QGC_SINGLETON(MultiVehicleManager, MultiVehicleManager) MultiVehicleManager::MultiVehicleManager(QGCApplication* app)
: QGCTool(app)
MultiVehicleManager::MultiVehicleManager(QObject* parent) :
QGCSingleton(parent)
, _activeVehicleAvailable(false) , _activeVehicleAvailable(false)
, _parameterReadyVehicleAvailable(false) , _parameterReadyVehicleAvailable(false)
, _activeVehicle(NULL) , _activeVehicle(NULL)
, _firmwarePluginManager(NULL)
, _autopilotPluginManager(NULL)
, _joystickManager(NULL)
, _mavlinkProtocol(NULL)
{ {
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
qmlRegisterUncreatableType<MultiVehicleManager>("QGroundControl.MultiVehicleManager", 1, 0, "MultiVehicleManager", "Reference only");
} }
MultiVehicleManager::~MultiVehicleManager() void MultiVehicleManager::setToolbox(QGCToolbox *toolbox)
{ {
QGCTool::setToolbox(toolbox);
_firmwarePluginManager = _toolbox->firmwarePluginManager();
_autopilotPluginManager = _toolbox->autopilotPluginManager();
_joystickManager = _toolbox->joystickManager();
_mavlinkProtocol = _toolbox->mavlinkProtocol();
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
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)
{ {
if (!getVehicleById(vehicleId) && !_ignoreVehicleIds.contains(vehicleId)) { if (!getVehicleById(vehicleId) && !_ignoreVehicleIds.contains(vehicleId)) {
if (vehicleId == MAVLinkProtocol::instance()->getSystemId()) { if (vehicleId == _mavlinkProtocol->getSystemId()) {
qgcApp()->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) {
_ignoreVehicleIds += vehicleId; _ignoreVehicleIds += vehicleId;
qgcApp()->showToolBarMessage(QString("The MAVLink protocol version on vehicle #%1 and QGroundControl differ! " _app->showToolBarMessage(QString("The MAVLink protocol version on vehicle #%1 and QGroundControl differ! "
"It is unsafe to use different MAVLink versions. " "It is unsafe to use different MAVLink versions. "
"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); 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";
......
...@@ -27,18 +27,24 @@ ...@@ -27,18 +27,24 @@
#ifndef MultiVehicleManager_H #ifndef MultiVehicleManager_H
#define MultiVehicleManager_H #define MultiVehicleManager_H
#include "QGCSingleton.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QmlObjectListModel.h" #include "QmlObjectListModel.h"
#include "QGCToolbox.h"
class MultiVehicleManager : public QGCSingleton class FirmwarePluginManager;
class AutoPilotPluginManager;
class JoystickManager;
class QGCApplication;
class MAVLinkProtocol;
class MultiVehicleManager : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(MultiVehicleManager, MultiVehicleManager)
public: public:
MultiVehicleManager(QGCApplication* app);
Q_INVOKABLE void saveSetting (const QString &key, const QString& value); Q_INVOKABLE void saveSetting (const QString &key, const QString& value);
Q_INVOKABLE QString loadSetting (const QString &key, const QString& defaultValue); Q_INVOKABLE QString loadSetting (const QString &key, const QString& defaultValue);
...@@ -76,6 +82,9 @@ public: ...@@ -76,6 +82,9 @@ public:
QmlObjectListModel* vehiclesModel(void) { return &_vehicles; } QmlObjectListModel* vehiclesModel(void) { return &_vehicles; }
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
signals: signals:
void vehicleAdded(Vehicle* vehicle); void vehicleAdded(Vehicle* vehicle);
void vehicleRemoved(Vehicle* vehicle); void vehicleRemoved(Vehicle* vehicle);
...@@ -92,10 +101,6 @@ private slots: ...@@ -92,10 +101,6 @@ private slots:
void _autopilotParametersReadyChanged(bool parametersReady); void _autopilotParametersReadyChanged(bool parametersReady);
private: private:
/// All access to singleton is through MultiVehicleManager::instance
MultiVehicleManager(QObject* parent = NULL);
~MultiVehicleManager();
bool _vehicleExists(int vehicleId); bool _vehicleExists(int vehicleId);
bool _activeVehicleAvailable; ///< true: An active vehicle is available bool _activeVehicleAvailable; ///< true: An active vehicle is available
...@@ -108,6 +113,11 @@ private: ...@@ -108,6 +113,11 @@ private:
QList<int> _ignoreVehicleIds; ///< List of vehicle id for which we ignore further communication QList<int> _ignoreVehicleIds; ///< List of vehicle id for which we ignore further communication
QmlObjectListModel _vehicles; QmlObjectListModel _vehicles;
FirmwarePluginManager* _firmwarePluginManager;
AutoPilotPluginManager* _autopilotPluginManager;
JoystickManager* _joystickManager;
MAVLinkProtocol* _mavlinkProtocol;
}; };
#endif #endif
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "MissionManager.h" #include "MissionManager.h"
#include "CoordinateVector.h" #include "CoordinateVector.h"
#include "ParameterLoader.h" #include "ParameterLoader.h"
#include "QGCApplication.h"
QGC_LOGGING_CATEGORY(VehicleLog, "VehicleLog") QGC_LOGGING_CATEGORY(VehicleLog, "VehicleLog")
...@@ -45,7 +46,13 @@ const char* Vehicle::_joystickModeSettingsKey = "JoystickMode"; ...@@ -45,7 +46,13 @@ const char* Vehicle::_joystickModeSettingsKey = "JoystickMode";
const char* Vehicle::_joystickEnabledSettingsKey = "JoystickEnabled"; const char* Vehicle::_joystickEnabledSettingsKey = "JoystickEnabled";
const char* Vehicle::_communicationInactivityKey = "CommunicationInactivity"; const char* Vehicle::_communicationInactivityKey = "CommunicationInactivity";
Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType) Vehicle::Vehicle(LinkInterface* link,
int vehicleId,
MAV_AUTOPILOT firmwareType,
MAV_TYPE vehicleType,
FirmwarePluginManager* firmwarePluginManager,
AutoPilotPluginManager* autopilotPluginManager,
JoystickManager* joystickManager)
: _id(vehicleId) : _id(vehicleId)
, _active(false) , _active(false)
, _firmwareType(firmwareType) , _firmwareType(firmwareType)
...@@ -96,15 +103,18 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType, ...@@ -96,15 +103,18 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType,
, _custom_mode(0) , _custom_mode(0)
, _nextSendMessageMultipleIndex(0) , _nextSendMessageMultipleIndex(0)
, _communicationInactivityTimeoutMSecs(_communicationInactivityTimeoutMSecsDefault) , _communicationInactivityTimeoutMSecs(_communicationInactivityTimeoutMSecsDefault)
, _firmwarePluginManager(firmwarePluginManager)
, _autopilotPluginManager(autopilotPluginManager)
, _joystickManager(joystickManager)
{ {
_addLink(link); _addLink(link);
_mavlink = MAVLinkProtocol::instance(); _mavlink = qgcApp()->toolbox()->mavlinkProtocol();
connect(_mavlink, &MAVLinkProtocol::messageReceived, this, &Vehicle::_mavlinkMessageReceived); connect(_mavlink, &MAVLinkProtocol::messageReceived, this, &Vehicle::_mavlinkMessageReceived);
connect(this, &Vehicle::_sendMessageOnThread, this, &Vehicle::_sendMessage, Qt::QueuedConnection); connect(this, &Vehicle::_sendMessageOnThread, this, &Vehicle::_sendMessage, Qt::QueuedConnection);
_uas = new UAS(_mavlink, this); _uas = new UAS(_mavlink, this, _firmwarePluginManager);
setLatitude(_uas->getLatitude()); setLatitude(_uas->getLatitude());
setLongitude(_uas->getLongitude()); setLongitude(_uas->getLongitude());
...@@ -112,8 +122,8 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType, ...@@ -112,8 +122,8 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType,
connect(_uas, &UAS::latitudeChanged, this, &Vehicle::setLatitude); connect(_uas, &UAS::latitudeChanged, this, &Vehicle::setLatitude);
connect(_uas, &UAS::longitudeChanged, this, &Vehicle::setLongitude); connect(_uas, &UAS::longitudeChanged, this, &Vehicle::setLongitude);
_firmwarePlugin = FirmwarePluginManager::instance()->firmwarePluginForAutopilot(_firmwareType, _vehicleType); _firmwarePlugin = _firmwarePluginManager->firmwarePluginForAutopilot(_firmwareType, _vehicleType);
_autopilotPlugin = AutoPilotPluginManager::instance()->newAutopilotPluginForVehicle(this); _autopilotPlugin = _autopilotPluginManager->newAutopilotPluginForVehicle(this);
connect(_autopilotPlugin, &AutoPilotPlugin::parametersReadyChanged, this, &Vehicle::_parametersReady); connect(_autopilotPlugin, &AutoPilotPlugin::parametersReadyChanged, this, &Vehicle::_parametersReady);
connect(_autopilotPlugin, &AutoPilotPlugin::missingParametersChanged, this, &Vehicle::missingParametersChanged); connect(_autopilotPlugin, &AutoPilotPlugin::missingParametersChanged, this, &Vehicle::missingParametersChanged);
...@@ -132,7 +142,7 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType, ...@@ -132,7 +142,7 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType,
_currentHeartbeatTimeout = 0; _currentHeartbeatTimeout = 0;
emit heartbeatTimeoutChanged(); emit heartbeatTimeoutChanged();
// Listen for system messages // Listen for system messages
connect(UASMessageHandler::instance(), &UASMessageHandler::textMessageCountChanged, this, &Vehicle::_handleTextMessage); connect(qgcApp()->toolbox()->uasMessageHandler(), &UASMessageHandler::textMessageCountChanged, this, &Vehicle::_handleTextMessage);
// Now connect the new UAS // Now connect the new UAS
connect(_mav, SIGNAL(attitudeChanged (UASInterface*,double,double,double,quint64)), this, SLOT(_updateAttitude(UASInterface*, double, double, double, quint64))); connect(_mav, SIGNAL(attitudeChanged (UASInterface*,double,double,double,quint64)), this, SLOT(_updateAttitude(UASInterface*, double, double, double, quint64)));
connect(_mav, SIGNAL(attitudeChanged (UASInterface*,int,double,double,double,quint64)), this, SLOT(_updateAttitude(UASInterface*,int,double, double, double, quint64))); connect(_mav, SIGNAL(attitudeChanged (UASInterface*,int,double,double,double,quint64)), this, SLOT(_updateAttitude(UASInterface*,int,double, double, double, quint64)));
...@@ -178,9 +188,14 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType, ...@@ -178,9 +188,14 @@ Vehicle::Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType,
Vehicle::~Vehicle() Vehicle::~Vehicle()
{ {
qDebug() << "~Vehicle";
delete _missionManager; delete _missionManager;
_missionManager = NULL; _missionManager = NULL;
delete _autopilotPlugin;
_autopilotPlugin = NULL;
delete _mav; delete _mav;
_mav = NULL; _mav = NULL;
} }
...@@ -285,9 +300,9 @@ bool Vehicle::_containsLink(LinkInterface* link) ...@@ -285,9 +300,9 @@ bool Vehicle::_containsLink(LinkInterface* link)
void Vehicle::_addLink(LinkInterface* link) void Vehicle::_addLink(LinkInterface* link)
{ {
if (!_containsLink(link)) { if (!_containsLink(link)) {
_links += LinkManager::instance()->sharedPointerForLink(link); _links += qgcApp()->toolbox()->linkManager()->sharedPointerForLink(link);
qCDebug(VehicleLog) << "_addLink:" << QString("%1").arg((ulong)link, 0, 16); qCDebug(VehicleLog) << "_addLink:" << QString("%1").arg((ulong)link, 0, 16);
connect(LinkManager::instance(), &LinkManager::linkDisconnected, this, &Vehicle::_linkDisconnected); connect(qgcApp()->toolbox()->linkManager(), &LinkManager::linkDisconnected, this, &Vehicle::_linkDisconnected);
} }
} }
...@@ -790,7 +805,7 @@ void Vehicle::_handleTextMessage(int newCount) ...@@ -790,7 +805,7 @@ void Vehicle::_handleTextMessage(int newCount)
return; return;
} }
UASMessageHandler* pMh = UASMessageHandler::instance(); UASMessageHandler* pMh = qgcApp()->toolbox()->uasMessageHandler();
Q_ASSERT(pMh); Q_ASSERT(pMh);
MessageType_t type = newCount ? _currentMessageType : MessageNone; MessageType_t type = newCount ? _currentMessageType : MessageNone;
int errorCount = _currentErrorCount; int errorCount = _currentErrorCount;
...@@ -941,7 +956,7 @@ void Vehicle::setJoystickEnabled(bool enabled) ...@@ -941,7 +956,7 @@ void Vehicle::setJoystickEnabled(bool enabled)
void Vehicle::_startJoystick(bool start) void Vehicle::_startJoystick(bool start)
{ {
#ifndef __mobile__ #ifndef __mobile__
Joystick* joystick = JoystickManager::instance()->activeJoystick(); Joystick* joystick = _joystickManager->activeJoystick();
if (joystick) { if (joystick) {
if (start) { if (start) {
if (_joystickEnabled) { if (_joystickEnabled) {
...@@ -1149,7 +1164,7 @@ void Vehicle::_communicationInactivityTimedOut(void) ...@@ -1149,7 +1164,7 @@ void Vehicle::_communicationInactivityTimedOut(void)
{ {
// Vechile is no longer communicating with us, disconnect all links // Vechile is no longer communicating with us, disconnect all links
LinkManager* linkMgr = LinkManager::instance(); LinkManager* linkMgr = qgcApp()->toolbox()->linkManager();
for (int i=0; i<_links.count(); i++) { for (int i=0; i<_links.count(); i++) {
linkMgr->disconnectLink(_links[i].data()); linkMgr->disconnectLink(_links[i].data());
} }
......
...@@ -40,9 +40,12 @@ ...@@ -40,9 +40,12 @@
class UAS; class UAS;
class UASInterface; class UASInterface;
class FirmwarePlugin; class FirmwarePlugin;
class FirmwarePluginManager;
class AutoPilotPlugin; class AutoPilotPlugin;
class AutoPilotPluginManager;
class MissionManager; class MissionManager;
class ParameterLoader; class ParameterLoader;
class JoystickManager;
Q_DECLARE_LOGGING_CATEGORY(VehicleLog) Q_DECLARE_LOGGING_CATEGORY(VehicleLog)
...@@ -51,7 +54,13 @@ class Vehicle : public QObject ...@@ -51,7 +54,13 @@ class Vehicle : public QObject
Q_OBJECT Q_OBJECT
public: public:
Vehicle(LinkInterface* link, int vehicleId, MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType); Vehicle(LinkInterface* link,
int vehicleId,
MAV_AUTOPILOT firmwareType,
MAV_TYPE vehicleType,
FirmwarePluginManager* firmwarePluginManager,
AutoPilotPluginManager* autopilotPluginManager,
JoystickManager* joystickManager);
~Vehicle(); ~Vehicle();
Q_PROPERTY(int id READ id CONSTANT) Q_PROPERTY(int id READ id CONSTANT)
...@@ -444,6 +453,10 @@ private: ...@@ -444,6 +453,10 @@ private:
QTimer _communicationInactivityTimer; QTimer _communicationInactivityTimer;
int _communicationInactivityTimeoutMSecs; int _communicationInactivityTimeoutMSecs;
static const int _communicationInactivityTimeoutMSecsDefault = 30 * 1000; static const int _communicationInactivityTimeoutMSecsDefault = 30 * 1000;
FirmwarePluginManager* _firmwarePluginManager;
AutoPilotPluginManager* _autopilotPluginManager;
JoystickManager* _joystickManager;
// Settings keys // Settings keys
static const char* _settingsGroup; static const char* _settingsGroup;
......
...@@ -68,7 +68,7 @@ FirmwareUpgradeController::FirmwareUpgradeController(void) : ...@@ -68,7 +68,7 @@ FirmwareUpgradeController::FirmwareUpgradeController(void) :
connect(_threadController, &PX4FirmwareUpgradeThreadController::flashComplete, this, &FirmwareUpgradeController::_flashComplete); connect(_threadController, &PX4FirmwareUpgradeThreadController::flashComplete, this, &FirmwareUpgradeController::_flashComplete);
connect(_threadController, &PX4FirmwareUpgradeThreadController::updateProgress, this, &FirmwareUpgradeController::_updateProgress); connect(_threadController, &PX4FirmwareUpgradeThreadController::updateProgress, this, &FirmwareUpgradeController::_updateProgress);
connect(LinkManager::instance(), &LinkManager::linkDisconnected, this, &FirmwareUpgradeController::_linkDisconnected); connect(qgcApp()->toolbox()->linkManager(), &LinkManager::linkDisconnected, this, &FirmwareUpgradeController::_linkDisconnected);
connect(&_eraseTimer, &QTimer::timeout, this, &FirmwareUpgradeController::_eraseProgressTick); connect(&_eraseTimer, &QTimer::timeout, this, &FirmwareUpgradeController::_eraseProgressTick);
} }
...@@ -558,7 +558,7 @@ void FirmwareUpgradeController::_appendStatusLog(const QString& text, bool criti ...@@ -558,7 +558,7 @@ void FirmwareUpgradeController::_appendStatusLog(const QString& text, bool criti
bool FirmwareUpgradeController::qgcConnections(void) bool FirmwareUpgradeController::qgcConnections(void)
{ {
return LinkManager::instance()->anyConnectedLinks(); return qgcApp()->toolbox()->linkManager()->anyConnectedLinks();
} }
void FirmwareUpgradeController::_linkDisconnected(LinkInterface* link) void FirmwareUpgradeController::_linkDisconnected(LinkInterface* link)
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "JoystickConfigController.h" #include "JoystickConfigController.h"
#include "JoystickManager.h" #include "JoystickManager.h"
#include "QGCMessageBox.h" #include "QGCMessageBox.h"
#include "QGCApplication.h"
#include <QSettings> #include <QSettings>
...@@ -66,12 +67,12 @@ JoystickConfigController::JoystickConfigController(void) ...@@ -66,12 +67,12 @@ JoystickConfigController::JoystickConfigController(void)
, _cancelButton(NULL) , _cancelButton(NULL)
, _nextButton(NULL) , _nextButton(NULL)
, _skipButton(NULL) , _skipButton(NULL)
, _joystickManager(qgcApp()->toolbox()->joystickManager())
{ {
JoystickManager* joystickManager = JoystickManager::instance();
connect(joystickManager, &JoystickManager::activeJoystickChanged, this, &JoystickConfigController::_activeJoystickChanged); connect(_joystickManager, &JoystickManager::activeJoystickChanged, this, &JoystickConfigController::_activeJoystickChanged);
_activeJoystickChanged(joystickManager->activeJoystick()); _activeJoystickChanged(_joystickManager->activeJoystick());
_resetInternalCalibrationValues(); _resetInternalCalibrationValues();
} }
...@@ -454,7 +455,7 @@ void JoystickConfigController::_resetInternalCalibrationValues(void) ...@@ -454,7 +455,7 @@ void JoystickConfigController::_resetInternalCalibrationValues(void)
/// @brief Sets internal calibration values from the stored settings /// @brief Sets internal calibration values from the stored settings
void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void) void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void)
{ {
Joystick* joystick = JoystickManager::instance()->activeJoystick(); Joystick* joystick = _joystickManager->activeJoystick();
// Initialize all function mappings to not set // Initialize all function mappings to not set
...@@ -539,7 +540,7 @@ void JoystickConfigController::_validateCalibration(void) ...@@ -539,7 +540,7 @@ void JoystickConfigController::_validateCalibration(void)
/// @brief Saves the rc calibration values to the board parameters. /// @brief Saves the rc calibration values to the board parameters.
void JoystickConfigController::_writeCalibration(void) void JoystickConfigController::_writeCalibration(void)
{ {
Joystick* joystick = JoystickManager::instance()->activeJoystick(); Joystick* joystick = _joystickManager->activeJoystick();
_validateCalibration(); _validateCalibration();
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
Q_DECLARE_LOGGING_CATEGORY(JoystickConfigControllerLog) Q_DECLARE_LOGGING_CATEGORY(JoystickConfigControllerLog)
class RadioConfigest; class RadioConfigest;
class JoystickManager;
namespace Ui { namespace Ui {
class JoystickConfigController; class JoystickConfigController;
...@@ -253,6 +254,8 @@ private: ...@@ -253,6 +254,8 @@ private:
QQuickItem* _skipButton; QQuickItem* _skipButton;
QString _imageHelp; QString _imageHelp;
JoystickManager* _joystickManager;
}; };
#endif // JoystickConfigController_H #endif // JoystickConfigController_H
...@@ -31,50 +31,14 @@ ...@@ -31,50 +31,14 @@
UT_REGISTER_TEST(SetupViewTest) UT_REGISTER_TEST(SetupViewTest)
SetupViewTest::SetupViewTest(void) :
_mainWindow(NULL)
{
}
void SetupViewTest::init(void)
{
UnitTest::init();
_mainWindow = MainWindow::_create();
Q_CHECK_PTR(_mainWindow);
}
void SetupViewTest::cleanup(void)
{
_mainWindow->close();
delete _mainWindow;
UnitTest::cleanup();
}
void SetupViewTest::_clickThrough_test(void) void SetupViewTest::_clickThrough_test(void)
{ {
LinkManager* linkMgr = LinkManager::instance(); _connectMockLink();
Q_CHECK_PTR(linkMgr);
MockLink* link = new MockLink(); AutoPilotPlugin* autopilot = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->autopilotPlugin();
Q_CHECK_PTR(link);
link->setFirmwareType(MAV_AUTOPILOT_PX4);
LinkManager::instance()->_addLink(link);
linkMgr->connectLink(link);
// Wait for the Vehicle to get created
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
QCOMPARE(spyVehicle.wait(5000), true);
QVERIFY(MultiVehicleManager::instance()->parameterReadyVehicleAvailable());
QVERIFY(MultiVehicleManager::instance()->activeVehicle());
AutoPilotPlugin* autopilot = MultiVehicleManager::instance()->activeVehicle()->autopilotPlugin();
Q_ASSERT(autopilot); Q_ASSERT(autopilot);
MainWindow* mainWindow = MainWindow::instance(); _createMainWindow();
Q_ASSERT(mainWindow);
// Switch to the Setup view // Switch to the Setup view
_mainWindow->showSetupView(); _mainWindow->showSetupView();
...@@ -103,7 +67,6 @@ void SetupViewTest::_clickThrough_test(void) ...@@ -103,7 +67,6 @@ void SetupViewTest::_clickThrough_test(void)
setExpectedMessageBox(QGCMessageBox::Yes); setExpectedMessageBox(QGCMessageBox::Yes);
_mainWindow->close(); _closeMainWindow();
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedMessageBox(); checkExpectedMessageBox();
} }
...@@ -35,17 +35,8 @@ class SetupViewTest : public UnitTest ...@@ -35,17 +35,8 @@ class SetupViewTest : public UnitTest
{ {
Q_OBJECT Q_OBJECT
public:
SetupViewTest(void);
private slots: private slots:
void init(void);
void cleanup(void);
void _clickThrough_test(void); void _clickThrough_test(void);
private:
MainWindow* _mainWindow;
}; };
#endif #endif
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QGCFileDialog.h" #include "QGCFileDialog.h"
#include "UAS.h" #include "UAS.h"
#include "QGCApplication.h"
#include <QSettings> #include <QSettings>
#include <QUrl> #include <QUrl>
...@@ -35,7 +36,7 @@ const char* CustomCommandWidgetController::_settingsKey = "CustomCommand.QmlFile ...@@ -35,7 +36,7 @@ const char* CustomCommandWidgetController::_settingsKey = "CustomCommand.QmlFile
CustomCommandWidgetController::CustomCommandWidgetController(void) : CustomCommandWidgetController::CustomCommandWidgetController(void) :
_uas(NULL) _uas(NULL)
{ {
_uas = MultiVehicleManager::instance()->activeVehicle()->uas(); _uas = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->uas();
Q_ASSERT(_uas); Q_ASSERT(_uas);
QSettings settings; QSettings settings;
......
...@@ -24,12 +24,13 @@ ...@@ -24,12 +24,13 @@
#include "ViewWidgetController.h" #include "ViewWidgetController.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "UAS.h" #include "UAS.h"
#include "QGCApplication.h"
ViewWidgetController::ViewWidgetController(void) : ViewWidgetController::ViewWidgetController(void) :
_autopilot(NULL), _autopilot(NULL),
_uas(NULL) _uas(NULL)
{ {
connect(MultiVehicleManager::instance(), &MultiVehicleManager::parameterReadyVehicleAvailableChanged, this, &ViewWidgetController::_vehicleAvailable); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::parameterReadyVehicleAvailableChanged, this, &ViewWidgetController::_vehicleAvailable);
} }
void ViewWidgetController::_vehicleAvailable(bool available) void ViewWidgetController::_vehicleAvailable(bool available)
...@@ -41,7 +42,7 @@ void ViewWidgetController::_vehicleAvailable(bool available) ...@@ -41,7 +42,7 @@ void ViewWidgetController::_vehicleAvailable(bool available)
} }
if (available) { if (available) {
Vehicle* vehicle = MultiVehicleManager::instance()->activeVehicle(); Vehicle* vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
_uas = vehicle->uas(); _uas = vehicle->uas();
_autopilot = vehicle->autopilotPlugin(); _autopilot = vehicle->autopilotPlugin();
...@@ -51,5 +52,5 @@ void ViewWidgetController::_vehicleAvailable(bool available) ...@@ -51,5 +52,5 @@ void ViewWidgetController::_vehicleAvailable(bool available)
} }
Q_INVOKABLE void ViewWidgetController::checkForVehicle(void) Q_INVOKABLE void ViewWidgetController::checkForVehicle(void)
{ {
_vehicleAvailable(MultiVehicleManager::instance()->activeVehicle()); _vehicleAvailable(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
} }
...@@ -46,27 +46,20 @@ This file is part of the QGROUNDCONTROL project ...@@ -46,27 +46,20 @@ This file is part of the QGROUNDCONTROL project
#include "QGCMessageBox.h" #include "QGCMessageBox.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "SerialPortIds.h" #include "SerialPortIds.h"
#include "QGCApplication.h"
IMPLEMENT_QGC_SINGLETON(LinkManager, LinkManager)
QGC_LOGGING_CATEGORY(LinkManagerLog, "LinkManagerLog") QGC_LOGGING_CATEGORY(LinkManagerLog, "LinkManagerLog")
/** LinkManager::LinkManager(QGCApplication* app)
* @brief Private singleton constructor : QGCTool(app)
*
* This class implements the singleton design pattern and has therefore only a private constructor.
**/
LinkManager::LinkManager(QObject* parent)
: QGCSingleton(parent)
, _configUpdateSuspended(false) , _configUpdateSuspended(false)
, _configurationsLoaded(false) , _configurationsLoaded(false)
, _connectionsSuspended(false) , _connectionsSuspended(false)
, _mavlinkChannelsUsedBitMask(0) , _mavlinkChannelsUsedBitMask(0)
, _nullSharedLink(NULL) , _nullSharedLink(NULL)
, _mavlinkProtocol(NULL)
{ {
#ifndef __ios__
connect(&_portListTimer, &QTimer::timeout, this, &LinkManager::_updateConfigurationList);
_portListTimer.start(1000);
#endif
} }
LinkManager::~LinkManager() LinkManager::~LinkManager()
...@@ -80,6 +73,18 @@ LinkManager::~LinkManager() ...@@ -80,6 +73,18 @@ LinkManager::~LinkManager()
Q_ASSERT_X(_links.count() == 0, "LinkManager", "LinkManager::_shutdown should have been called previously"); Q_ASSERT_X(_links.count() == 0, "LinkManager", "LinkManager::_shutdown should have been called previously");
} }
void LinkManager::setToolbox(QGCToolbox *toolbox)
{
QGCTool::setToolbox(toolbox);
_mavlinkProtocol = _toolbox->mavlinkProtocol();
#ifndef __ios__
connect(&_portListTimer, &QTimer::timeout, this, &LinkManager::_updateConfigurationList);
_portListTimer.start(1000);
#endif
}
LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config) LinkInterface* LinkManager::createConnectedLink(LinkConfiguration* config)
{ {
Q_ASSERT(config); Q_ASSERT(config);
...@@ -149,16 +154,15 @@ void LinkManager::_addLink(LinkInterface* link) ...@@ -149,16 +154,15 @@ void LinkManager::_addLink(LinkInterface* link)
// MainWindow may be around when doing things like running unit tests // MainWindow may be around when doing things like running unit tests
if (MainWindow::instance()) { if (MainWindow::instance()) {
connect(link, &LinkInterface::communicationError, qgcApp(), &QGCApplication::criticalMessageBoxOnMainThread); connect(link, &LinkInterface::communicationError, _app, &QGCApplication::criticalMessageBoxOnMainThread);
} }
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance(); connect(link, &LinkInterface::bytesReceived, _mavlinkProtocol, &MAVLinkProtocol::receiveBytes);
connect(link, &LinkInterface::bytesReceived, mavlink, &MAVLinkProtocol::receiveBytes); connect(link, &LinkInterface::connected, _mavlinkProtocol, &MAVLinkProtocol::linkConnected);
connect(link, &LinkInterface::connected, mavlink, &MAVLinkProtocol::linkConnected); connect(link, &LinkInterface::disconnected, _mavlinkProtocol, &MAVLinkProtocol::linkDisconnected);
connect(link, &LinkInterface::disconnected, mavlink, &MAVLinkProtocol::linkDisconnected); _mavlinkProtocol->resetMetadataForLink(link);
mavlink->resetMetadataForLink(link);
connect(link, &LinkInterface::connected, this, &LinkManager::_linkConnected); connect(link, &LinkInterface::connected, this, &LinkManager::_linkConnected);
connect(link, &LinkInterface::disconnected, this, &LinkManager::_linkDisconnected); connect(link, &LinkInterface::disconnected, this, &LinkManager::_linkDisconnected);
} }
......
...@@ -34,6 +34,7 @@ This file is part of the PIXHAWK project ...@@ -34,6 +34,7 @@ This file is part of the PIXHAWK project
#include "LinkConfiguration.h" #include "LinkConfiguration.h"
#include "LinkInterface.h" #include "LinkInterface.h"
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "QGCToolbox.h"
// Links // Links
#ifndef __ios__ #ifndef __ios__
...@@ -48,12 +49,11 @@ This file is part of the PIXHAWK project ...@@ -48,12 +49,11 @@ This file is part of the PIXHAWK project
#endif #endif
#include "ProtocolInterface.h" #include "ProtocolInterface.h"
#include "QGCSingleton.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
Q_DECLARE_LOGGING_CATEGORY(LinkManagerLog) Q_DECLARE_LOGGING_CATEGORY(LinkManagerLog)
class LinkManagerTest; class QGCApplication;
/// Manage communication links /// Manage communication links
/// ///
...@@ -61,16 +61,16 @@ class LinkManagerTest; ...@@ -61,16 +61,16 @@ class LinkManagerTest;
/// links and takes care of connecting them as well assigning the correct /// links and takes care of connecting them as well assigning the correct
/// protocol instance to transport the link data into the application. /// protocol instance to transport the link data into the application.
class LinkManager : public QGCSingleton class LinkManager : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(LinkManager, LinkManager)
/// Unit Test has access to private constructor/destructor /// Unit Test has access to private constructor/destructor
friend class LinkManagerTest; friend class LinkManagerTest;
public: public:
LinkManager(QGCApplication* app);
~LinkManager();
/*! /*!
Add a new link configuration setting to the list Add a new link configuration setting to the list
...@@ -144,6 +144,9 @@ public: ...@@ -144,6 +144,9 @@ public:
void _deleteLink(LinkInterface* link); void _deleteLink(LinkInterface* link);
void _addLink(LinkInterface* link); void _addLink(LinkInterface* link);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
signals: signals:
void newLink(LinkInterface* link); void newLink(LinkInterface* link);
void linkDeleted(LinkInterface* link); void linkDeleted(LinkInterface* link);
...@@ -156,10 +159,6 @@ private slots: ...@@ -156,10 +159,6 @@ private slots:
void _linkDisconnected(void); void _linkDisconnected(void);
private: private:
/// All access to LinkManager is through LinkManager::instance
LinkManager(QObject* parent = NULL);
~LinkManager();
virtual void _shutdown(void); virtual void _shutdown(void);
bool _connectionsSuspendedMsg(void); bool _connectionsSuspendedMsg(void);
...@@ -186,6 +185,8 @@ private: ...@@ -186,6 +185,8 @@ private:
uint32_t _mavlinkChannelsUsedBitMask; uint32_t _mavlinkChannelsUsedBitMask;
SharedLinkInterface _nullSharedLink; SharedLinkInterface _nullSharedLink;
MAVLinkProtocol* _mavlinkProtocol;
}; };
#endif #endif
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "LogReplayLink.h" #include "LogReplayLink.h"
#include "LinkManager.h" #include "LinkManager.h"
#include "QGCApplication.h"
#include <QFileInfo> #include <QFileInfo>
#include <QtEndian> #include <QtEndian>
...@@ -101,7 +102,7 @@ LogReplayLink::~LogReplayLink(void) ...@@ -101,7 +102,7 @@ LogReplayLink::~LogReplayLink(void)
bool LogReplayLink::_connect(void) bool LogReplayLink::_connect(void)
{ {
// Disallow replay when any links are connected // Disallow replay when any links are connected
if (LinkManager::instance()->anyConnectedLinks()) { if (qgcApp()->toolbox()->linkManager()->anyConnectedLinks()) {
emit communicationError(_errorTitle, "You must close all connections prior to replaying a log."); emit communicationError(_errorTitle, "You must close all connections prior to replaying a log.");
return false; return false;
} }
...@@ -366,9 +367,9 @@ void LogReplayLink::_readNextLogEntry(void) ...@@ -366,9 +367,9 @@ void LogReplayLink::_readNextLogEntry(void)
void LogReplayLink::_play(void) void LogReplayLink::_play(void)
{ {
// FIXME: With move to link I don't think this is needed any more? Except for the replay widget handling multi-uas? // FIXME: With move to link I don't think this is needed any more? Except for the replay widget handling multi-uas?
LinkManager::instance()->setConnectionsSuspended(tr("Connect not allowed during Flight Data replay.")); qgcApp()->toolbox()->linkManager()->setConnectionsSuspended(tr("Connect not allowed during Flight Data replay."));
#ifndef __mobile__ #ifndef __mobile__
MAVLinkProtocol::instance()->suspendLogForReplay(true); qgcApp()->toolbox()->mavlinkProtocol()->suspendLogForReplay(true);
#endif #endif
// Make sure we aren't at the end of the file, if we are, reset to the beginning and play from there. // Make sure we aren't at the end of the file, if we are, reset to the beginning and play from there.
...@@ -398,9 +399,9 @@ void LogReplayLink::_play(void) ...@@ -398,9 +399,9 @@ void LogReplayLink::_play(void)
void LogReplayLink::_pause(void) void LogReplayLink::_pause(void)
{ {
LinkManager::instance()->setConnectionsAllowed(); qgcApp()->toolbox()->linkManager()->setConnectionsAllowed();
#ifndef __mobile__ #ifndef __mobile__
MAVLinkProtocol::instance()->suspendLogForReplay(false); qgcApp()->toolbox()->mavlinkProtocol()->suspendLogForReplay(false);
#endif #endif
_readTickTimer.stop(); _readTickTimer.stop();
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
Q_DECLARE_METATYPE(mavlink_message_t) Q_DECLARE_METATYPE(mavlink_message_t)
IMPLEMENT_QGC_SINGLETON(MAVLinkProtocol, MAVLinkProtocol)
QGC_LOGGING_CATEGORY(MAVLinkProtocolLog, "MAVLinkProtocolLog") QGC_LOGGING_CATEGORY(MAVLinkProtocolLog, "MAVLinkProtocolLog")
#ifndef __mobile__ #ifndef __mobile__
...@@ -42,53 +42,30 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext ...@@ -42,53 +42,30 @@ const char* MAVLinkProtocol::_logFileExtension = "mavlink"; ///< Ext
* The default constructor will create a new MAVLink object sending heartbeats at * The default constructor will create a new MAVLink object sending heartbeats at
* the MAVLINK_HEARTBEAT_DEFAULT_RATE to all connected links. * the MAVLINK_HEARTBEAT_DEFAULT_RATE to all connected links.
*/ */
MAVLinkProtocol::MAVLinkProtocol(QObject* parent) : MAVLinkProtocol::MAVLinkProtocol(QGCApplication* app)
QGCSingleton(parent), : QGCTool(app)
m_multiplexingEnabled(false), , m_multiplexingEnabled(false)
m_authEnabled(false), , m_authEnabled(false)
m_enable_version_check(true), , m_enable_version_check(true)
m_paramRetransmissionTimeout(350), , m_paramRetransmissionTimeout(350)
m_paramRewriteTimeout(500), , m_paramRewriteTimeout(500)
m_paramGuardEnabled(true), , m_paramGuardEnabled(true)
m_actionGuardEnabled(false), , m_actionGuardEnabled(false)
m_actionRetransmissionTimeout(100), , m_actionRetransmissionTimeout(100)
versionMismatchIgnore(false), , versionMismatchIgnore(false)
systemId(QGC::defaultSystemId), , systemId(QGC::defaultSystemId)
#ifndef __mobile__ #ifndef __mobile__
_logSuspendError(false), , _logSuspendError(false)
_logSuspendReplay(false), , _logSuspendReplay(false)
_logWasArmed(false), , _logWasArmed(false)
_tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension)), , _tempLogFile(QString("%2.%3").arg(_tempLogFileTemplate).arg(_logFileExtension))
#endif #endif
_linkMgr(LinkManager::instance()), , _heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE)
_heartbeatRate(MAVLINK_HEARTBEAT_DEFAULT_RATE), , _heartbeatsEnabled(true)
_heartbeatsEnabled(true) , _linkMgr(NULL)
, _multiVehicleManager(NULL)
{ {
qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
loadSettings();
// All the *Counter variables are not initialized here, as they should be initialized
// on a per-link basis before those links are used. @see resetMetadataForLink().
// Initialize the list for tracking dropped messages to invalid.
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 256; j++)
{
lastIndex[i][j] = -1;
}
}
// Start heartbeat timer, emitting a heartbeat at the configured rate
connect(&_heartbeatTimer, &QTimer::timeout, this, &MAVLinkProtocol::sendHeartbeat);
_heartbeatTimer.start(1000/_heartbeatRate);
connect(this, &MAVLinkProtocol::protocolStatusMessage, qgcApp(), &QGCApplication::criticalMessageBoxOnMainThread);
connect(this, &MAVLinkProtocol::saveTempFlightDataLog, qgcApp(), &QGCApplication::saveTempFlightDataLogOnMainThread);
emit versionCheckChanged(m_enable_version_check);
} }
MAVLinkProtocol::~MAVLinkProtocol() MAVLinkProtocol::~MAVLinkProtocol()
...@@ -100,6 +77,40 @@ MAVLinkProtocol::~MAVLinkProtocol() ...@@ -100,6 +77,40 @@ MAVLinkProtocol::~MAVLinkProtocol()
#endif #endif
} }
void MAVLinkProtocol::setToolbox(QGCToolbox *toolbox)
{
QGCTool::setToolbox(toolbox);
_linkMgr = _toolbox->linkManager();
_multiVehicleManager = _toolbox->multiVehicleManager();
qRegisterMetaType<mavlink_message_t>("mavlink_message_t");
m_authKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
loadSettings();
// All the *Counter variables are not initialized here, as they should be initialized
// on a per-link basis before those links are used. @see resetMetadataForLink().
// Initialize the list for tracking dropped messages to invalid.
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 256; j++)
{
lastIndex[i][j] = -1;
}
}
// Start heartbeat timer, emitting a heartbeat at the configured rate
connect(&_heartbeatTimer, &QTimer::timeout, this, &MAVLinkProtocol::sendHeartbeat);
_heartbeatTimer.start(1000/_heartbeatRate);
connect(this, &MAVLinkProtocol::protocolStatusMessage, _app, &QGCApplication::criticalMessageBoxOnMainThread);
connect(this, &MAVLinkProtocol::saveTempFlightDataLog, _app, &QGCApplication::saveTempFlightDataLogOnMainThread);
emit versionCheckChanged(m_enable_version_check);
}
void MAVLinkProtocol::loadSettings() void MAVLinkProtocol::loadSettings()
{ {
// Load defaults from settings // Load defaults from settings
...@@ -185,7 +196,7 @@ void MAVLinkProtocol::_linkStatusChanged(LinkInterface* link, bool connected) ...@@ -185,7 +196,7 @@ void MAVLinkProtocol::_linkStatusChanged(LinkInterface* link, bool connected)
} }
// Use the same shared pointer as LinkManager // Use the same shared pointer as LinkManager
_connectedLinks.append(LinkManager::instance()->sharedPointerForLink(link)); _connectedLinks.append(_linkMgr->sharedPointerForLink(link));
#ifndef __mobile__ #ifndef __mobile__
if (_connectedLinks.count() == 1) { if (_connectedLinks.count() == 1) {
...@@ -235,7 +246,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) ...@@ -235,7 +246,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
// Since receiveBytes signals cross threads we can end up with signals in the queue // Since receiveBytes signals cross threads we can end up with signals in the queue
// that come through after the link is disconnected. For these we just drop the data // that come through after the link is disconnected. For these we just drop the data
// since the link is closed. // since the link is closed.
if (!LinkManager::instance()->containsLink(link)) { if (!_linkMgr->containsLink(link)) {
return; return;
} }
...@@ -356,7 +367,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b) ...@@ -356,7 +367,7 @@ void MAVLinkProtocol::receiveBytes(LinkInterface* link, QByteArray b)
// Notify the vehicle manager of the heartbeat. This will create/update vehicles as needed. // Notify the vehicle manager of the heartbeat. This will create/update vehicles as needed.
mavlink_heartbeat_t heartbeat; mavlink_heartbeat_t heartbeat;
mavlink_msg_heartbeat_decode(&message, &heartbeat); mavlink_msg_heartbeat_decode(&message, &heartbeat);
if (!MultiVehicleManager::instance()->notifyHeartbeatInfo(link, message.sysid, heartbeat)) { if (!_multiVehicleManager->notifyHeartbeatInfo(link, message.sysid, heartbeat)) {
continue; continue;
} }
} }
...@@ -667,7 +678,7 @@ void MAVLinkProtocol::_stopLogging(void) ...@@ -667,7 +678,7 @@ void MAVLinkProtocol::_stopLogging(void)
{ {
if (_closeLogFile()) { if (_closeLogFile()) {
// If the signals are not connected it means we are running a unit test. In that case just delete log files // If the signals are not connected it means we are running a unit test. In that case just delete log files
if (_logWasArmed && qgcApp()->promptFlightDataSave()) { if (_logWasArmed && _app->promptFlightDataSave()) {
emit saveTempFlightDataLog(_tempLogFile.fileName()); emit saveTempFlightDataLog(_tempLogFile.fileName());
} else { } else {
QFile::remove(_tempLogFile.fileName()); QFile::remove(_tempLogFile.fileName());
......
...@@ -43,9 +43,11 @@ This file is part of the QGROUNDCONTROL project ...@@ -43,9 +43,11 @@ This file is part of the QGROUNDCONTROL project
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QGC.h" #include "QGC.h"
#include "QGCTemporaryFile.h" #include "QGCTemporaryFile.h"
#include "QGCSingleton.h" #include "QGCToolbox.h"
class LinkManager; class LinkManager;
class MultiVehicleManager;
class QGCApplication;
Q_DECLARE_LOGGING_CATEGORY(MAVLinkProtocolLog) Q_DECLARE_LOGGING_CATEGORY(MAVLinkProtocolLog)
...@@ -56,13 +58,14 @@ Q_DECLARE_LOGGING_CATEGORY(MAVLinkProtocolLog) ...@@ -56,13 +58,14 @@ Q_DECLARE_LOGGING_CATEGORY(MAVLinkProtocolLog)
* for more information, please see the official website. * for more information, please see the official website.
* @ref http://pixhawk.ethz.ch/software/mavlink/ * @ref http://pixhawk.ethz.ch/software/mavlink/
**/ **/
class MAVLinkProtocol : public QGCSingleton class MAVLinkProtocol : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(MAVLinkProtocol, MAVLinkProtocol)
public: public:
MAVLinkProtocol(QGCApplication* app);
~MAVLinkProtocol();
/** @brief Get the human-friendly name of this protocol */ /** @brief Get the human-friendly name of this protocol */
QString getName(); QString getName();
/** @brief Get the system id of this application */ /** @brief Get the system id of this application */
...@@ -145,6 +148,9 @@ public: ...@@ -145,6 +148,9 @@ public:
/// Suspend/Restart logging during replay. /// Suspend/Restart logging during replay.
void suspendLogForReplay(bool suspend); void suspendLogForReplay(bool suspend);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
public slots: public slots:
/** @brief Receive bytes from a communication interface */ /** @brief Receive bytes from a communication interface */
void receiveBytes(LinkInterface* link, QByteArray b); void receiveBytes(LinkInterface* link, QByteArray b);
...@@ -279,9 +285,6 @@ signals: ...@@ -279,9 +285,6 @@ signals:
void saveTempFlightDataLog(QString tempLogfile); void saveTempFlightDataLog(QString tempLogfile);
private: private:
MAVLinkProtocol(QObject* parent = NULL);
~MAVLinkProtocol();
void _linkStatusChanged(LinkInterface* link, bool connected); void _linkStatusChanged(LinkInterface* link, bool connected);
#ifndef __mobile__ #ifndef __mobile__
...@@ -303,11 +306,12 @@ private: ...@@ -303,11 +306,12 @@ private:
/// This way Link deletion works correctly. /// This way Link deletion works correctly.
QList<SharedLinkInterface> _connectedLinks; QList<SharedLinkInterface> _connectedLinks;
LinkManager* _linkMgr;
QTimer _heartbeatTimer; ///< Timer to emit heartbeats QTimer _heartbeatTimer; ///< Timer to emit heartbeats
int _heartbeatRate; ///< Heartbeat rate, controls the timer interval int _heartbeatRate; ///< Heartbeat rate, controls the timer interval
bool _heartbeatsEnabled; ///< Enabled/disable heartbeat emission bool _heartbeatsEnabled; ///< Enabled/disable heartbeat emission
LinkManager* _linkMgr;
MultiVehicleManager* _multiVehicleManager;
}; };
#endif // MAVLINKPROTOCOL_H_ #endif // MAVLINKPROTOCOL_H_
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "MockLink.h" #include "MockLink.h"
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "QGCApplication.h"
#include <QTimer> #include <QTimer>
#include <QDebug> #include <QDebug>
...@@ -76,7 +77,7 @@ const char* MockConfiguration::_vehicleTypeKey = "VehicleType"; ...@@ -76,7 +77,7 @@ const char* MockConfiguration::_vehicleTypeKey = "VehicleType";
const char* MockConfiguration::_sendStatusTextKey = "SendStatusText"; const char* MockConfiguration::_sendStatusTextKey = "SendStatusText";
MockLink::MockLink(MockConfiguration* config) MockLink::MockLink(MockConfiguration* config)
: _missionItemHandler(this) : _missionItemHandler(this, qgcApp()->toolbox()->mavlinkProtocol())
, _name("MockLink") , _name("MockLink")
, _connected(false) , _connected(false)
, _vehicleSystemId(128) // FIXME: Pull from eventual parameter manager , _vehicleSystemId(128) // FIXME: Pull from eventual parameter manager
......
...@@ -28,11 +28,12 @@ ...@@ -28,11 +28,12 @@
QGC_LOGGING_CATEGORY(MockLinkMissionItemHandlerLog, "MockLinkMissionItemHandlerLog") QGC_LOGGING_CATEGORY(MockLinkMissionItemHandlerLog, "MockLinkMissionItemHandlerLog")
MockLinkMissionItemHandler::MockLinkMissionItemHandler(MockLink* mockLink) MockLinkMissionItemHandler::MockLinkMissionItemHandler(MockLink* mockLink, MAVLinkProtocol* mavlinkProtocol)
: _mockLink(mockLink) : _mockLink(mockLink)
, _missionItemResponseTimer(NULL) , _missionItemResponseTimer(NULL)
, _failureMode(FailNone) , _failureMode(FailNone)
, _sendHomePositionOnEmptyList(false) , _sendHomePositionOnEmptyList(false)
, _mavlinkProtocol(mavlinkProtocol)
{ {
Q_ASSERT(mockLink); Q_ASSERT(mockLink);
} }
...@@ -234,8 +235,8 @@ void MockLinkMissionItemHandler::_requestNextMissionItem(int sequenceNumber) ...@@ -234,8 +235,8 @@ void MockLinkMissionItemHandler::_requestNextMissionItem(int sequenceNumber)
mavlink_message_t message; mavlink_message_t message;
mavlink_mission_request_t missionRequest; mavlink_mission_request_t missionRequest;
missionRequest.target_system = MAVLinkProtocol::instance()->getSystemId(); missionRequest.target_system = _mavlinkProtocol->getSystemId();
missionRequest.target_component = MAVLinkProtocol::instance()->getComponentId(); missionRequest.target_component = _mavlinkProtocol->getComponentId();
missionRequest.seq = sequenceNumber; missionRequest.seq = sequenceNumber;
mavlink_msg_mission_request_encode(_mockLink->vehicleId(), MAV_COMP_ID_MISSIONPLANNER, &message, &missionRequest); mavlink_msg_mission_request_encode(_mockLink->vehicleId(), MAV_COMP_ID_MISSIONPLANNER, &message, &missionRequest);
...@@ -258,8 +259,8 @@ void MockLinkMissionItemHandler::_sendAck(MAV_MISSION_RESULT ackType) ...@@ -258,8 +259,8 @@ void MockLinkMissionItemHandler::_sendAck(MAV_MISSION_RESULT ackType)
mavlink_message_t message; mavlink_message_t message;
mavlink_mission_ack_t missionAck; mavlink_mission_ack_t missionAck;
missionAck.target_system = MAVLinkProtocol::instance()->getSystemId(); missionAck.target_system = _mavlinkProtocol->getSystemId();
missionAck.target_component = MAVLinkProtocol::instance()->getComponentId(); missionAck.target_component = _mavlinkProtocol->getComponentId();
missionAck.type = ackType; missionAck.type = ackType;
mavlink_msg_mission_ack_encode(_mockLink->vehicleId(), MAV_COMP_ID_MISSIONPLANNER, &message, &missionAck); mavlink_msg_mission_ack_encode(_mockLink->vehicleId(), MAV_COMP_ID_MISSIONPLANNER, &message, &missionAck);
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "MAVLinkProtocol.h"
class MockLink; class MockLink;
...@@ -40,7 +41,7 @@ class MockLinkMissionItemHandler : public QObject ...@@ -40,7 +41,7 @@ class MockLinkMissionItemHandler : public QObject
Q_OBJECT Q_OBJECT
public: public:
MockLinkMissionItemHandler(MockLink* mockLink); MockLinkMissionItemHandler(MockLink* mockLink, MAVLinkProtocol* mavlinkProtocol);
~MockLinkMissionItemHandler(); ~MockLinkMissionItemHandler();
// Prepares for destruction on correct thread // Prepares for destruction on correct thread
...@@ -111,10 +112,11 @@ private: ...@@ -111,10 +112,11 @@ private:
typedef QMap<uint16_t, mavlink_mission_item_t> MissionList_t; typedef QMap<uint16_t, mavlink_mission_item_t> MissionList_t;
MissionList_t _missionItems; MissionList_t _missionItems;
QTimer* _missionItemResponseTimer; QTimer* _missionItemResponseTimer;
FailureMode_t _failureMode; FailureMode_t _failureMode;
bool _failureFirstTimeOnly; bool _failureFirstTimeOnly;
bool _sendHomePositionOnEmptyList; bool _sendHomePositionOnEmptyList;
MAVLinkProtocol* _mavlinkProtocol;
}; };
#endif #endif
...@@ -46,6 +46,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -46,6 +46,7 @@ This file is part of the QGROUNDCONTROL project
#include "QGCFileDialog.h" #include "QGCFileDialog.h"
#include "QGCMessageBox.h" #include "QGCMessageBox.h"
#include "HomePositionManager.h" #include "HomePositionManager.h"
#include "QGCApplication.h"
// FlightGear _fgProcess start and connection is quite fragile. Uncomment the define below to get higher level of debug output // FlightGear _fgProcess start and connection is quite fragile. Uncomment the define below to get higher level of debug output
// for tracking down problems. // for tracking down problems.
...@@ -957,11 +958,11 @@ bool QGCFlightGearLink::connectSimulation() ...@@ -957,11 +958,11 @@ bool QGCFlightGearLink::connectSimulation()
} }
// We start out at our home position // We start out at our home position
_fgArgList << QString("--lat=%1").arg(HomePositionManager::instance()->getHomeLatitude()); _fgArgList << QString("--lat=%1").arg(qgcApp()->toolbox()->homePositionManager()->getHomeLatitude());
_fgArgList << QString("--lon=%1").arg(HomePositionManager::instance()->getHomeLongitude()); _fgArgList << QString("--lon=%1").arg(qgcApp()->toolbox()->homePositionManager()->getHomeLongitude());
// The altitude is not set because an altitude not equal to the ground altitude leads to a non-zero default throttle in flightgear // The altitude is not set because an altitude not equal to the ground altitude leads to a non-zero default throttle in flightgear
// Without the altitude-setting the aircraft is positioned on the ground // Without the altitude-setting the aircraft is positioned on the ground
//_fgArgList << QString("--altitude=%1").arg(HomePositionManager::instance()->getHomeAltitude()); //_fgArgList << QString("--altitude=%1").arg(qgcApp()->toolbox()->homePositionManager()->getHomeAltitude());
#ifdef DEBUG_FLIGHTGEAR_CONNECT #ifdef DEBUG_FLIGHTGEAR_CONNECT
// This tell FlightGear to output highest debug level of log output. Handy for debuggin failures by looking at the FG // This tell FlightGear to output highest debug level of log output. Handy for debuggin failures by looking at the FG
......
...@@ -133,7 +133,7 @@ bool SerialLink::_disconnect(void) ...@@ -133,7 +133,7 @@ bool SerialLink::_disconnect(void)
} }
#ifdef __android__ #ifdef __android__
LinkManager::instance()->suspendConfigurationUpdates(false); qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(false);
#endif #endif
return true; return true;
} }
...@@ -150,7 +150,7 @@ bool SerialLink::_connect(void) ...@@ -150,7 +150,7 @@ bool SerialLink::_connect(void)
_disconnect(); _disconnect();
#ifdef __android__ #ifdef __android__
LinkManager::instance()->suspendConfigurationUpdates(true); qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(true);
#endif #endif
// Initialize the connection // Initialize the connection
......
...@@ -38,7 +38,7 @@ Mouse6dofInput::Mouse6dofInput(Mouse3DInput* mouseInput) : ...@@ -38,7 +38,7 @@ Mouse6dofInput::Mouse6dofInput(Mouse3DInput* mouseInput) :
bValue(0.0), bValue(0.0),
cValue(0.0) cValue(0.0)
{ {
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged);
// Connect 3DxWare SDK MotionEvent // Connect 3DxWare SDK MotionEvent
connect(mouseInput, SIGNAL(Move3d(std::vector<float>&)), this, SLOT(motion3DMouse(std::vector<float>&))); connect(mouseInput, SIGNAL(Move3d(std::vector<float>&)), this, SLOT(motion3DMouse(std::vector<float>&)));
...@@ -63,7 +63,7 @@ Mouse6dofInput::Mouse6dofInput(QWidget* parent) : ...@@ -63,7 +63,7 @@ Mouse6dofInput::Mouse6dofInput(QWidget* parent) :
bValue(0.0), bValue(0.0),
cValue(0.0) cValue(0.0)
{ {
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &Mouse6dofInput::_activeVehicleChanged);
if (!mouseActive) if (!mouseActive)
{ {
...@@ -137,7 +137,7 @@ void Mouse6dofInput::_activeVehicleChanged(Vehicle* vehicle) ...@@ -137,7 +137,7 @@ void Mouse6dofInput::_activeVehicleChanged(Vehicle* vehicle)
void Mouse6dofInput::init() void Mouse6dofInput::init()
{ {
// Make sure active UAS is set // Make sure active UAS is set
_activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle()); _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
} }
void Mouse6dofInput::run() void Mouse6dofInput::run()
......
...@@ -27,14 +27,14 @@ ...@@ -27,14 +27,14 @@
#include "FileManagerTest.h" #include "FileManagerTest.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "UAS.h" #include "UAS.h"
#include "QGCApplication.h"
//UT_REGISTER_TEST(FileManagerTest) //UT_REGISTER_TEST(FileManagerTest)
FileManagerTest::FileManagerTest(void) : FileManagerTest::FileManagerTest(void)
_mockLink(NULL), : _fileServer(NULL)
_fileServer(NULL), , _fileManager(NULL)
_fileManager(NULL), , _multiSpy(NULL)
_multiSpy(NULL)
{ {
} }
...@@ -44,24 +44,12 @@ void FileManagerTest::init(void) ...@@ -44,24 +44,12 @@ void FileManagerTest::init(void)
{ {
UnitTest::init(); UnitTest::init();
_mockLink = new MockLink(); _connectMockLink();
Q_CHECK_PTR(_mockLink);
LinkManager::instance()->_addLink(_mockLink);
LinkManager::instance()->connectLink(_mockLink);
_fileServer = _mockLink->getFileServer(); _fileServer = _mockLink->getFileServer();
QVERIFY(_fileServer != NULL); QVERIFY(_fileServer != NULL);
// Wait or the Vehicle to show up _fileManager = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->uas()->getFileManager();
MultiVehicleManager* vehicleManager = MultiVehicleManager::instance();
QSignalSpy spyVehicleCreate(vehicleManager, SIGNAL(activeVehicleChanged(Vehicle*)));
if (!vehicleManager->activeVehicle()) {
QCOMPARE(spyVehicleCreate.wait(10000), true);
}
UASInterface* uas = vehicleManager->activeVehicle()->uas();
QVERIFY(uas != NULL);
_fileManager = uas->getFileManager();
QVERIFY(_fileManager != NULL); QVERIFY(_fileManager != NULL);
Q_ASSERT(_multiSpy == NULL); Q_ASSERT(_multiSpy == NULL);
...@@ -89,9 +77,9 @@ void FileManagerTest::cleanup(void) ...@@ -89,9 +77,9 @@ void FileManagerTest::cleanup(void)
// Disconnecting the link will prompt for log file save // Disconnecting the link will prompt for log file save
setExpectedFileDialog(getSaveFileName, QStringList()); setExpectedFileDialog(getSaveFileName, QStringList());
LinkManager::instance()->disconnectLink(_mockLink); _disconnectMockLink();
_fileServer = NULL; _fileServer = NULL;
_mockLink = NULL;
_fileManager = NULL; _fileManager = NULL;
delete _multiSpy; delete _multiSpy;
......
...@@ -76,7 +76,6 @@ private: ...@@ -76,7 +76,6 @@ private:
static const uint8_t _systemIdQGC = 255; static const uint8_t _systemIdQGC = 255;
static const uint8_t _systemIdServer = 128; static const uint8_t _systemIdServer = 128;
MockLink* _mockLink;
MockLinkFileServer* _fileServer; MockLinkFileServer* _fileServer;
FileManager* _fileManager; FileManager* _fileManager;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "LinkManagerTest.h" #include "LinkManagerTest.h"
#include "MockLink.h" #include "MockLink.h"
#include "QGCApplication.h"
UT_REGISTER_TEST(LinkManagerTest) UT_REGISTER_TEST(LinkManagerTest)
...@@ -45,7 +46,7 @@ void LinkManagerTest::init(void) ...@@ -45,7 +46,7 @@ void LinkManagerTest::init(void)
Q_ASSERT(_linkMgr == NULL); Q_ASSERT(_linkMgr == NULL);
Q_ASSERT(_multiSpy == NULL); Q_ASSERT(_multiSpy == NULL);
_linkMgr = new LinkManager(NULL /* no parent */); _linkMgr = qgcApp()->toolbox()->linkManager();
Q_CHECK_PTR(_linkMgr); Q_CHECK_PTR(_linkMgr);
_rgSignals[newLinkSignalIndex] = SIGNAL(newLink(LinkInterface*)); _rgSignals[newLinkSignalIndex] = SIGNAL(newLink(LinkInterface*));
...@@ -60,9 +61,6 @@ void LinkManagerTest::cleanup(void) ...@@ -60,9 +61,6 @@ void LinkManagerTest::cleanup(void)
Q_ASSERT(_linkMgr); Q_ASSERT(_linkMgr);
Q_ASSERT(_multiSpy); Q_ASSERT(_multiSpy);
_linkMgr->_shutdown();
delete _linkMgr;
delete _multiSpy; delete _multiSpy;
_linkMgr = NULL; _linkMgr = NULL;
...@@ -77,12 +75,11 @@ void LinkManagerTest::_add_test(void) ...@@ -77,12 +75,11 @@ void LinkManagerTest::_add_test(void)
Q_ASSERT(_linkMgr); Q_ASSERT(_linkMgr);
Q_ASSERT(_linkMgr->getLinks().count() == 0); Q_ASSERT(_linkMgr->getLinks().count() == 0);
MockLink* link = new MockLink(); _connectMockLink();
_linkMgr->_addLink(link);
QList<LinkInterface*> links = _linkMgr->getLinks(); QList<LinkInterface*> links = _linkMgr->getLinks();
QCOMPARE(links.count(), 1); QCOMPARE(links.count(), 1);
QCOMPARE(dynamic_cast<MockLink*>(links[0]), link); QCOMPARE(dynamic_cast<MockLink*>(links[0]), _mockLink);
} }
void LinkManagerTest::_delete_test(void) void LinkManagerTest::_delete_test(void)
...@@ -90,9 +87,8 @@ void LinkManagerTest::_delete_test(void) ...@@ -90,9 +87,8 @@ void LinkManagerTest::_delete_test(void)
Q_ASSERT(_linkMgr); Q_ASSERT(_linkMgr);
Q_ASSERT(_linkMgr->getLinks().count() == 0); Q_ASSERT(_linkMgr->getLinks().count() == 0);
MockLink* link = new MockLink(); _connectMockLink();
_linkMgr->_addLink(link); _disconnectMockLink();
_linkMgr->_deleteLink(link);
QCOMPARE(_linkMgr->getLinks().count(), 0); QCOMPARE(_linkMgr->getLinks().count(), 0);
} }
...@@ -103,9 +99,8 @@ void LinkManagerTest::_addSignals_test(void) ...@@ -103,9 +99,8 @@ void LinkManagerTest::_addSignals_test(void)
Q_ASSERT(_linkMgr->getLinks().count() == 0); Q_ASSERT(_linkMgr->getLinks().count() == 0);
Q_ASSERT(_multiSpy->checkNoSignals() == true); Q_ASSERT(_multiSpy->checkNoSignals() == true);
MockLink* link = new MockLink(); _connectMockLink();
_linkMgr->_addLink(link);
QCOMPARE(_multiSpy->checkOnlySignalByMask(newLinkSignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(newLinkSignalMask), true);
QSignalSpy* spy = _multiSpy->getSpyByIndex(newLinkSignalIndex); QSignalSpy* spy = _multiSpy->getSpyByIndex(newLinkSignalIndex);
...@@ -115,7 +110,7 @@ void LinkManagerTest::_addSignals_test(void) ...@@ -115,7 +110,7 @@ void LinkManagerTest::_addSignals_test(void)
QObject* object = qvariant_cast<QObject *>(signalArgs[0]); QObject* object = qvariant_cast<QObject *>(signalArgs[0]);
QVERIFY(object != NULL); QVERIFY(object != NULL);
MockLink* signalLink = qobject_cast<MockLink*>(object); MockLink* signalLink = qobject_cast<MockLink*>(object);
QCOMPARE(signalLink, link); QCOMPARE(signalLink, _mockLink);
} }
void LinkManagerTest::_deleteSignals_test(void) void LinkManagerTest::_deleteSignals_test(void)
...@@ -124,11 +119,9 @@ void LinkManagerTest::_deleteSignals_test(void) ...@@ -124,11 +119,9 @@ void LinkManagerTest::_deleteSignals_test(void)
Q_ASSERT(_linkMgr->getLinks().count() == 0); Q_ASSERT(_linkMgr->getLinks().count() == 0);
Q_ASSERT(_multiSpy->checkNoSignals() == true); Q_ASSERT(_multiSpy->checkNoSignals() == true);
MockLink* link = new MockLink(); _connectMockLink();
_linkMgr->_addLink(link);
_multiSpy->clearAllSignals(); _multiSpy->clearAllSignals();
_disconnectMockLink();
_linkMgr->_deleteLink(link);
QCOMPARE(_multiSpy->checkOnlySignalByMask(linkDeletedSignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(linkDeletedSignalMask), true);
QSignalSpy* spy = _multiSpy->getSpyByIndex(linkDeletedSignalIndex); QSignalSpy* spy = _multiSpy->getSpyByIndex(linkDeletedSignalIndex);
......
...@@ -31,56 +31,18 @@ ...@@ -31,56 +31,18 @@
#include "QGCMessageBox.h" #include "QGCMessageBox.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
UT_REGISTER_TEST(MainWindowTest) // FIXME: Temporarily turned off
//UT_REGISTER_TEST(MainWindowTest)
MainWindowTest::MainWindowTest(void) :
_mainWindow()
{
}
void MainWindowTest::init(void)
{
UnitTest::init();
_mainWindow = MainWindow::_create();
Q_CHECK_PTR(_mainWindow);
}
void MainWindowTest::cleanup(void)
{
_mainWindow->close();
QTest::qWait(200);
delete _mainWindow;
UnitTest::cleanup();
}
void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot) void MainWindowTest::_connectWindowClose_test(MAV_AUTOPILOT autopilot)
{ {
LinkManager* linkMgr = LinkManager::instance(); _createMainWindow();
Q_CHECK_PTR(linkMgr); _connectMockLink(autopilot);
MockLink* link = new MockLink();
Q_CHECK_PTR(link);
link->setFirmwareType(autopilot);
LinkManager::instance()->_addLink(link);
linkMgr->connectLink(link);
// Wait for the Vehicle to work it's way through the various threads
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(activeVehicleChanged(Vehicle*)));
QCOMPARE(spyVehicle.wait(5000), true);
// On MainWindow close we should get a message box telling the user to disconnect first. Cancel should do nothing. // On MainWindow close we should get a message box telling the user to disconnect first. Cancel should do nothing.
setExpectedMessageBox(QGCMessageBox::Cancel); setExpectedMessageBox(QGCMessageBox::Cancel);
_mainWindow->close(); _closeMainWindow(true /* cancelExpected */);
QTest::qWait(1000); // Need to allow signals to move between threads
checkExpectedMessageBox(); checkExpectedMessageBox();
linkMgr->disconnectLink(link);
QTest::qWait(1000); // Need to allow signals to move between threads
} }
void MainWindowTest::_connectWindowClosePX4_test(void) { void MainWindowTest::_connectWindowClosePX4_test(void) {
......
...@@ -36,20 +36,12 @@ class MainWindowTest : public UnitTest ...@@ -36,20 +36,12 @@ class MainWindowTest : public UnitTest
{ {
Q_OBJECT Q_OBJECT
public:
MainWindowTest(void);
private slots: private slots:
void init(void);
void cleanup(void);
void _connectWindowClosePX4_test(void); void _connectWindowClosePX4_test(void);
void _connectWindowCloseGeneric_test(void); void _connectWindowCloseGeneric_test(void);
private: private:
void _connectWindowClose_test(MAV_AUTOPILOT autopilot); void _connectWindowClose_test(MAV_AUTOPILOT autopilot);
MainWindow* _mainWindow;
}; };
#endif #endif
...@@ -92,7 +92,7 @@ void MavlinkLogTest::_bootLogDetectionCancel_test(void) ...@@ -92,7 +92,7 @@ void MavlinkLogTest::_bootLogDetectionCancel_test(void)
setExpectedFileDialog(getSaveFileName, QStringList()); setExpectedFileDialog(getSaveFileName, QStringList());
// Kick the protocol to check for lost log files and wait for signals to move through // Kick the protocol to check for lost log files and wait for signals to move through
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles); connect(this, &MavlinkLogTest::checkForLostLogFiles, qgcApp()->toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles(); emit checkForLostLogFiles();
QTest::qWait(1000); QTest::qWait(1000);
...@@ -112,7 +112,7 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void) ...@@ -112,7 +112,7 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void)
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
// Kick the protocol to check for lost log files and wait for signals to move through // Kick the protocol to check for lost log files and wait for signals to move through
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles); connect(this, &MavlinkLogTest::checkForLostLogFiles, qgcApp()->toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles(); emit checkForLostLogFiles();
QTest::qWait(1000); QTest::qWait(1000);
...@@ -129,7 +129,7 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) ...@@ -129,7 +129,7 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void)
_createTempLogFile(true); _createTempLogFile(true);
// Kick the protocol to check for lost log files and wait for signals to move through // Kick the protocol to check for lost log files and wait for signals to move through
connect(this, &MavlinkLogTest::checkForLostLogFiles, MAVLinkProtocol::instance(), &MAVLinkProtocol::checkForLostLogFiles); connect(this, &MavlinkLogTest::checkForLostLogFiles, qgcApp()->toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles(); emit checkForLostLogFiles();
QTest::qWait(1000); QTest::qWait(1000);
...@@ -138,23 +138,12 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void) ...@@ -138,23 +138,12 @@ void MavlinkLogTest::_bootLogDetectionZeroLength_test(void)
void MavlinkLogTest::_connectLogWorker(bool arm) void MavlinkLogTest::_connectLogWorker(bool arm)
{ {
LinkManager* linkMgr = LinkManager::instance(); _connectMockLink();
Q_CHECK_PTR(linkMgr);
MockLink* link = new MockLink();
Q_CHECK_PTR(link);
LinkManager::instance()->_addLink(link);
linkMgr->connectLink(link);
// Wait for the uas to work it's way through the various threads
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(activeVehicleChanged(Vehicle*)));
QCOMPARE(spyVehicle.wait(5000), true);
QDir logSaveDir; QDir logSaveDir;
if (arm) { if (arm) {
MultiVehicleManager::instance()->activeVehicle()->setArmed(true); qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->setArmed(true);
QTest::qWait(1500); // Wait long enough for heartbeat to come through QTest::qWait(1500); // Wait long enough for heartbeat to come through
// On Disconnect: We should get a getSaveFileName dialog. // On Disconnect: We should get a getSaveFileName dialog.
...@@ -163,8 +152,7 @@ void MavlinkLogTest::_connectLogWorker(bool arm) ...@@ -163,8 +152,7 @@ void MavlinkLogTest::_connectLogWorker(bool arm)
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile)); setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
} }
linkMgr->disconnectLink(link); _disconnectMockLink();
QTest::qWait(1000); // Need to allow signals to move between threads
if (arm) { if (arm) {
checkExpectedFileDialog(); checkExpectedFileDialog();
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "PX4RCCalibrationTest.h" #include "PX4RCCalibrationTest.h"
#include "RadioComponentController.h" #include "RadioComponentController.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "QGCApplication.h"
/// @file /// @file
/// @brief QRadioComponentController Widget unit test /// @brief QRadioComponentController Widget unit test
...@@ -149,18 +150,9 @@ void RadioConfigTest::init(void) ...@@ -149,18 +150,9 @@ void RadioConfigTest::init(void)
{ {
UnitTest::init(); UnitTest::init();
_mockLink = new MockLink(); _connectMockLink();
Q_CHECK_PTR(_mockLink);
LinkManager::instance()->_addLink(_mockLink);
LinkManager::instance()->connectLink(_mockLink);
// Wait for the Vehicle to get created _autopilot = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->autopilotPlugin();
QSignalSpy spyVehicle(MultiVehicleManager::instance(), SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
QCOMPARE(spyVehicle.wait(5000), true);
QVERIFY(MultiVehicleManager::instance()->parameterReadyVehicleAvailable());
QVERIFY(MultiVehicleManager::instance()->activeVehicle());
_autopilot = MultiVehicleManager::instance()->activeVehicle()->autopilotPlugin();
Q_ASSERT(_autopilot); Q_ASSERT(_autopilot);
// This will instatiate the widget with an active uas with ready parameters // This will instatiate the widget with an active uas with ready parameters
...@@ -192,8 +184,6 @@ void RadioConfigTest::cleanup(void) ...@@ -192,8 +184,6 @@ void RadioConfigTest::cleanup(void)
// Disconnecting the link will prompt for log file save // Disconnecting the link will prompt for log file save
setExpectedFileDialog(getSaveFileName, QStringList()); setExpectedFileDialog(getSaveFileName, QStringList());
LinkManager::instance()->disconnectLink(_mockLink);
UnitTest::cleanup(); UnitTest::cleanup();
} }
......
...@@ -94,7 +94,6 @@ private: ...@@ -94,7 +94,6 @@ private:
void _validateParameters(void); void _validateParameters(void);
MockLink* _mockLink;
AutoPilotPlugin* _autopilot; AutoPilotPlugin* _autopilot;
QGCQmlWidgetHolder* _calWidget; QGCQmlWidgetHolder* _calWidget;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "UnitTest.h" #include "UnitTest.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "MainWindow.h"
bool UnitTest::_messageBoxRespondedTo = false; bool UnitTest::_messageBoxRespondedTo = false;
bool UnitTest::_badResponseButton = false; bool UnitTest::_badResponseButton = false;
...@@ -41,14 +42,17 @@ QStringList UnitTest::_fileDialogResponse; ...@@ -41,14 +42,17 @@ QStringList UnitTest::_fileDialogResponse;
enum UnitTest::FileDialogType UnitTest::_fileDialogExpectedType = getOpenFileName; enum UnitTest::FileDialogType UnitTest::_fileDialogExpectedType = getOpenFileName;
int UnitTest::_missedFileDialogCount = 0; int UnitTest::_missedFileDialogCount = 0;
UnitTest::UnitTest(void) : UnitTest::UnitTest(void)
_expectMissedFileDialog(false), : _linkManager(NULL)
_expectMissedMessageBox(false), , _mockLink(NULL)
_unitTestRun(false), , _mainWindow(NULL)
_initCalled(false), , _expectMissedFileDialog(false)
_cleanupCalled(false) , _expectMissedMessageBox(false)
{ , _unitTestRun(false)
, _initCalled(false)
, _cleanupCalled(false)
{
} }
UnitTest::~UnitTest() UnitTest::~UnitTest()
...@@ -101,6 +105,11 @@ int UnitTest::run(QString& singleTest) ...@@ -101,6 +105,11 @@ int UnitTest::run(QString& singleTest)
void UnitTest::init(void) void UnitTest::init(void)
{ {
_initCalled = true; _initCalled = true;
if (!_linkManager) {
_linkManager = qgcApp()->toolbox()->linkManager();
connect(_linkManager, &LinkManager::linkDeleted, this, &UnitTest::_linkDeleted);
}
_messageBoxRespondedTo = false; _messageBoxRespondedTo = false;
_missedMessageBoxCount = 0; _missedMessageBoxCount = 0;
...@@ -128,6 +137,9 @@ void UnitTest::cleanup(void) ...@@ -128,6 +137,9 @@ void UnitTest::cleanup(void)
{ {
_cleanupCalled = true; _cleanupCalled = true;
_disconnectMockLink();
_closeMainWindow();
// We add a slight delay here to allow for deleteLater and Qml cleanup // We add a slight delay here to allow for deleteLater and Qml cleanup
QTest::qWait(200); QTest::qWait(200);
...@@ -358,3 +370,58 @@ QString UnitTest::_getSaveFileName( ...@@ -358,3 +370,58 @@ QString UnitTest::_getSaveFileName(
return _fileDialogResponseSingle(getSaveFileName); return _fileDialogResponseSingle(getSaveFileName);
} }
void UnitTest::_connectMockLink(MAV_AUTOPILOT autopilot)
{
Q_ASSERT(!_mockLink);
_mockLink = new MockLink();
_mockLink->setFirmwareType(autopilot);
_linkManager->_addLink(_mockLink);
_linkManager->connectLink(_mockLink);
// Wait for the Vehicle to get created
QSignalSpy spyVehicle(qgcApp()->toolbox()->multiVehicleManager(), SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
QCOMPARE(spyVehicle.wait(5000), true);
QVERIFY(qgcApp()->toolbox()->multiVehicleManager()->parameterReadyVehicleAvailable());
QVERIFY(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
}
void UnitTest::_disconnectMockLink(void)
{
if (_mockLink) {
QSignalSpy linkSpy(_linkManager, SIGNAL(linkDeleted(LinkInterface*)));
_linkManager->disconnectLink(_mockLink);
// Wait for link to go away
linkSpy.wait(1000);
QCOMPARE(linkSpy.count(), 1);
}
}
void UnitTest::_linkDeleted(LinkInterface* link)
{
if (link == _mockLink) {
_mockLink = NULL;
}
}
void UnitTest::_createMainWindow(void)
{
_mainWindow = MainWindow::_create();
Q_CHECK_PTR(_mainWindow);
}
void UnitTest::_closeMainWindow(bool cancelExpected)
{
if (_mainWindow) {
QSignalSpy mainWindowSpy(_mainWindow, SIGNAL(mainWindowClosed()));
_mainWindow->close();
mainWindowSpy.wait(2000);
QCOMPARE(mainWindowSpy.count(), cancelExpected ? 0 : 1);
}
}
...@@ -35,11 +35,16 @@ ...@@ -35,11 +35,16 @@
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include "QGCMAVLink.h"
#include "LinkInterface.h"
#define UT_REGISTER_TEST(className) static UnitTestWrapper<className> t(#className); #define UT_REGISTER_TEST(className) static UnitTestWrapper<className> t(#className);
class QGCMessageBox; class QGCMessageBox;
class QGCFileDialog; class QGCFileDialog;
class UnitTest; class LinkManager;
class MockLink;
class MainWindow;
class UnitTest : public QObject class UnitTest : public QObject
{ {
...@@ -102,9 +107,21 @@ protected slots: ...@@ -102,9 +107,21 @@ protected slots:
virtual void cleanup(void); virtual void cleanup(void);
protected: protected:
void _connectMockLink(MAV_AUTOPILOT autopilot = MAV_AUTOPILOT_PX4);
void _disconnectMockLink(void);
void _createMainWindow(void);
void _closeMainWindow(bool cancelExpected = false);
LinkManager* _linkManager;
MockLink* _mockLink;
MainWindow* _mainWindow;
bool _expectMissedFileDialog; // true: expect a missed file dialog, used for internal testing bool _expectMissedFileDialog; // true: expect a missed file dialog, used for internal testing
bool _expectMissedMessageBox; // true: expect a missed message box, used for internal testing bool _expectMissedMessageBox; // true: expect a missed message box, used for internal testing
private slots:
void _linkDeleted(LinkInterface* link);
private: private:
// When the app is running in unit test mode the QGCMessageBox methods are re-routed here. // When the app is running in unit test mode the QGCMessageBox methods are re-routed here.
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "QGCApplication.h"
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
...@@ -718,7 +719,7 @@ void FileManager::_sendRequest(Request* request) ...@@ -718,7 +719,7 @@ void FileManager::_sendRequest(Request* request)
qCDebug(FileManagerLog) << "_sendRequest opcode:" << request->hdr.opcode << "seqNumber:" << request->hdr.seqNumber; qCDebug(FileManagerLog) << "_sendRequest opcode:" << request->hdr.opcode << "seqNumber:" << request->hdr.seqNumber;
if (_systemIdQGC == 0) { if (_systemIdQGC == 0) {
_systemIdQGC = MAVLinkProtocol::instance()->getSystemId(); _systemIdQGC = qgcApp()->toolbox()->mavlinkProtocol()->getSystemId();
} }
Q_ASSERT(_vehicle); Q_ASSERT(_vehicle);
......
...@@ -50,7 +50,7 @@ QGC_LOGGING_CATEGORY(UASLog, "UASLog") ...@@ -50,7 +50,7 @@ QGC_LOGGING_CATEGORY(UASLog, "UASLog")
* creating the UAS. * creating the UAS.
*/ */
UAS::UAS(MAVLinkProtocol* protocol, Vehicle* vehicle) : UASInterface(), UAS::UAS(MAVLinkProtocol* protocol, Vehicle* vehicle, FirmwarePluginManager * firmwarePluginManager) : UASInterface(),
lipoFull(4.2f), lipoFull(4.2f),
lipoEmpty(3.5f), lipoEmpty(3.5f),
uasId(vehicle->id()), uasId(vehicle->id()),
...@@ -177,7 +177,8 @@ UAS::UAS(MAVLinkProtocol* protocol, Vehicle* vehicle) : UASInterface(), ...@@ -177,7 +177,8 @@ UAS::UAS(MAVLinkProtocol* protocol, Vehicle* vehicle) : UASInterface(),
lastSendTimeGPS(0), lastSendTimeGPS(0),
lastSendTimeSensors(0), lastSendTimeSensors(0),
lastSendTimeOpticalFlow(0), lastSendTimeOpticalFlow(0),
_vehicle(vehicle) _vehicle(vehicle),
_firmwarePluginManager(firmwarePluginManager)
{ {
for (unsigned int i = 0; i<255;++i) for (unsigned int i = 0; i<255;++i)
...@@ -398,7 +399,7 @@ void UAS::receiveMessage(mavlink_message_t message) ...@@ -398,7 +399,7 @@ void UAS::receiveMessage(mavlink_message_t message)
bool statechanged = false; bool statechanged = false;
bool modechanged = false; bool modechanged = false;
QString audiomodeText = FirmwarePluginManager::instance()->firmwarePluginForAutopilot((MAV_AUTOPILOT)state.autopilot, (MAV_TYPE)state.type)->flightMode(state.base_mode, state.custom_mode); QString audiomodeText = _firmwarePluginManager->firmwarePluginForAutopilot((MAV_AUTOPILOT)state.autopilot, (MAV_TYPE)state.type)->flightMode(state.base_mode, state.custom_mode);
if ((state.system_status != this->status) && state.system_status != MAV_STATE_UNINIT) if ((state.system_status != this->status) && state.system_status != MAV_STATE_UNINIT)
{ {
...@@ -443,7 +444,7 @@ void UAS::receiveMessage(mavlink_message_t message) ...@@ -443,7 +444,7 @@ void UAS::receiveMessage(mavlink_message_t message)
if (statechanged && ((int)state.system_status == (int)MAV_STATE_CRITICAL || state.system_status == (int)MAV_STATE_EMERGENCY)) if (statechanged && ((int)state.system_status == (int)MAV_STATE_CRITICAL || state.system_status == (int)MAV_STATE_EMERGENCY))
{ {
_say(QString("Emergency for system %1").arg(this->getUASID()), GAudioOutput::AUDIO_SEVERITY_EMERGENCY); _say(QString("Emergency for system %1").arg(this->getUASID()), GAudioOutput::AUDIO_SEVERITY_EMERGENCY);
QTimer::singleShot(3000, GAudioOutput::instance(), SLOT(startEmergency())); QTimer::singleShot(3000, qgcApp()->toolbox()->audioOutput(), SLOT(startEmergency()));
} }
else if (modechanged || statechanged) else if (modechanged || statechanged)
{ {
...@@ -1058,28 +1059,7 @@ void UAS::receiveMessage(mavlink_message_t message) ...@@ -1058,28 +1059,7 @@ void UAS::receiveMessage(mavlink_message_t message)
emit NavigationControllerDataChanged(this, p.nav_roll, p.nav_pitch, p.nav_bearing, p.target_bearing, p.wp_dist); emit NavigationControllerDataChanged(this, p.nav_roll, p.nav_pitch, p.nav_bearing, p.target_bearing, p.wp_dist);
} }
break; break;
// Messages to ignore
case MAVLINK_MSG_ID_RAW_IMU:
case MAVLINK_MSG_ID_SCALED_IMU:
case MAVLINK_MSG_ID_RAW_PRESSURE:
case MAVLINK_MSG_ID_SCALED_PRESSURE:
case MAVLINK_MSG_ID_OPTICAL_FLOW:
case MAVLINK_MSG_ID_DEBUG_VECT:
case MAVLINK_MSG_ID_DEBUG:
case MAVLINK_MSG_ID_NAMED_VALUE_FLOAT:
case MAVLINK_MSG_ID_NAMED_VALUE_INT:
case MAVLINK_MSG_ID_MANUAL_CONTROL:
case MAVLINK_MSG_ID_HIGHRES_IMU:
case MAVLINK_MSG_ID_DISTANCE_SENSOR:
break;
default: default:
{
if (!unknownPackets.contains(message.msgid))
{
unknownPackets.append(message.msgid);
qDebug() << "Unknown message from system:" << uasId << "message:" << message.msgid;
}
}
break; break;
} }
} }
...@@ -2474,5 +2454,5 @@ void UAS::unsetRCToParameterMap() ...@@ -2474,5 +2454,5 @@ void UAS::unsetRCToParameterMap()
void UAS::_say(const QString& text, int severity) void UAS::_say(const QString& text, int severity)
{ {
if (!qgcApp()->runningUnitTests()) if (!qgcApp()->runningUnitTests())
GAudioOutput::instance()->say(text, severity); qgcApp()->toolbox()->audioOutput()->say(text, severity);
} }
...@@ -38,6 +38,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -38,6 +38,7 @@ This file is part of the QGROUNDCONTROL project
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "FileManager.h" #include "FileManager.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "FirmwarePluginManager.h"
#ifndef __mobile__ #ifndef __mobile__
#include "QGCHilLink.h" #include "QGCHilLink.h"
...@@ -62,7 +63,7 @@ class UAS : public UASInterface ...@@ -62,7 +63,7 @@ class UAS : public UASInterface
{ {
Q_OBJECT Q_OBJECT
public: public:
UAS(MAVLinkProtocol* protocol, Vehicle* vehicle); UAS(MAVLinkProtocol* protocol, Vehicle* vehicle, FirmwarePluginManager * firmwarePluginManager);
~UAS(); ~UAS();
float lipoFull; ///< 100% charged voltage float lipoFull; ///< 100% charged voltage
...@@ -695,7 +696,8 @@ private: ...@@ -695,7 +696,8 @@ private:
void _say(const QString& text, int severity = 6); void _say(const QString& text, int severity = 6);
private: private:
Vehicle* _vehicle; Vehicle* _vehicle;
FirmwarePluginManager* _firmwarePluginManager;
}; };
......
...@@ -52,20 +52,17 @@ bool UASMessage::severityIsError() ...@@ -52,20 +52,17 @@ bool UASMessage::severityIsError()
} }
} }
IMPLEMENT_QGC_SINGLETON(UASMessageHandler, UASMessageHandler) UASMessageHandler::UASMessageHandler(QGCApplication* app)
: QGCTool(app)
UASMessageHandler::UASMessageHandler(QObject *parent)
: QGCSingleton(parent)
, _activeUAS(NULL) , _activeUAS(NULL)
, _errorCount(0) , _errorCount(0)
, _errorCountTotal(0) , _errorCountTotal(0)
, _warningCount(0) , _warningCount(0)
, _normalCount(0) , _normalCount(0)
, _showErrorsInToolbar(false) , _showErrorsInToolbar(false)
, _multiVehicleManager(NULL)
{ {
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &UASMessageHandler::_activeVehicleChanged);
emit textMessageReceived(NULL);
emit textMessageCountChanged(0);
} }
UASMessageHandler::~UASMessageHandler() UASMessageHandler::~UASMessageHandler()
...@@ -73,6 +70,17 @@ UASMessageHandler::~UASMessageHandler() ...@@ -73,6 +70,17 @@ UASMessageHandler::~UASMessageHandler()
clearMessages(); clearMessages();
} }
void UASMessageHandler::setToolbox(QGCToolbox *toolbox)
{
QGCTool::setToolbox(toolbox);
_multiVehicleManager = _toolbox->multiVehicleManager();
connect(_multiVehicleManager, &MultiVehicleManager::activeVehicleChanged, this, &UASMessageHandler::_activeVehicleChanged);
emit textMessageReceived(NULL);
emit textMessageCountChanged(0);
}
void UASMessageHandler::clearMessages() void UASMessageHandler::clearMessages()
{ {
_mutex.lock(); _mutex.lock();
...@@ -190,7 +198,7 @@ void UASMessageHandler::handleTextMessage(int, int compId, int severity, QString ...@@ -190,7 +198,7 @@ void UASMessageHandler::handleTextMessage(int, int compId, int severity, QString
emit textMessageCountChanged(count); emit textMessageCountChanged(count);
if (_showErrorsInToolbar && message->severityIsError()) { if (_showErrorsInToolbar && message->severityIsError()) {
qgcApp()->showToolBarMessage(message->getText()); _app->showToolBarMessage(message->getText());
} }
} }
......
...@@ -34,11 +34,12 @@ This file is part of the QGROUNDCONTROL project ...@@ -34,11 +34,12 @@ This file is part of the QGROUNDCONTROL project
#include <QVector> #include <QVector>
#include <QMutex> #include <QMutex>
#include "QGCSingleton.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "QGCToolbox.h"
class UASInterface; class UASInterface;
class UASMessageHandler; class UASMessageHandler;
class QGCApplication;
/*! /*!
* @class UASMessage * @class UASMessage
...@@ -68,7 +69,7 @@ public: ...@@ -68,7 +69,7 @@ public:
* @return true: This message is a of a severity which is considered an error * @return true: This message is a of a severity which is considered an error
*/ */
bool severityIsError(); bool severityIsError();
private: private:
UASMessage(int componentid, int severity, QString text); UASMessage(int componentid, int severity, QString text);
void _setFormatedText(const QString formatedText) { _formatedText = formatedText; } void _setFormatedText(const QString formatedText) { _formatedText = formatedText; }
...@@ -78,14 +79,14 @@ private: ...@@ -78,14 +79,14 @@ private:
QString _formatedText; QString _formatedText;
}; };
class UASMessageHandler : public QGCSingleton class UASMessageHandler : public QGCTool
{ {
Q_OBJECT Q_OBJECT
DECLARE_QGC_SINGLETON(UASMessageHandler, UASMessageHandler)
public: public:
explicit UASMessageHandler(QObject *parent = 0); explicit UASMessageHandler(QGCApplication* app);
~UASMessageHandler(); ~UASMessageHandler();
/** /**
* @brief Locks access to the message list * @brief Locks access to the message list
*/ */
...@@ -126,6 +127,9 @@ public: ...@@ -126,6 +127,9 @@ public:
/// Begin to show message which are errors in the toolbar /// Begin to show message which are errors in the toolbar
void showErrorsInToolbar(void) { _showErrorsInToolbar = true; } void showErrorsInToolbar(void) { _showErrorsInToolbar = true; }
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
public slots: public slots:
/** /**
* @brief Handle text message from current active UAS * @brief Handle text message from current active UAS
...@@ -152,16 +156,16 @@ private slots: ...@@ -152,16 +156,16 @@ private slots:
void _activeVehicleChanged(Vehicle* vehicle); void _activeVehicleChanged(Vehicle* vehicle);
private: private:
// Stores the UAS that we're currently receiving messages from. UASInterface* _activeUAS;
UASInterface* _activeUAS; QVector<UASMessage*> _messages;
QVector<UASMessage*> _messages; QMutex _mutex;
QMutex _mutex; int _errorCount;
int _errorCount; int _errorCountTotal;
int _errorCountTotal; int _warningCount;
int _warningCount; int _normalCount;
int _normalCount; QString _latestError;
QString _latestError; bool _showErrorsInToolbar;
bool _showErrorsInToolbar; MultiVehicleManager* _multiVehicleManager;
}; };
#endif // QGCMESSAGEHANDLER_H #endif // QGCMESSAGEHANDLER_H
...@@ -33,6 +33,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -33,6 +33,7 @@ This file is part of the QGROUNDCONTROL project
#include "MAVLinkSettingsWidget.h" #include "MAVLinkSettingsWidget.h"
#include "LinkManager.h" #include "LinkManager.h"
#include "UDPLink.h" #include "UDPLink.h"
#include "QGCApplication.h"
#include "ui_MAVLinkSettingsWidget.h" #include "ui_MAVLinkSettingsWidget.h"
#include <QSettings> #include <QSettings>
...@@ -142,7 +143,7 @@ void MAVLinkSettingsWidget::enableDroneOS(bool enable) ...@@ -142,7 +143,7 @@ void MAVLinkSettingsWidget::enableDroneOS(bool enable)
// Delete from all lists first // Delete from all lists first
UDPLink* firstUdp = NULL; UDPLink* firstUdp = NULL;
QList<LinkInterface*> links = LinkManager::instance()->getLinks(); QList<LinkInterface*> links = qgcApp()->toolbox()->linkManager()->getLinks();
foreach (LinkInterface* link, links) foreach (LinkInterface* link, links)
{ {
UDPLink* udp = dynamic_cast<UDPLink*>(link); UDPLink* udp = dynamic_cast<UDPLink*>(link);
......
...@@ -210,8 +210,8 @@ MainWindow::MainWindow() ...@@ -210,8 +210,8 @@ MainWindow::MainWindow()
#endif //QGC_MOUSE_ENABLED_LINUX #endif //QGC_MOUSE_ENABLED_LINUX
// These also cause the screen to redraw so we need to update any OpenGL canvases in QML controls // These also cause the screen to redraw so we need to update any OpenGL canvases in QML controls
connect(LinkManager::instance(), &LinkManager::linkConnected, this, &MainWindow::_linkStateChange); connect(qgcApp()->toolbox()->linkManager(), &LinkManager::linkConnected, this, &MainWindow::_linkStateChange);
connect(LinkManager::instance(), &LinkManager::linkDisconnected, this, &MainWindow::_linkStateChange); connect(qgcApp()->toolbox()->linkManager(), &LinkManager::linkDisconnected, this, &MainWindow::_linkStateChange);
// Connect link // Connect link
if (_autoReconnect) if (_autoReconnect)
...@@ -323,7 +323,7 @@ void MainWindow::_buildCommonWidgets(void) ...@@ -323,7 +323,7 @@ void MainWindow::_buildCommonWidgets(void)
{ {
// Add generic MAVLink decoder // Add generic MAVLink decoder
// TODO: This is never deleted // TODO: This is never deleted
mavlinkDecoder = new MAVLinkDecoder(MAVLinkProtocol::instance(), this); mavlinkDecoder = new MAVLinkDecoder(qgcApp()->toolbox()->mavlinkProtocol(), this);
connect(mavlinkDecoder, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)), connect(mavlinkDecoder, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),
this, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64))); this, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)));
...@@ -372,7 +372,7 @@ void MainWindow::_createInnerDockWidget(const QString& widgetName) ...@@ -372,7 +372,7 @@ void MainWindow::_createInnerDockWidget(const QString& widgetName)
switch(action->data().toInt()) { switch(action->data().toInt()) {
case MAVLINK_INSPECTOR: case MAVLINK_INSPECTOR:
widget = new QGCMAVLinkInspector(widgetName, action, MAVLinkProtocol::instance(),this); widget = new QGCMAVLinkInspector(widgetName, action, qgcApp()->toolbox()->mavlinkProtocol(),this);
break; break;
case CUSTOM_COMMAND: case CUSTOM_COMMAND:
widget = new CustomCommandWidget(widgetName, action, this); widget = new CustomCommandWidget(widgetName, action, this);
...@@ -438,7 +438,7 @@ void MainWindow::showStatusBarCallback(bool checked) ...@@ -438,7 +438,7 @@ void MainWindow::showStatusBarCallback(bool checked)
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
// Disallow window close if there are active connections // Disallow window close if there are active connections
if (LinkManager::instance()->anyConnectedLinks()) { if (qgcApp()->toolbox()->linkManager()->anyConnectedLinks()) {
QGCMessageBox::StandardButton button = QGCMessageBox::StandardButton button =
QGCMessageBox::warning( QGCMessageBox::warning(
tr("QGroundControl close"), tr("QGroundControl close"),
...@@ -446,7 +446,7 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -446,7 +446,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel); QMessageBox::Cancel);
if (button == QMessageBox::Yes) { if (button == QMessageBox::Yes) {
LinkManager::instance()->disconnectAll(); qgcApp()->toolbox()->linkManager()->disconnectAll();
// The above disconnect causes a flurry of activity as the vehicle components are removed. This in turn // The above disconnect causes a flurry of activity as the vehicle components are removed. This in turn
// causes the Windows Version of Qt to crash if you allow the close event to be accepted. In order to prevent // causes the Windows Version of Qt to crash if you allow the close event to be accepted. In order to prevent
// the crash, we ignore the close event and setup a delayed timer to close the window after things settle down. // the crash, we ignore the close event and setup a delayed timer to close the window after things settle down.
...@@ -461,7 +461,7 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -461,7 +461,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents); qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
// Should not be any active connections // Should not be any active connections
Q_ASSERT(!LinkManager::instance()->anyConnectedLinks()); Q_ASSERT(!qgcApp()->toolbox()->linkManager()->anyConnectedLinks());
// We have to pull out the QmlWidget from the main window and delete it here, before // We have to pull out the QmlWidget from the main window and delete it here, before
// the MainWindow ends up getting deleted. Otherwise the Qml has a reference to MainWindow // the MainWindow ends up getting deleted. Otherwise the Qml has a reference to MainWindow
...@@ -472,7 +472,11 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -472,7 +472,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
_storeCurrentViewState(); _storeCurrentViewState();
storeSettings(); storeSettings();
event->accept(); event->accept();
_instance = NULL;
emit mainWindowClosed();
} }
void MainWindow::loadSettings() void MainWindow::loadSettings()
...@@ -542,9 +546,9 @@ void MainWindow::connectCommonActions() ...@@ -542,9 +546,9 @@ void MainWindow::connectCommonActions()
connect(_ui.actionAdd_Link, SIGNAL(triggered()), this, SLOT(manageLinks())); connect(_ui.actionAdd_Link, SIGNAL(triggered()), this, SLOT(manageLinks()));
// Audio output // Audio output
_ui.actionMuteAudioOutput->setChecked(GAudioOutput::instance()->isMuted()); _ui.actionMuteAudioOutput->setChecked(qgcApp()->toolbox()->audioOutput()->isMuted());
connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), _ui.actionMuteAudioOutput, SLOT(setChecked(bool))); connect(qgcApp()->toolbox()->audioOutput(), SIGNAL(mutedChanged(bool)), _ui.actionMuteAudioOutput, SLOT(setChecked(bool)));
connect(_ui.actionMuteAudioOutput, SIGNAL(triggered(bool)), GAudioOutput::instance(), SLOT(mute(bool))); connect(_ui.actionMuteAudioOutput, SIGNAL(triggered(bool)), qgcApp()->toolbox()->audioOutput(), SLOT(mute(bool)));
// Application Settings // Application Settings
connect(_ui.actionSettings, SIGNAL(triggered()), this, SLOT(showSettings())); connect(_ui.actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
...@@ -555,7 +559,7 @@ void MainWindow::connectCommonActions() ...@@ -555,7 +559,7 @@ void MainWindow::connectCommonActions()
connect(_ui.actionSetup, &QAction::triggered, this, &MainWindow::showSetupView); connect(_ui.actionSetup, &QAction::triggered, this, &MainWindow::showSetupView);
// Connect internal actions // Connect internal actions
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &MainWindow::_vehicleAdded); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleAdded, this, &MainWindow::_vehicleAdded);
} }
void MainWindow::_openUrl(const QString& url, const QString& errorMessage) void MainWindow::_openUrl(const QString& url, const QString& errorMessage)
...@@ -570,7 +574,7 @@ void MainWindow::_openUrl(const QString& url, const QString& errorMessage) ...@@ -570,7 +574,7 @@ void MainWindow::_openUrl(const QString& url, const QString& errorMessage)
void MainWindow::showSettings() void MainWindow::showSettings()
{ {
SettingsDialog settings(this); SettingsDialog settings(qgcApp()->toolbox()->audioOutput(), qgcApp()->toolbox()->flightMapSettings(), this);
settings.exec(); settings.exec();
} }
...@@ -593,7 +597,7 @@ void MainWindow::_storeCurrentViewState(void) ...@@ -593,7 +597,7 @@ void MainWindow::_storeCurrentViewState(void)
void MainWindow::manageLinks() void MainWindow::manageLinks()
{ {
SettingsDialog settings(this, SettingsDialog::ShowCommLinks); SettingsDialog settings(qgcApp()->toolbox()->audioOutput(), qgcApp()->toolbox()->flightMapSettings(), this, SettingsDialog::ShowCommLinks);
settings.exec(); settings.exec();
} }
...@@ -619,7 +623,7 @@ void MainWindow::restoreLastUsedConnection() ...@@ -619,7 +623,7 @@ void MainWindow::restoreLastUsedConnection()
if(settings.contains(key)) { if(settings.contains(key)) {
QString connection = settings.value(key).toString(); QString connection = settings.value(key).toString();
// Create a link for it // Create a link for it
LinkManager::instance()->createConnectedLink(connection); qgcApp()->toolbox()->linkManager()->createConnectedLink(connection);
} }
} }
......
...@@ -154,6 +154,9 @@ signals: ...@@ -154,6 +154,9 @@ signals:
/** Emitted when any the Canvas elements within QML wudgets need updating */ /** Emitted when any the Canvas elements within QML wudgets need updating */
void repaintCanvas(); void repaintCanvas();
// Used for unit tests to know when the main window closes
void mainWindowClosed(void);
#ifdef QGC_MOUSE_ENABLED_LINUX #ifdef QGC_MOUSE_ENABLED_LINUX
/** @brief Forward X11Event to catch 3DMouse inputs */ /** @brief Forward X11Event to catch 3DMouse inputs */
void x11EventOccured(XEvent *event); void x11EventOccured(XEvent *event);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "MultiVehicleDockWidget.h" #include "MultiVehicleDockWidget.h"
#include "ui_MultiVehicleDockWidget.h" #include "ui_MultiVehicleDockWidget.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "QGCApplication.h"
MultiVehicleDockWidget::MultiVehicleDockWidget(const QString& title, QAction* action, QWidget *parent) MultiVehicleDockWidget::MultiVehicleDockWidget(const QString& title, QAction* action, QWidget *parent)
: QGCDockWidget(title, action, parent) : QGCDockWidget(title, action, parent)
...@@ -33,19 +34,19 @@ MultiVehicleDockWidget::MultiVehicleDockWidget(const QString& title, QAction* ac ...@@ -33,19 +34,19 @@ MultiVehicleDockWidget::MultiVehicleDockWidget(const QString& title, QAction* ac
setWindowTitle(title); setWindowTitle(title);
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &MultiVehicleDockWidget::_activeVehicleChanged); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &MultiVehicleDockWidget::_activeVehicleChanged);
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &MultiVehicleDockWidget::_vehicleAdded); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleAdded, this, &MultiVehicleDockWidget::_vehicleAdded);
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleRemoved, this, &MultiVehicleDockWidget::_vehicleRemoved); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleRemoved, this, &MultiVehicleDockWidget::_vehicleRemoved);
} }
void MultiVehicleDockWidget::init(void) void MultiVehicleDockWidget::init(void)
{ {
foreach (Vehicle* vehicle, MultiVehicleManager::instance()->vehicles()) { foreach (Vehicle* vehicle, qgcApp()->toolbox()->multiVehicleManager()->vehicles()) {
_vehicleAdded(vehicle); _vehicleAdded(vehicle);
} }
if (MultiVehicleManager::instance()->activeVehicle()) { if (qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()) {
_activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle()); _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
} }
} }
......
...@@ -38,7 +38,7 @@ QGCLinkConfiguration::QGCLinkConfiguration(QWidget *parent) : ...@@ -38,7 +38,7 @@ QGCLinkConfiguration::QGCLinkConfiguration(QWidget *parent) :
_ui(new Ui::QGCLinkConfiguration) _ui(new Ui::QGCLinkConfiguration)
{ {
// Stop automatic link updates while this UI is up // Stop automatic link updates while this UI is up
LinkManager::instance()->suspendConfigurationUpdates(true); qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(true);
_ui->setupUi(this); _ui->setupUi(this);
_viewModel = new LinkViewModel; _viewModel = new LinkViewModel;
_ui->linkView->setModel(_viewModel); _ui->linkView->setModel(_viewModel);
...@@ -52,7 +52,7 @@ QGCLinkConfiguration::~QGCLinkConfiguration() ...@@ -52,7 +52,7 @@ QGCLinkConfiguration::~QGCLinkConfiguration()
if(_viewModel) delete _viewModel; if(_viewModel) delete _viewModel;
if(_ui) delete _ui; if(_ui) delete _ui;
// Resume automatic link updates // Resume automatic link updates
LinkManager::instance()->suspendConfigurationUpdates(false); qgcApp()->toolbox()->linkManager()->suspendConfigurationUpdates(false);
} }
void QGCLinkConfiguration::on_delLinkButton_clicked() void QGCLinkConfiguration::on_delLinkButton_clicked()
...@@ -72,13 +72,13 @@ void QGCLinkConfiguration::on_delLinkButton_clicked() ...@@ -72,13 +72,13 @@ void QGCLinkConfiguration::on_delLinkButton_clicked()
LinkInterface* iface = config->getLink(); LinkInterface* iface = config->getLink();
if(iface) { if(iface) {
// Disconnect it (if connected) // Disconnect it (if connected)
LinkManager::instance()->disconnectLink(iface); qgcApp()->toolbox()->linkManager()->disconnectLink(iface);
} }
_viewModel->beginChange(); _viewModel->beginChange();
// Remove configuration // Remove configuration
LinkManager::instance()->removeLinkConfiguration(config); qgcApp()->toolbox()->linkManager()->removeLinkConfiguration(config);
// Save list // Save list
LinkManager::instance()->saveLinkConfigurationList(); qgcApp()->toolbox()->linkManager()->saveLinkConfigurationList();
_viewModel->endChange(); _viewModel->endChange();
} }
} }
...@@ -101,10 +101,10 @@ void QGCLinkConfiguration::on_connectLinkButton_clicked() ...@@ -101,10 +101,10 @@ void QGCLinkConfiguration::on_connectLinkButton_clicked()
if(link) { if(link) {
// Disconnect Link // Disconnect Link
if (link->isConnected()) { if (link->isConnected()) {
LinkManager::instance()->disconnectLink(link); qgcApp()->toolbox()->linkManager()->disconnectLink(link);
} }
} else { } else {
LinkInterface* link = LinkManager::instance()->createConnectedLink(config); LinkInterface* link = qgcApp()->toolbox()->linkManager()->createConnectedLink(config);
if(link) { if(link) {
// Now go hunting for the parent so we can shut this down // Now go hunting for the parent so we can shut this down
QWidget* pQw = parentWidget(); QWidget* pQw = parentWidget();
...@@ -186,8 +186,8 @@ void QGCLinkConfiguration::on_addLinkButton_clicked() ...@@ -186,8 +186,8 @@ void QGCLinkConfiguration::on_addLinkButton_clicked()
if(config) { if(config) {
_fixUnnamed(config); _fixUnnamed(config);
_viewModel->beginChange(); _viewModel->beginChange();
LinkManager::instance()->addLinkConfiguration(commDialog->getConfig()); qgcApp()->toolbox()->linkManager()->addLinkConfiguration(commDialog->getConfig());
LinkManager::instance()->saveLinkConfigurationList(); qgcApp()->toolbox()->linkManager()->saveLinkConfigurationList();
_viewModel->endChange(); _viewModel->endChange();
} }
} }
...@@ -213,7 +213,7 @@ void QGCLinkConfiguration::_editLink(int row) ...@@ -213,7 +213,7 @@ void QGCLinkConfiguration::_editLink(int row)
_viewModel->beginChange(); _viewModel->beginChange();
config->copyFrom(tmpConfig); config->copyFrom(tmpConfig);
// Save it // Save it
LinkManager::instance()->saveLinkConfigurationList(); qgcApp()->toolbox()->linkManager()->saveLinkConfigurationList();
_viewModel->endChange(); _viewModel->endChange();
// Tell link about changes (if any) // Tell link about changes (if any)
config->updateSettings(); config->updateSettings();
...@@ -261,14 +261,14 @@ LinkViewModel::LinkViewModel(QObject *parent) : QAbstractListModel(parent) ...@@ -261,14 +261,14 @@ LinkViewModel::LinkViewModel(QObject *parent) : QAbstractListModel(parent)
int LinkViewModel::rowCount( const QModelIndex & parent) const int LinkViewModel::rowCount( const QModelIndex & parent) const
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
QList<LinkConfiguration*> cfgList = LinkManager::instance()->getLinkConfigurationList(); QList<LinkConfiguration*> cfgList = qgcApp()->toolbox()->linkManager()->getLinkConfigurationList();
int count = cfgList.count(); int count = cfgList.count();
return count; return count;
} }
QVariant LinkViewModel::data( const QModelIndex & index, int role) const QVariant LinkViewModel::data( const QModelIndex & index, int role) const
{ {
QList<LinkConfiguration*> cfgList = LinkManager::instance()->getLinkConfigurationList(); QList<LinkConfiguration*> cfgList = qgcApp()->toolbox()->linkManager()->getLinkConfigurationList();
if (role == Qt::DisplayRole && index.row() < cfgList.count()) { if (role == Qt::DisplayRole && index.row() < cfgList.count()) {
QString name(cfgList.at(index.row())->name()); QString name(cfgList.at(index.row())->name());
return name; return name;
...@@ -278,7 +278,7 @@ QVariant LinkViewModel::data( const QModelIndex & index, int role) const ...@@ -278,7 +278,7 @@ QVariant LinkViewModel::data( const QModelIndex & index, int role) const
LinkConfiguration* LinkViewModel::getConfiguration(int row) LinkConfiguration* LinkViewModel::getConfiguration(int row)
{ {
QList<LinkConfiguration*> cfgList = LinkManager::instance()->getLinkConfigurationList(); QList<LinkConfiguration*> cfgList = qgcApp()->toolbox()->linkManager()->getLinkConfigurationList();
if(row < cfgList.count()) { if(row < cfgList.count()) {
return cfgList.at(row); return cfgList.at(row);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "QGCMAVLinkInspector.h" #include "QGCMAVLinkInspector.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "UAS.h" #include "UAS.h"
#include "QGCApplication.h"
#include "ui_QGCMAVLinkInspector.h" #include "ui_QGCMAVLinkInspector.h"
...@@ -52,7 +53,7 @@ QGCMAVLinkInspector::QGCMAVLinkInspector(const QString& title, QAction* action, ...@@ -52,7 +53,7 @@ QGCMAVLinkInspector::QGCMAVLinkInspector(const QString& title, QAction* action,
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearView())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearView()));
// Connect external connections // Connect external connections
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &QGCMAVLinkInspector::_vehicleAdded); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleAdded, this, &QGCMAVLinkInspector::_vehicleAdded);
connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t))); connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t)));
// Attach the UI's refresh rate to a timer. // Attach the UI's refresh rate to a timer.
...@@ -101,7 +102,7 @@ void QGCMAVLinkInspector::rebuildComponentList() ...@@ -101,7 +102,7 @@ void QGCMAVLinkInspector::rebuildComponentList()
ui->componentComboBox->addItem(tr("All"), 0); ui->componentComboBox->addItem(tr("All"), 0);
// Fill // Fill
Vehicle* vehicle = MultiVehicleManager::instance()->getVehicleById(selectedSystemID); Vehicle* vehicle = qgcApp()->toolbox()->multiVehicleManager()->getVehicleById(selectedSystemID);
if (vehicle) if (vehicle)
{ {
UASInterface* uas = vehicle->uas(); UASInterface* uas = vehicle->uas();
...@@ -334,7 +335,7 @@ void QGCMAVLinkInspector::addUAStoTree(int sysId) ...@@ -334,7 +335,7 @@ void QGCMAVLinkInspector::addUAStoTree(int sysId)
if(!uasTreeWidgetItems.contains(sysId)) if(!uasTreeWidgetItems.contains(sysId))
{ {
// Add the UAS to the main tree after it has been created // Add the UAS to the main tree after it has been created
Vehicle* vehicle = MultiVehicleManager::instance()->getVehicleById(sysId); Vehicle* vehicle = qgcApp()->toolbox()->multiVehicleManager()->getVehicleById(sysId);
if (vehicle) if (vehicle)
{ {
UASInterface* uas = vehicle->uas(); UASInterface* uas = vehicle->uas();
......
...@@ -60,7 +60,7 @@ void QGCMAVLinkLogPlayer::_pause(void) ...@@ -60,7 +60,7 @@ void QGCMAVLinkLogPlayer::_pause(void)
void QGCMAVLinkLogPlayer::_selectLogFileForPlayback(void) void QGCMAVLinkLogPlayer::_selectLogFileForPlayback(void)
{ {
// Disallow replay when any links are connected // Disallow replay when any links are connected
if (LinkManager::instance()->anyConnectedLinks()) { if (qgcApp()->toolbox()->linkManager()->anyConnectedLinks()) {
QGCMessageBox::information(tr("Log Replay"), tr("You must close all connections prior to replaying a log.")); QGCMessageBox::information(tr("Log Replay"), tr("You must close all connections prior to replaying a log."));
return; return;
} }
...@@ -81,7 +81,7 @@ void QGCMAVLinkLogPlayer::_selectLogFileForPlayback(void) ...@@ -81,7 +81,7 @@ void QGCMAVLinkLogPlayer::_selectLogFileForPlayback(void)
linkConfig->setLogFilename(logFilename); linkConfig->setLogFilename(logFilename);
linkConfig->setName(linkConfig->logFilenameShort()); linkConfig->setName(linkConfig->logFilenameShort());
_ui->logFileNameLabel->setText(linkConfig->logFilenameShort()); _ui->logFileNameLabel->setText(linkConfig->logFilenameShort());
_replayLink = (LogReplayLink*)LinkManager::instance()->createConnectedLink(linkConfig); _replayLink = (LogReplayLink*)qgcApp()->toolbox()->linkManager()->createConnectedLink(linkConfig);
connect(_replayLink, &LogReplayLink::logFileStats, this, &QGCMAVLinkLogPlayer::_logFileStats); connect(_replayLink, &LogReplayLink::logFileStats, this, &QGCMAVLinkLogPlayer::_logFileStats);
connect(_replayLink, &LogReplayLink::playbackStarted, this, &QGCMAVLinkLogPlayer::_playbackStarted); connect(_replayLink, &LogReplayLink::playbackStarted, this, &QGCMAVLinkLogPlayer::_playbackStarted);
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "QGCMapRCToParamDialog.h" #include "QGCMapRCToParamDialog.h"
#include "ui_QGCMapRCToParamDialog.h" #include "ui_QGCMapRCToParamDialog.h"
#include "MultiVehicleManager.h"
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
...@@ -34,11 +33,12 @@ ...@@ -34,11 +33,12 @@
#include <QShowEvent> #include <QShowEvent>
#include <QPushButton> #include <QPushButton>
QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav, QWidget *parent) : QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav, MultiVehicleManager* multiVehicleManager, QWidget *parent)
QDialog(parent), : QDialog(parent)
param_id(param_id), , param_id(param_id)
mav(mav), , mav(mav)
ui(new Ui::QGCMapRCToParamDialog) , _multiVehicleManager(multiVehicleManager)
, ui(new Ui::QGCMapRCToParamDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
...@@ -49,7 +49,7 @@ QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav ...@@ -49,7 +49,7 @@ QGCMapRCToParamDialog::QGCMapRCToParamDialog(QString param_id, UASInterface *mav
ui->paramIdLabel->setText(param_id); ui->paramIdLabel->setText(param_id);
// refresh the parameter from onboard to make sure the current value is used // refresh the parameter from onboard to make sure the current value is used
AutoPilotPlugin* autopilot = MultiVehicleManager::instance()->getVehicleById(mav->getUASID())->autopilotPlugin(); AutoPilotPlugin* autopilot = _multiVehicleManager->getVehicleById(mav->getUASID())->autopilotPlugin();
Q_ASSERT(autopilot); Q_ASSERT(autopilot);
connect(autopilot->getParameterFact(FactSystem::defaultComponentId, param_id), &Fact::valueChanged, this, &QGCMapRCToParamDialog::_parameterUpdated); connect(autopilot->getParameterFact(FactSystem::defaultComponentId, param_id), &Fact::valueChanged, this, &QGCMapRCToParamDialog::_parameterUpdated);
autopilot->refreshParameter(FactSystem::defaultComponentId, param_id); autopilot->refreshParameter(FactSystem::defaultComponentId, param_id);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "UASInterface.h" #include "UASInterface.h"
#include "AutoPilotPlugin.h" #include "AutoPilotPlugin.h"
#include "MultiVehicleManager.h"
namespace Ui { namespace Ui {
class QGCMapRCToParamDialog; class QGCMapRCToParamDialog;
...@@ -46,7 +47,7 @@ class QGCMapRCToParamDialog : public QDialog ...@@ -46,7 +47,7 @@ class QGCMapRCToParamDialog : public QDialog
QThread paramLoadThread; QThread paramLoadThread;
public: public:
explicit QGCMapRCToParamDialog(QString param_id, UASInterface *mav, QWidget *parent = 0); explicit QGCMapRCToParamDialog(QString param_id, UASInterface *mav, MultiVehicleManager* multiVehicleManager, QWidget *parent = 0);
~QGCMapRCToParamDialog(); ~QGCMapRCToParamDialog();
signals: signals:
...@@ -65,7 +66,8 @@ private slots: ...@@ -65,7 +66,8 @@ private slots:
void _parameterUpdated(QVariant value); void _parameterUpdated(QVariant value);
private: private:
Ui::QGCMapRCToParamDialog *ui; MultiVehicleManager* _multiVehicleManager;
Ui::QGCMapRCToParamDialog* ui;
}; };
#endif // QGCMAPRCTOPARAMDIALOG_H #endif // QGCMAPRCTOPARAMDIALOG_H
#include "QGCTabbedInfoView.h" #include "QGCTabbedInfoView.h"
#include "QGCApplication.h"
QGCTabbedInfoView::QGCTabbedInfoView(const QString& title, QAction* action, QWidget *parent) QGCTabbedInfoView::QGCTabbedInfoView(const QString& title, QAction* action, QWidget *parent)
: QGCDockWidget(title, action, parent) : QGCDockWidget(title, action, parent)
{ {
ui.setupUi(this); ui.setupUi(this);
messageView = new UASMessageViewWidget(this); messageView = new UASMessageViewWidget(qgcApp()->toolbox()->uasMessageHandler(), this);
//actionsWidget = new UASActionsWidget(this); //actionsWidget = new UASActionsWidget(this);
quickView = new UASQuickView(this); quickView = new UASQuickView(this);
//rawView = new UASRawStatusView(this); //rawView = new UASRawStatusView(this);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "UASInterface.h" #include "UASInterface.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "QGCUASFileView.h" #include "QGCUASFileView.h"
#include "QGCApplication.h"
QGCUASFileViewMulti::QGCUASFileViewMulti(const QString& title, QAction* action, QWidget *parent) : QGCUASFileViewMulti::QGCUASFileViewMulti(const QString& title, QAction* action, QWidget *parent) :
QGCDockWidget(title, action, parent), QGCDockWidget(title, action, parent),
...@@ -10,13 +11,13 @@ QGCUASFileViewMulti::QGCUASFileViewMulti(const QString& title, QAction* action, ...@@ -10,13 +11,13 @@ QGCUASFileViewMulti::QGCUASFileViewMulti(const QString& title, QAction* action,
{ {
ui->setupUi(this); ui->setupUi(this);
setMinimumSize(600, 80); setMinimumSize(600, 80);
connect(MultiVehicleManager::instance(), &MultiVehicleManager::activeVehicleChanged, this, &QGCUASFileViewMulti::_activeVehicleChanged); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &QGCUASFileViewMulti::_activeVehicleChanged);
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleAdded, this, &QGCUASFileViewMulti::_vehicleAdded); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleAdded, this, &QGCUASFileViewMulti::_vehicleAdded);
connect(MultiVehicleManager::instance(), &MultiVehicleManager::vehicleRemoved, this, &QGCUASFileViewMulti::_vehicleRemoved); connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleRemoved, this, &QGCUASFileViewMulti::_vehicleRemoved);
if (MultiVehicleManager::instance()->activeVehicle()) { if (qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()) {
_vehicleAdded(MultiVehicleManager::instance()->activeVehicle()); _vehicleAdded(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
_activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle()); _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
} }
loadSettings(); loadSettings();
......
...@@ -39,10 +39,12 @@ ...@@ -39,10 +39,12 @@
#include "MainToolBarController.h" #include "MainToolBarController.h"
#include "FlightMapSettings.h" #include "FlightMapSettings.h"
SettingsDialog::SettingsDialog(QWidget *parent, int showTab, Qt::WindowFlags flags) : SettingsDialog::SettingsDialog(GAudioOutput* audioOutput, FlightMapSettings* flightMapSettings, QWidget *parent, int showTab, Qt::WindowFlags flags)
QDialog(parent, flags), : QDialog(parent, flags)
_mainWindow(MainWindow::instance()), , _mainWindow(MainWindow::instance())
_ui(new Ui::SettingsDialog) , _audioOutput(audioOutput)
, _flightMapSettings(flightMapSettings)
, _ui(new Ui::SettingsDialog)
{ {
_ui->setupUi(this); _ui->setupUi(this);
...@@ -55,7 +57,7 @@ _ui(new Ui::SettingsDialog) ...@@ -55,7 +57,7 @@ _ui(new Ui::SettingsDialog)
move(position.topLeft()); move(position.topLeft());
QGCLinkConfiguration* pLinkConf = new QGCLinkConfiguration(this); QGCLinkConfiguration* pLinkConf = new QGCLinkConfiguration(this);
MAVLinkSettingsWidget* pMavsettings = new MAVLinkSettingsWidget(MAVLinkProtocol::instance(), this); MAVLinkSettingsWidget* pMavsettings = new MAVLinkSettingsWidget(qgcApp()->toolbox()->mavlinkProtocol(), this);
// Add the link settings pane // Add the link settings pane
_ui->tabWidget->addTab(pLinkConf, "Comm Links"); _ui->tabWidget->addTab(pLinkConf, "Comm Links");
...@@ -65,9 +67,9 @@ _ui(new Ui::SettingsDialog) ...@@ -65,9 +67,9 @@ _ui(new Ui::SettingsDialog)
this->window()->setWindowTitle(tr("QGroundControl Settings")); this->window()->setWindowTitle(tr("QGroundControl Settings"));
// Audio preferences // Audio preferences
_ui->audioMuteCheckBox->setChecked(GAudioOutput::instance()->isMuted()); _ui->audioMuteCheckBox->setChecked(_audioOutput->isMuted());
connect(_ui->audioMuteCheckBox, SIGNAL(toggled(bool)), GAudioOutput::instance(), SLOT(mute(bool))); connect(_ui->audioMuteCheckBox, SIGNAL(toggled(bool)), _audioOutput, SLOT(mute(bool)));
connect(GAudioOutput::instance(), SIGNAL(mutedChanged(bool)), _ui->audioMuteCheckBox, SLOT(setChecked(bool))); connect(_audioOutput, SIGNAL(mutedChanged(bool)), _ui->audioMuteCheckBox, SLOT(setChecked(bool)));
// Reconnect // Reconnect
_ui->reconnectCheckBox->setChecked(_mainWindow->autoReconnectEnabled()); _ui->reconnectCheckBox->setChecked(_mainWindow->autoReconnectEnabled());
...@@ -92,7 +94,7 @@ _ui(new Ui::SettingsDialog) ...@@ -92,7 +94,7 @@ _ui(new Ui::SettingsDialog)
// Flight Map settings // Flight Map settings
FlightMapSettings* fmSettings = FlightMapSettings::instance(); FlightMapSettings* fmSettings = _flightMapSettings;
_ui->bingMapRadio->setChecked(fmSettings->mapProvider() == "Bing"); _ui->bingMapRadio->setChecked(fmSettings->mapProvider() == "Bing");
_ui->googleMapRadio->setChecked(fmSettings->mapProvider() == "Google"); _ui->googleMapRadio->setChecked(fmSettings->mapProvider() == "Google");
_ui->openMapRadio->setChecked(fmSettings->mapProvider() == "Open"); _ui->openMapRadio->setChecked(fmSettings->mapProvider() == "Open");
...@@ -178,20 +180,20 @@ void SettingsDialog::_selectSavedFilesDirectory(void) ...@@ -178,20 +180,20 @@ void SettingsDialog::_selectSavedFilesDirectory(void)
void SettingsDialog::_bingMapRadioClicked(bool checked) void SettingsDialog::_bingMapRadioClicked(bool checked)
{ {
if (checked) { if (checked) {
FlightMapSettings::instance()->setMapProvider("Bing"); _flightMapSettings->setMapProvider("Bing");
} }
} }
void SettingsDialog::_googleMapRadioClicked(bool checked) void SettingsDialog::_googleMapRadioClicked(bool checked)
{ {
if (checked) { if (checked) {
FlightMapSettings::instance()->setMapProvider("Google"); _flightMapSettings->setMapProvider("Google");
} }
} }
void SettingsDialog::_openMapRadioClicked(bool checked) void SettingsDialog::_openMapRadioClicked(bool checked)
{ {
if (checked) { if (checked) {
FlightMapSettings::instance()->setMapProvider("Open"); _flightMapSettings->setMapProvider("Open");
} }
} }
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
#define SETTINGSDIALOG_H #define SETTINGSDIALOG_H
#include <QDialog> #include <QDialog>
#include "MainWindow.h" #include "MainWindow.h"
#include "GAudioOutput.h"
#include "FlightMapSettings.h"
namespace Ui namespace Ui
{ {
...@@ -45,7 +48,7 @@ public: ...@@ -45,7 +48,7 @@ public:
ShowMavlink ShowMavlink
}; };
SettingsDialog(QWidget *parent = 0, int showTab = ShowDefault, Qt::WindowFlags flags = Qt::Sheet); SettingsDialog(GAudioOutput* audioOuput, FlightMapSettings* flightMapSettings, QWidget *parent = 0, int showTab = ShowDefault, Qt::WindowFlags flags = Qt::Sheet);
~SettingsDialog(); ~SettingsDialog();
public slots: public slots:
...@@ -62,6 +65,8 @@ private slots: ...@@ -62,6 +65,8 @@ private slots:
private: private:
MainWindow* _mainWindow; MainWindow* _mainWindow;
GAudioOutput* _audioOutput;
FlightMapSettings* _flightMapSettings;
Ui::SettingsDialog* _ui; Ui::SettingsDialog* _ui;
}; };
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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