Skip to content

Commit bc724b5

Browse files
committed
AutoPilotPlugins: Cleanup
1 parent 03af084 commit bc724b5

18 files changed

+902
-1186
lines changed

src/AutoPilotPlugins/AutoPilotPlugin.cc

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,43 @@
77
*
88
****************************************************************************/
99

10-
11-
/// @file
12-
/// @author Don Gagne <[email protected]>
13-
1410
#include "AutoPilotPlugin.h"
15-
#include "QGCApplication.h"
1611
#include "FirmwarePlugin.h"
12+
#include "QGCApplication.h"
13+
#include "QGCLoggingCategory.h"
1714
#include "Vehicle.h"
1815
#include "VehicleComponent.h"
16+
1917
#include <QtCore/QCoreApplication>
2018

21-
AutoPilotPlugin::AutoPilotPlugin(Vehicle* vehicle, QObject* parent)
19+
QGC_LOGGING_CATEGORY(AutoPilotPluginLog, "qgc.autopilotplugin.autopilotplugin");
20+
21+
AutoPilotPlugin::AutoPilotPlugin(Vehicle *vehicle, QObject *parent)
2222
: QObject(parent)
2323
, _vehicle(vehicle)
2424
, _firmwarePlugin(vehicle->firmwarePlugin())
25-
, _setupComplete(false)
2625
{
27-
26+
// qCDebug(AutoPilotPluginLog) << Q_FUNC_INFO << this;
2827
}
2928

3029
AutoPilotPlugin::~AutoPilotPlugin()
3130
{
32-
31+
// qCDebug(AutoPilotPluginLog) << Q_FUNC_INFO << this;
3332
}
3433

35-
void AutoPilotPlugin::_recalcSetupComplete(void)
34+
void AutoPilotPlugin::_recalcSetupComplete()
3635
{
3736
bool newSetupComplete = true;
3837

39-
for(const QVariant& componentVariant: vehicleComponents()) {
40-
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
38+
for (const QVariant &componentVariant : vehicleComponents()) {
39+
const VehicleComponent *const component = qobject_cast<const VehicleComponent*>(qvariant_cast<const QObject*>(componentVariant));
4140
if (component) {
4241
if (!component->setupComplete()) {
4342
newSetupComplete = false;
4443
break;
4544
}
4645
} else {
47-
qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
46+
qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
4847
}
4948
}
5049

@@ -54,22 +53,17 @@ void AutoPilotPlugin::_recalcSetupComplete(void)
5453
}
5554
}
5655

57-
bool AutoPilotPlugin::setupComplete(void) const
58-
{
59-
return _setupComplete;
60-
}
61-
62-
void AutoPilotPlugin::parametersReadyPreChecks(void)
56+
void AutoPilotPlugin::parametersReadyPreChecks()
6357
{
6458
_recalcSetupComplete();
6559

6660
// Connect signals in order to keep setupComplete up to date
67-
for(QVariant componentVariant: vehicleComponents()) {
68-
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
61+
for (QVariant componentVariant : vehicleComponents()) {
62+
VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject*>(componentVariant));
6963
if (component) {
70-
connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
64+
(void) connect(component, &VehicleComponent::setupCompleteChanged, this, &AutoPilotPlugin::_recalcSetupComplete);
7165
} else {
72-
qWarning() << "AutoPilotPlugin::_recalcSetupComplete Incorrectly typed VehicleComponent";
66+
qCWarning(AutoPilotPluginLog) << "Incorrectly typed VehicleComponent";
7367
}
7468
}
7569

@@ -82,12 +76,12 @@ void AutoPilotPlugin::parametersReadyPreChecks(void)
8276
}
8377
}
8478

