Skip to content

Commit

Permalink
Convert QGCCorePlugin to Singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Nov 29, 2024
1 parent 4797dd7 commit 2815f53
Show file tree
Hide file tree
Showing 75 changed files with 339 additions and 531 deletions.
1 change: 0 additions & 1 deletion custom-example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ target_link_libraries(CustomPlugin
PUBLIC
Qt6::Core
MAVLink
QGC
Settings
)

Expand Down
6 changes: 6 additions & 0 deletions custom-example/qgcimages.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<file alias="attitudePointer.svg">../src/FlightMap/Images/attitudePointer.svg</file>
<file alias="AwarenessAircraft.svg">../src/FlightMap/Images/AwarenessAircraft.svg</file>
<file alias="Battery.svg">../src/UI/toolbar/Images/Battery.svg</file>
<file alias="BatteryGreen.svg">../src/UI/toolbar/Images/BatteryGreen.svg</file>
<file alias="BatteryYellowGreen.svg">../src/UI/toolbar/Images/BatteryYellowGreen.svg</file>
<file alias="BatteryYellow.svg">../src/UI/toolbar/Images/BatteryYellow.svg</file>
<file alias="BatteryOrange.svg">../src/UI/toolbar/Images/BatteryOrange.svg</file>
<file alias="BatteryCritical.svg">../src/UI/toolbar/Images/BatteryCritical.svg</file>
<file alias="BatteryEMERGENCY.svg">../src/UI/toolbar/Images/BatteryEMERGENCY.svg</file>
<file alias="camera.svg">../resources/camera.svg</file>
<file alias="camera_photo.svg">../src/Camera/images/camera_photo.svg</file>
<file alias="camera_video.svg">../src/Camera/images/camera_video.svg</file>
Expand Down
2 changes: 1 addition & 1 deletion custom-example/qgcresources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<file alias="SplashScreen">../resources/SplashScreen.png</file>
<file alias="Stop">../resources/Stop.svg</file>
<file alias="takeoff.svg">../resources/takeoff.svg</file>
<file alias="terrain.svg">resources/terrain.svg</file>
<file alias="terrain.svg">../resources/terrain.svg</file>
<file alias="TrashDelete.svg">../resources/TrashDelete.svg</file>
<file alias="waves.svg">../resources/waves.svg</file>
<file alias="wind-guru.svg">../resources/wind-guru.svg</file>
Expand Down
6 changes: 4 additions & 2 deletions custom-example/qgroundcontrol.qrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<RCC>
<qresource prefix="/toolbar">
<file alias="ArmedIndicator.qml">../src/UI/toolbar/ArmedIndicator.qml</file>
<file alias="GPSIndicator.qml">../src/UI/toolbar/GPSIndicator.qml</file>
<file alias="GPSRTKIndicator.qml">../src/UI/toolbar/GPSRTKIndicator.qml</file>
<file alias="RTKGPSIndicator.qml">../src/UI/toolbar/RTKGPSIndicator.qml</file>
<file alias="VehicleGPSIndicator.qml">../src/UI/toolbar/VehicleGPSIndicator.qml</file>
<file alias="JoystickIndicator.qml">../src/UI/toolbar/JoystickIndicator.qml</file>
<file alias="LinkIndicator.qml">../src/UI/toolbar/LinkIndicator.qml</file>
<file alias="MessageIndicator.qml">../src/UI/toolbar/MessageIndicator.qml</file>
Expand Down Expand Up @@ -103,6 +103,7 @@
<file alias="QGroundControl/Controls/FlightModeDropdown.qml">../src/QmlControls/FlightModeDropdown.qml</file>
<file alias="QGroundControl/Controls/FlightModeMenu.qml">../src/QmlControls/FlightModeMenu.qml</file>
<file alias="QGroundControl/Controls/FWLandingPatternMapVisual.qml">../src/PlanView/FWLandingPatternMapVisual.qml</file>
<file alias="QGroundControl/Controls/GPSIndicator.qml">../src/UI/toolbar/GPSIndicator.qml</file>
<file alias="QGroundControl/Controls/GPSIndicatorPage.qml">../src/UI/toolbar/GPSIndicatorPage.qml</file>
<file alias="QGroundControl/Controls/GeoFenceEditor.qml">../src/PlanView/GeoFenceEditor.qml</file>
<file alias="QGroundControl/Controls/GeoFenceMapVisuals.qml">../src/PlanView/GeoFenceMapVisuals.qml</file>
Expand Down Expand Up @@ -418,6 +419,7 @@
<file alias="VTOLLandingPattern.FactMetaData.json">../src/MissionManager/VTOLLandingPattern.FactMetaData.json</file>
<file alias="Viewer3D.SettingsGroup.json">../src/Settings/Viewer3D.SettingsGroup.json</file>
<file alias="GimbalController.SettingsGroup.json">../src/Settings/GimbalController.SettingsGroup.json</file>
<file alias="CameraMetaData.json">../src/Camera/CameraMetaData.json</file>
</qresource>
<qresource prefix="/MockLink">
<file alias="APMArduSubMockLink.params">../src/Comms/MockLink/APMArduSubMockLink.params</file>
Expand Down
5 changes: 2 additions & 3 deletions custom-example/src/AutoPilotPlugin/CustomAutoPilotPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

