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 += \
src/QGCQuickWidget.h \
src/QGCSingleton.h \
src/QGCTemporaryFile.h \
src/QGCToolbox.h \
src/QmlControls/CoordinateVector.h \
src/QmlControls/MavlinkQmlSingleton.h \
src/QmlControls/ParameterEditorController.h \
......@@ -356,6 +357,7 @@ SOURCES += \
src/QGCQuickWidget.cc \
src/QGCSingleton.cc \
src/QGCTemporaryFile.cc \
src/QGCToolbox.cc \
src/QGCGeo.cc \
src/QmlControls/CoordinateVector.cc \
src/QmlControls/ParameterEditorController.cc \
......
......@@ -101,7 +101,7 @@ bool AutoPilotPlugin::setupComplete(void)
void AutoPilotPlugin::resetAllParametersToDefaults(void)
{
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);
_vehicle->sendMessage(msg);
......
......@@ -29,14 +29,6 @@
#include "APM/APMAutoPilotPlugin.h"
#include "Generic/GenericAutoPilotPlugin.h"
IMPLEMENT_QGC_SINGLETON(AutoPilotPluginManager, AutoPilotPluginManager)
AutoPilotPluginManager::AutoPilotPluginManager(QObject* parent) :
QGCSingleton(parent)
{
}
AutoPilotPlugin* AutoPilotPluginManager::newAutopilotPluginForVehicle(Vehicle* vehicle)
{
switch (vehicle->firmwareType()) {
......
......@@ -32,23 +32,19 @@
#include <QString>
#include "AutoPilotPlugin.h"
#include "QGCSingleton.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
DECLARE_QGC_SINGLETON(AutoPilotPluginManager, AutoPilotPluginManager)
public:
AutoPilotPluginManager(QGCApplication* app) : QGCTool(app) { }
AutoPilotPlugin* newAutopilotPluginForVehicle(Vehicle* vehicle);
private:
/// All access to singleton is through AutoPilotPluginManager::instance
AutoPilotPluginManager(QObject* parent = NULL);
};
#endif
......@@ -98,7 +98,7 @@ AirframeComponentController::~AirframeComponentController()
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.");
return;
}
......@@ -139,7 +139,7 @@ void AirframeComponentController::_rebootAfterStackUnwind(void)
QGC::SLEEP::usleep(500);
qgcApp()->processEvents(QEventLoop::ExcludeUserInputEvents);
}
LinkManager::instance()->disconnectAll();
qgcApp()->toolbox()->linkManager()->disconnectAll();
qgcApp()->restoreOverrideCursor();
}
......
......@@ -135,7 +135,6 @@ QString Fact::valueString(void) const
switch (type()) {
case FactMetaData::valueTypeFloat:
qDebug() << name() << value() << decimalPlaces();
valueString = QString("%1").arg(value().toFloat(), 0, 'g', decimalPlaces());
break;
case FactMetaData::valueTypeDouble:
......
......@@ -36,7 +36,7 @@ QGC_LOGGING_CATEGORY(FactPanelControllerLog, "FactPanelControllerLog")
FactPanelController::FactPanelController(void) :
_factPanel(NULL)
{
_vehicle = MultiVehicleManager::instance()->activeVehicle();
_vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
Q_ASSERT(_vehicle);
_uas = _vehicle->uas();
......
......@@ -29,19 +29,18 @@
#include <QtQml>
IMPLEMENT_QGC_SINGLETON(FactSystem, FactSystem)
const char* FactSystem::_factSystemQmlUri = "QGroundControl.FactSystem";
FactSystem::FactSystem(QObject* parent) :
QGCSingleton(parent)
FactSystem::FactSystem(QGCApplication* app)
: 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 @@
#include "Fact.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
/// 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
......@@ -40,13 +38,17 @@
/// 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.
class FactSystem : public QGCSingleton
class FactSystem : public QGCTool
{
Q_OBJECT
DECLARE_QGC_SINGLETON(FactSystem, FactSystem)
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 {
ParameterProvider,
} Provider_t;
......@@ -54,10 +56,6 @@ public:
static const int defaultComponentId = -1;
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
};
......
......@@ -44,19 +44,9 @@ void FactSystemTestBase::_init(MAV_AUTOPILOT autopilot)
{
UnitTest::init();
MockLink* link = new MockLink();
link->setFirmwareType(autopilot);
LinkManager::instance()->_addLink(link);
_connectMockLink(autopilot);
LinkManager::instance()->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());
_plugin = MultiVehicleManager::instance()->activeVehicle()->autopilotPlugin();
_plugin = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()->autopilotPlugin();
Q_ASSERT(_plugin);
}
......
......@@ -50,7 +50,7 @@ ParameterLoader::ParameterLoader(AutoPilotPlugin* autopilot, Vehicle* vehicle, Q
QObject(parent),
_autopilot(autopilot),
_vehicle(vehicle),
_mavlink(MAVLinkProtocol::instance()),
_mavlink(qgcApp()->toolbox()->mavlinkProtocol()),
_parametersReady(false),
_initialLoadComplete(false),
_defaultComponentId(FactSystem::defaultComponentId),
......@@ -308,7 +308,7 @@ void ParameterLoader::refreshAllParameters(void)
_dataMutex.unlock();
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance();
MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol();
Q_ASSERT(mavlink);
mavlink_message_t msg;
......@@ -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 */
_cacheTimeoutTimer.start();
MAVLinkProtocol* mavlink = MAVLinkProtocol::instance();
MAVLinkProtocol* mavlink = qgcApp()->toolbox()->mavlinkProtocol();
Q_ASSERT(mavlink);
mavlink_message_t msg;
......@@ -825,7 +825,7 @@ void ParameterLoader::_checkInitialLoadComplete(void)
// Check for any errors during vehicle boot
UASMessageHandler* msgHandler = UASMessageHandler::instance();
UASMessageHandler* msgHandler = qgcApp()->toolbox()->uasMessageHandler();
if (msgHandler->getErrorCountTotal()) {
QString errors;
bool firstError = true;
......
......@@ -139,8 +139,7 @@ QString APMCustomMode::modeString() const
return mode;
}
APMFirmwarePlugin::APMFirmwarePlugin(QObject* parent)
: FirmwarePlugin(parent)
APMFirmwarePlugin::APMFirmwarePlugin(void)
{
_textSeverityAdjustmentNeeded = false;
}
......
......@@ -94,7 +94,7 @@ public:
protected:
/// All access to singleton is through stack specific implementation
APMFirmwarePlugin(QObject* parent = NULL);
APMFirmwarePlugin(void);
void setSupportedModes(QList<APMCustomMode> supportedModes);
private:
......
......@@ -53,8 +53,7 @@ APMCopterMode::APMCopterMode(uint32_t mode, bool settable) : APMCustomMode(mode,
setEnumToStringMapping(enumToString);
}
ArduCopterFirmwarePlugin::ArduCopterFirmwarePlugin(QObject* parent) :
APMFirmwarePlugin(parent)
ArduCopterFirmwarePlugin::ArduCopterFirmwarePlugin(void)
{
QList<APMCustomMode> supportedFlightModes;
supportedFlightModes << APMCopterMode(APMCopterMode::STABILIZE ,true);
......
......@@ -68,7 +68,7 @@ public:
protected:
/// All access to singleton is through instance()
ArduCopterFirmwarePlugin(QObject* parent = NULL);
ArduCopterFirmwarePlugin(void);
private:
};
......
......@@ -50,8 +50,7 @@ APMPlaneMode::APMPlaneMode(uint32_t mode, bool settable) : APMCustomMode(mode, s
setEnumToStringMapping(enumToString);
}
ArduPlaneFirmwarePlugin::ArduPlaneFirmwarePlugin(QObject* parent) :
APMFirmwarePlugin(parent)
ArduPlaneFirmwarePlugin::ArduPlaneFirmwarePlugin(void)
{
QList<APMCustomMode> supportedFlightModes;
supportedFlightModes << APMPlaneMode(APMPlaneMode::MANUAL ,true);
......
......@@ -66,7 +66,7 @@ public:
protected:
/// All access to singleton is through instance()
ArduPlaneFirmwarePlugin(QObject* parent = NULL);
ArduPlaneFirmwarePlugin(void);
private:
};
......
......@@ -44,8 +44,7 @@ APMRoverMode::APMRoverMode(uint32_t mode, bool settable) : APMCustomMode(mode, s
setEnumToStringMapping(enumToString);
}
ArduRoverFirmwarePlugin::ArduRoverFirmwarePlugin(QObject* parent) :
APMFirmwarePlugin(parent)
ArduRoverFirmwarePlugin::ArduRoverFirmwarePlugin(void)
{
QList<APMCustomMode> supportedFlightModes;
supportedFlightModes << APMRoverMode(APMRoverMode::MANUAL ,true);
......
......@@ -66,7 +66,7 @@ public:
protected:
/// All access to singleton is through instance()
ArduRoverFirmwarePlugin(QObject* parent = NULL);
ArduRoverFirmwarePlugin(void);
private:
};
......
......@@ -112,7 +112,7 @@ public:
virtual void addMetaDataToFact(Fact* fact) = 0;
protected:
FirmwarePlugin(QObject* parent = NULL) : QGCSingleton(parent) { }
FirmwarePlugin(void) { };
};
#endif
......@@ -31,19 +31,6 @@
#include "APM/ArduRoverFirmwarePlugin.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)
{
switch (autopilotType) {
......
......@@ -29,29 +29,26 @@
#include <QObject>
#include "QGCSingleton.h"
#include "FirmwarePlugin.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.
class FirmwarePluginManager : public QGCSingleton
class FirmwarePluginManager : public QGCTool
{
Q_OBJECT
DECLARE_QGC_SINGLETON(FirmwarePluginManager, FirmwarePluginManager)
public:
FirmwarePluginManager(QGCApplication* app) : QGCTool(app) { }
/// Returns appropriate plugin for autopilot type.
/// @param autopilotType 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.
FirmwarePlugin* firmwarePluginForAutopilot(MAV_AUTOPILOT autopilotType, MAV_TYPE vehicleType);
private:
/// All access to singleton is through FirmwarePluginManager::instance
FirmwarePluginManager(QObject* parent = NULL);
~FirmwarePluginManager();
};
#endif
......@@ -31,8 +31,7 @@
IMPLEMENT_QGC_SINGLETON(GenericFirmwarePlugin, FirmwarePlugin)
GenericFirmwarePlugin::GenericFirmwarePlugin(QObject* parent)
: FirmwarePlugin(parent)
GenericFirmwarePlugin::GenericFirmwarePlugin(void)
{
}
......
......@@ -51,8 +51,7 @@ public:
virtual QString getDefaultComponentIdParam(void) const { return QString(); }
private:
/// All access to singleton is through AutoPilotPluginManager::instance
GenericFirmwarePlugin(QObject* parent = NULL);
GenericFirmwarePlugin(void);
};
#endif
......@@ -88,8 +88,7 @@ static const struct Modes2Name rgModes2Name[] = {
};
PX4FirmwarePlugin::PX4FirmwarePlugin(QObject* parent)
: FirmwarePlugin(parent)
PX4FirmwarePlugin::PX4FirmwarePlugin(void)
{
}
......
......@@ -53,7 +53,7 @@ public:
private:
/// All access to singleton is through AutoPilotPluginManager::instance
PX4FirmwarePlugin(QObject* parent = NULL);
PX4FirmwarePlugin(void);
PX4ParameterMetaData _parameterMetaData;
};
......
......@@ -26,27 +26,26 @@
#include <QSettings>
#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::_settingsGroup = "FlightMapSettings";
const char* FlightMapSettings::_mapProviderKey = "MapProvider";
const char* FlightMapSettings::_mapTypeKey = "MapType";
FlightMapSettings::FlightMapSettings(QObject* parent)
: QObject(parent)
FlightMapSettings::FlightMapSettings(QGCApplication* app)
: QGCTool(app)
, _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)
......
......@@ -24,17 +24,18 @@ This file is part of the QGROUNDCONTROL project
#ifndef FlightMapSettings_H
#define FlightMapSettings_H
#include "QGCSingleton.h"
#include "QGCToolbox.h"
#include <QObject>
#include <QStringList>
class FlightMapSettings : public QObject
class FlightMapSettings : public QGCTool
{
Q_OBJECT
DECLARE_QGC_SINGLETON(FlightMapSettings, FlightMapSettings)
public:
FlightMapSettings(QGCApplication* app);
/// mapProvider is either Bing, Google or Open to specify to set of maps available
Q_PROPERTY(QString mapProvider READ mapProvider WRITE setMapProvider NOTIFY mapProviderChanged)
......@@ -54,15 +55,14 @@ public:
QString mapProvider(void);
void setMapProvider(const QString& mapProvider);
// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
signals:
void mapProviderChanged(const QString& mapProvider);
void mapTypesChanged(const QStringList& mapTypes);
private:
/// @brief All access to FlightMapSettings singleton is through FlightMapSettings::instance
FlightMapSettings(QObject* parent = NULL);
~FlightMapSettings();
void _storeSettings(void);
void _loadSettings(void);
......
......@@ -43,12 +43,10 @@ This file is part of the QGROUNDCONTROL project
#include <QtAndroidExtras/QAndroidJniObject>
#endif
IMPLEMENT_QGC_SINGLETON(GAudioOutput, GAudioOutput)
const char* GAudioOutput::_mutedKey = "AudioMuted";
GAudioOutput::GAudioOutput(QObject *parent)
: QGCSingleton(parent)
GAudioOutput::GAudioOutput(QGCApplication* app)
: QGCTool(app)
, muted(false)
#ifndef __android__
, thread(new QThread())
......@@ -57,7 +55,7 @@ GAudioOutput::GAudioOutput(QObject *parent)
{
QSettings settings;
muted = settings.value(_mutedKey, false).toBool();
muted |= qgcApp()->runningUnitTests();
muted |= app->runningUnitTests();
#ifndef __android__
worker->moveToThread(thread);
connect(this, &GAudioOutput::textToSpeak, worker, &QGCAudioWorker::say);
......
......@@ -38,20 +38,23 @@ This file is part of the PIXHAWK project
#include <QStringList>
#include "QGCAudioWorker.h"
#include "QGCSingleton.h"
#include "QGCToolbox.h"
class QGCApplication;
/**
* @brief Audio Output (speech synthesizer and "beep" output)
* This class follows the singleton design pattern
* @see http://en.wikipedia.org/wiki/Singleton_pattern
*/
class GAudioOutput : public QGCSingleton
class GAudioOutput : public QGCTool
{
Q_OBJECT
DECLARE_QGC_SINGLETON(GAudioOutput, GAudioOutput)
public:
GAudioOutput(QGCApplication* app);
~GAudioOutput();
/** @brief List available voices */
QStringList listVoices(void);
enum
......@@ -95,9 +98,6 @@ protected:
#endif
private:
GAudioOutput(QObject *parent = NULL);
~GAudioOutput();
static const char* _mutedKey;
};
......
......@@ -39,27 +39,27 @@
#define MEAN_EARTH_DIAMETER 12756274.0
#define UMR 0.017453292519943295769236907684886
IMPLEMENT_QGC_SINGLETON(HomePositionManager, HomePositionManager)
const char* HomePositionManager::_settingsGroup = "HomePositionManager";
const char* HomePositionManager::_latitudeKey = "Latitude";
const char* HomePositionManager::_longitudeKey = "Longitude";
const char* HomePositionManager::_altitudeKey = "Altitude";
HomePositionManager::HomePositionManager(QObject* parent)
: QObject(parent)
HomePositionManager::HomePositionManager(QGCApplication* app)
: QGCTool(app)
, homeLat(47.3769)
, homeLon(8.549444)
, 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)
......@@ -116,7 +116,7 @@ void HomePositionManager::_loadSettings(void)
settings.endGroup();
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
......@@ -169,7 +169,7 @@ bool HomePositionManager::setHomePositionAndNotify(double lat, double lon, doubl
bool changed = setHomePosition(lat, lon, alt);
if (changed) {
MultiVehicleManager::instance()->setHomePositionForAllVehicles(homeLat, homeLon, homeAlt);
qgcApp()->toolbox()->multiVehicleManager()->setHomePositionForAllVehicles(homeLat, homeLon, homeAlt);
}
return changed;
......@@ -218,9 +218,10 @@ void HomePositionManager::deleteHomePosition(const QString& name)
_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)
, _coordinate(coordinate)
, _homePositionManager(homePositionManager)
{
setObjectName(name);
}
......@@ -238,7 +239,7 @@ QString HomePosition::name(void)
void HomePosition::setName(const QString& name)
{
setObjectName(name);
HomePositionManager::instance()->_storeSettings();
_homePositionManager->_storeSettings();
emit nameChanged(name);
}
......@@ -250,6 +251,6 @@ QGeoCoordinate HomePosition::coordinate(void)
void HomePosition::setCoordinate(const QGeoCoordinate& coordinate)
{
_coordinate = coordinate;
HomePositionManager::instance()->_storeSettings();
_homePositionManager->_storeSettings();
emit coordinateChanged(coordinate);
}
......@@ -24,17 +24,19 @@ This file is part of the QGROUNDCONTROL project
#ifndef HomePositionManager_H
#define HomePositionManager_H
#include "QGCSingleton.h"
#include "QmlObjectListModel.h"
#include "QGCToolbox.h"
#include <QGeoCoordinate>
class HomePositionManager;
class HomePosition : public QObject
{
Q_OBJECT
public:
HomePosition(const QString& name, const QGeoCoordinate& coordinate, QObject* parent = NULL);
HomePosition(const QString& name, const QGeoCoordinate& coordinate, HomePositionManager* homePositionManager, QObject* parent = NULL);
~HomePosition();
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
......@@ -47,22 +49,23 @@ public:
QGeoCoordinate coordinate(void);
void setCoordinate(const QGeoCoordinate& coordinate);
signals:
void nameChanged(const QString& name);
void coordinateChanged(const QGeoCoordinate& coordinate);
private:
QGeoCoordinate _coordinate;
QGeoCoordinate _coordinate;