85-
VehicleComponent* AutoPilotPlugin::findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
79+
VehicleComponent *AutoPilotPlugin::findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent)
8680
{
8781
if (knownVehicleComponent != UnknownVehicleComponent) {
88-
for(const QVariant& componentVariant: vehicleComponents()) {
89-
VehicleComponent* component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
90-
if (component && component->KnownVehicleComponent() == knownVehicleComponent) {
82+
for (const QVariant &componentVariant: vehicleComponents()) {
83+
VehicleComponent *const component = qobject_cast<VehicleComponent*>(qvariant_cast<QObject *>(componentVariant));
84+
if (component && (component->KnownVehicleComponent() == knownVehicleComponent)) {
9185
return component;
9286
}
9387
}

src/AutoPilotPlugins/AutoPilotPlugin.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,30 @@
99

1010
#pragma once
1111

12+
#include <QtCore/QLoggingCategory>
1213
#include <QtCore/QObject>
1314
#include <QtCore/QString>
1415
#include <QtCore/QVariantList>
1516

16-
class Vehicle;
1717
class FirmwarePlugin;
18+
class Vehicle;
1819
class VehicleComponent;
1920

20-
/// This is the base class for AutoPilot plugins
21-
///
21+
Q_DECLARE_LOGGING_CATEGORY(AutoPilotPluginLog)
22+
2223
/// The AutoPilotPlugin class is an abstract base class which represent the methods and objects
2324
/// which are specific to a certain AutoPilot. This is the only place where AutoPilot specific
2425
/// code should reside in QGroundControl. The remainder of the QGroundControl source is
2526
/// generic to a common mavlink implementation.
26-
2727
class AutoPilotPlugin : public QObject
2828
{
2929
Q_OBJECT
30+
Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents NOTIFY vehicleComponentsChanged) ///< List of VehicleComponent objects
31+
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) ///< false: One or more vehicle components require setup
3032

3133
public:
32-
AutoPilotPlugin(Vehicle* vehicle, QObject* parent);
33-
~AutoPilotPlugin();
34+
explicit AutoPilotPlugin(Vehicle *vehicle, QObject *parent = nullptr);
35+
virtual ~AutoPilotPlugin();
3436

3537
// Vehicle Components which are available for firmware types
3638
enum KnownVehicleComponent {
@@ -43,35 +45,30 @@ class AutoPilotPlugin : public QObject
4345
};
4446
Q_ENUM(KnownVehicleComponent)
4547

46-
Q_PROPERTY(QVariantList vehicleComponents READ vehicleComponents NOTIFY vehicleComponentsChanged) ///< List of VehicleComponent objects
47-
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged) ///< false: One or more vehicle components require setup
48-
4948
/// Called when parameters are ready for the first time. Note that parameters may still be missing.
5049
/// Overrides must call base class.
51-
virtual void parametersReadyPreChecks(void);
50+
virtual void parametersReadyPreChecks();
5251

5352
// Must be implemented by derived class
54-
virtual const QVariantList& vehicleComponents(void) = 0;
53+
virtual const QVariantList &vehicleComponents() = 0;
5554

5655
/// Returns the name of the vehicle component which must complete setup prior to this one. Empty string for none.
57-
Q_INVOKABLE virtual QString prerequisiteSetup(VehicleComponent* component) const = 0;
58-
59-
Q_INVOKABLE VehicleComponent* findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent);
56+
Q_INVOKABLE virtual QString prerequisiteSetup(VehicleComponent *component) const = 0;
6057

61-
Q_INVOKABLE bool knownVehicleComponentAvailable(KnownVehicleComponent knownVehicleComponent) { return findKnownVehicleComponent(knownVehicleComponent) != nullptr; }
58+
Q_INVOKABLE VehicleComponent *findKnownVehicleComponent(KnownVehicleComponent knownVehicleComponent);
59+
Q_INVOKABLE bool knownVehicleComponentAvailable(KnownVehicleComponent knownVehicleComponent) { return (findKnownVehicleComponent(knownVehicleComponent) != nullptr); }
6260

63-
// Property accessors
64-
bool setupComplete(void) const;
61+
bool setupComplete() const { return _setupComplete; }
6562

6663
signals:
67-
void setupCompleteChanged (void);
68-
void vehicleComponentsChanged (void);
64+
void setupCompleteChanged();
65+
void vehicleComponentsChanged();
6966

7067
protected:
71-
Vehicle* _vehicle;
72-
FirmwarePlugin* _firmwarePlugin;
73-
bool _setupComplete;
68+
Vehicle *_vehicle = nullptr;
69+
FirmwarePlugin *_firmwarePlugin = nullptr;
70+
bool _setupComplete = false;
7471

7572
private slots:
76-
void _recalcSetupComplete(void);
73+
void _recalcSetupComplete();
7774
};