#include "CustomAutoPilotPlugin.h"
#include "ParameterManager.h"
#include "QGCApplication.h"
#include "QGCCorePlugin.h"
#include "Vehicle.h"

CustomAutoPilotPlugin::CustomAutoPilotPlugin(Vehicle* vehicle, QObject* parent)
: PX4AutoPilotPlugin(vehicle, parent)
{
// Whenever we go on/out of advanced mode the available list of settings pages will change
connect(qgcApp()->toolbox()->corePlugin(), &QGCCorePlugin::showAdvancedUIChanged, this, &CustomAutoPilotPlugin::_advancedChanged);
connect(QGCCorePlugin::instance(), &QGCCorePlugin::showAdvancedUIChanged, this, &CustomAutoPilotPlugin::_advancedChanged);
}

// This signals that when Advanced Mode changes the list of Vehicle Settings page also changed
Expand All @@ -35,7 +34,7 @@ const QVariantList& CustomAutoPilotPlugin::vehicleComponents()
{
if (_components.count() == 0 && !_incorrectParameterVersion) {
if (_vehicle) {
bool showAdvanced = qgcApp()->toolbox()->corePlugin()->showAdvancedUI();
bool showAdvanced = QGCCorePlugin::instance()->showAdvancedUI();
if (_vehicle->parameterManager()->parametersReady()) {
if (showAdvanced) {
_airframeComponent = new AirframeComponent(_vehicle, this);
Expand Down
30 changes: 17 additions & 13 deletions custom-example/src/CustomPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
*/

#include "CustomPlugin.h"
#include "QGCApplication.h"
#include "QmlComponentInfo.h"
#include "QGCPalette.h"
#include "QGCMAVLink.h"
#include "AppSettings.h"
#include "BrandImageSettings.h"

#include <QtCore/qapplicationstatic.h>
#include <QtQml/QQmlApplicationEngine>

QGC_LOGGING_CATEGORY(CustomLog, "gcs.custom.customplugin")

Q_APPLICATION_STATIC(CustomPlugin, _customPluginInstance);

CustomFlyViewOptions::CustomFlyViewOptions(CustomOptions* options, QObject* parent)
: QGCFlyViewOptions(options, parent)
{
Expand All @@ -37,9 +41,11 @@ bool CustomFlyViewOptions::showInstrumentPanel(void) const
return false;
}

CustomOptions::CustomOptions(CustomPlugin*, QObject* parent)
CustomOptions::CustomOptions(CustomPlugin *plugin, QObject *parent)
: QGCOptions(parent)
, _plugin(plugin)
{
Q_CHECK_PTR(_plugin);
}

QGCFlyViewOptions* CustomOptions::flyViewOptions(void)
Expand All @@ -53,7 +59,7 @@ QGCFlyViewOptions* CustomOptions::flyViewOptions(void)
// Firmware upgrade page is only shown in Advanced Mode.
bool CustomOptions::showFirmwareUpgrade() const
{
return qgcApp()->toolbox()->corePlugin()->showAdvancedUI();
return _plugin->showAdvancedUI();
}

// Normal QGC needs to work with an ESP8266 WiFi thing which is remarkably crappy. This in turns causes PX4 Pro calibration to fail
Expand All @@ -64,23 +70,21 @@ bool CustomOptions::wifiReliableForCalibration(void) const
return true;
}

CustomPlugin::CustomPlugin(QGCApplication *app, QGCToolbox* toolbox)
: QGCCorePlugin(app, toolbox)
CustomPlugin::CustomPlugin(QObject *parent)
: QGCCorePlugin(parent)
, _options(new CustomOptions(this, this))
{
_options = new CustomOptions(this, this);
_showAdvancedUI = false;
connect(this, &QGCCorePlugin::showAdvancedUIChanged, this, &CustomPlugin::_advancedChanged);
}

CustomPlugin::~CustomPlugin()
{
}

void CustomPlugin::setToolbox(QGCToolbox* toolbox)
QGCCorePlugin *CustomPlugin::instance()
{
QGCCorePlugin::setToolbox(toolbox);

// Allows us to be notified when the user goes in/out out advanced mode
connect(qgcApp()->toolbox()->corePlugin(), &QGCCorePlugin::showAdvancedUIChanged, this, &CustomPlugin::_advancedChanged);
return _customPluginInstance();
}

void CustomPlugin::_advancedChanged(bool changed)
Expand Down Expand Up @@ -116,7 +120,7 @@ QString CustomPlugin::brandImageOutdoor(void) const
return QStringLiteral("/custom/img/dronecode-black.svg");
}

bool CustomPlugin::overrideSettingsGroupVisibility(QString name)
bool CustomPlugin::overrideSettingsGroupVisibility(const QString &name)
{
// We have set up our own specific brand imaging. Hide the brand image settings such that the end user
// can't change it.
Expand Down Expand Up @@ -147,7 +151,7 @@ bool CustomPlugin::adjustSettingMetaData(const QString& settingsGroup, FactMetaD
}

// This modifies QGC colors palette to match possible custom corporate branding
void CustomPlugin::paletteOverride(QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo)
void CustomPlugin::paletteOverride(const QString &colorName, QGCPalette::PaletteColorInfo_t& colorInfo)
{
if (colorName == QStringLiteral("window")) {
colorInfo[QGCPalette::Dark][QGCPalette::ColorGroupEnabled] = QColor("#212529");
Expand Down
18 changes: 9 additions & 9 deletions custom-example/src/CustomPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "QGCCorePlugin.h"
#include "QGCOptions.h"
#include <QGCLoggingCategory.h>
#include "QGCLoggingCategory.h"

class CustomOptions;
class CustomPlugin;
Expand All @@ -37,36 +37,36 @@ class CustomFlyViewOptions : public QGCFlyViewOptions
class CustomOptions : public QGCOptions
{
public:
CustomOptions(CustomPlugin*, QObject* parent = nullptr);
CustomOptions(CustomPlugin *plugin, QObject* parent = nullptr);

// Overrides from QGCOptions
bool wifiReliableForCalibration (void) const final;
bool showFirmwareUpgrade (void) const final;
QGCFlyViewOptions* flyViewOptions(void) final;

private:
CustomFlyViewOptions* _flyViewOptions = nullptr;
QGCCorePlugin *_plugin = nullptr;
CustomFlyViewOptions *_flyViewOptions = nullptr;
};

class CustomPlugin : public QGCCorePlugin
{
Q_OBJECT
public:
CustomPlugin(QGCApplication* app, QGCToolbox *toolbox);
CustomPlugin(QObject *parent = nullptr);
~CustomPlugin();

static QGCCorePlugin *instance();

// Overrides from QGCCorePlugin
QGCOptions* options (void) final;
QString brandImageIndoor (void) const final;
QString brandImageOutdoor (void) const final;
bool overrideSettingsGroupVisibility (QString name) final;
bool overrideSettingsGroupVisibility (const QString &name) final;
bool adjustSettingMetaData (const QString& settingsGroup, FactMetaData& metaData) final;
void paletteOverride (QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo) final;
void paletteOverride (const QString &colorName, QGCPalette::PaletteColorInfo_t& colorInfo) final;
QQmlApplicationEngine* createQmlApplicationEngine (QObject* parent) final;

// Overrides from QGCTool
void setToolbox (QGCToolbox* toolbox);

private slots:
void _advancedChanged(bool advanced);

Expand Down
5 changes: 4 additions & 1 deletion src/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ target_link_libraries(API
Qt6::Core
Qt6::Gui
MAVLink
QGC
QmlControls
)

target_include_directories(API PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

if(QGC_CUSTOM_BUILD)
target_link_libraries(API PRIVATE CustomPlugin)
endif()
Loading

0 comments on commit 2815f53

Please sign in to comment.