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

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
Supports Markdown
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