src/AutoPilotPlugins/Common/ESP8266Component.cc

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,11 @@
77
*
88
****************************************************************************/
99

10-
1110
#include "ESP8266Component.h"
12-
#include "AutoPilotPlugin.h"
1311

14-
ESP8266Component::ESP8266Component(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
12+
ESP8266Component::ESP8266Component(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent)
1513
: VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
1614
, _name(tr("WiFi Bridge"))
1715
{
1816

1917
}
20-
21-
QString ESP8266Component::name(void) const
22-
{
23-
return _name;
24-
}
25-
26-
QString ESP8266Component::description(void) const
27-
{
28-
return tr("The ESP8266 WiFi Bridge Component is used to setup the WiFi link.");
29-
}
30-
31-
QString ESP8266Component::iconResource(void) const
32-
{
33-
return "/qmlimages/wifi.svg";
34-
}
35-
36-
bool ESP8266Component::requiresSetup(void) const
37-
{
38-
return false;
39-
}
40-
41-
bool ESP8266Component::setupComplete(void) const
42-
{
43-
return true;
44-
}
45-
46-
QStringList ESP8266Component::setupCompleteChangedTriggerList(void) const
47-
{
48-
return QStringList();
49-
}
50-
51-
QUrl ESP8266Component::setupSource(void) const
52-
{
53-
return QUrl::fromUserInput("qrc:/qml/ESP8266Component.qml");
54-
}
55-
56-
QUrl ESP8266Component::summaryQmlSource(void) const
57-
{
58-
return QUrl::fromUserInput("qrc:/qml/ESP8266ComponentSummary.qml");
59-
}

src/AutoPilotPlugins/Common/ESP8266Component.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,27 @@
77
*
88
****************************************************************************/
99

10-
1110
#pragma once
1211

1312
#include "VehicleComponent.h"
1413

1514
class ESP8266Component : public VehicleComponent
1615
{
1716
Q_OBJECT
17+
1818
public:
19-
ESP8266Component (Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent = nullptr);
20-
21-
// Virtuals from VehicleComponent
22-
QStringList setupCompleteChangedTriggerList() const;
23-
24-
// Virtuals from VehicleComponent
25-
QString name () const;
26-
QString description () const;
27-
QString iconResource () const;
28-
bool requiresSetup () const;
29-
bool setupComplete () const;
30-
QUrl setupSource () const;
31-
QUrl summaryQmlSource () const;
32-
19+
explicit ESP8266Component(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent = nullptr);
20+
21+
QStringList setupCompleteChangedTriggerList() const final { return QStringList(); }
22+
QString name() const final { return _name; }
23+
QString description() const final { return tr("The ESP8266 WiFi Bridge Component is used to setup the WiFi link."); }
24+
QString iconResource() const final { return QStringLiteral("/qmlimages/wifi.svg"); }
25+
bool requiresSetup() const final { return false; }
26+
bool setupComplete() const final { return true; }
27+
QUrl setupSource() const final { return QUrl::fromUserInput("qrc:/qml/ESP8266Component.qml"); }
28+
QUrl summaryQmlSource() const final { return QUrl::fromUserInput("qrc:/qml/ESP8266ComponentSummary.qml"); }
29+
3330
private:
34-
const QString _name;
35-
QVariantList _summaryItems;
31+
const QString _name;
32+
QVariantList _summaryItems;
3633
};

0 commit comments

Comments
 (0)