From 290362a1ba8c2c10dffc347ff3683e55dfd3da07 Mon Sep 17 00:00:00 2001 From: Holden Date: Fri, 21 Feb 2025 23:32:26 -0500 Subject: [PATCH] FactControls: Cleanup FactPanelController --- .../FactControls/FactPanelController.cc | 62 ++++++++++--------- .../FactControls/FactPanelController.h | 35 +++++------ 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/FactSystem/FactControls/FactPanelController.cc b/src/FactSystem/FactControls/FactPanelController.cc index cc8760f6f0a..18bd04d8d22 100644 --- a/src/FactSystem/FactControls/FactPanelController.cc +++ b/src/FactSystem/FactControls/FactPanelController.cc @@ -8,24 +8,23 @@ ****************************************************************************/ #include "FactPanelController.h" +#include "AutoPilotPlugin.h" #include "MultiVehicleManager.h" -#include "QGCApplication.h" #include "ParameterManager.h" -#include "AutoPilotPlugin.h" -#include "Vehicle.h" +#include "QGCApplication.h" #include "QGCLoggingCategory.h" +#include "Vehicle.h" #include -/// @file -/// @author Don Gagne - -QGC_LOGGING_CATEGORY(FactPanelControllerLog, "FactPanelControllerLog") +QGC_LOGGING_CATEGORY(FactPanelControllerLog, "qgc.factsystem.factcontrols.factpanelcontroller") FactPanelController::FactPanelController(QObject *parent) : QObject(parent) + , _vehicle(MultiVehicleManager::instance()->activeVehicle()) { - _vehicle = MultiVehicleManager::instance()->activeVehicle(); + // qCDebug(FactPanelControllerLog) << Q_FUNC_INFO << this; + if (_vehicle) { _autopilot = _vehicle->autopilotPlugin(); } else { @@ -34,24 +33,29 @@ FactPanelController::FactPanelController(QObject *parent) _missingParametersTimer.setInterval(500); _missingParametersTimer.setSingleShot(true); - connect(&_missingParametersTimer, &QTimer::timeout, this, &FactPanelController::_checkForMissingParameters); + (void) connect(&_missingParametersTimer, &QTimer::timeout, this, &FactPanelController::_checkForMissingParameters); +} + +FactPanelController::~FactPanelController() +{ + // qCDebug(FactPanelControllerLog) << Q_FUNC_INFO << this; } -void FactPanelController::_reportMissingParameter(int componentId, const QString& name) +void FactPanelController::_reportMissingParameter(int componentId, const QString &name) const { if (componentId == ParameterManager::defaultComponentId) { componentId = _vehicle->defaultComponentId(); } qgcApp()->reportMissingParameter(componentId, name); - qCWarning(FactPanelControllerLog) << "Missing parameter:" << QString("%1:%2").arg(componentId).arg(name); + qCWarning(FactPanelControllerLog) << "Missing parameter:" << QStringLiteral("%1:%2").arg(componentId).arg(name); } -bool FactPanelController::_allParametersExists(int componentId, QStringList names) +bool FactPanelController::_allParametersExists(int componentId, const QStringList &names) const { bool noMissingFacts = true; - foreach (const QString &name, names) { + for (const QString &name : names) { if (_vehicle && !_vehicle->parameterManager()->parameterExists(componentId, name)) { _reportMissingParameter(componentId, name); noMissingFacts = false; @@ -61,29 +65,29 @@ bool FactPanelController::_allParametersExists(int componentId, QStringList name return noMissingFacts; } - -Fact* FactPanelController::getParameterFact(int componentId, const QString& name, bool reportMissing) +Fact *FactPanelController::getParameterFact(int componentId, const QString &name, bool reportMissing) const { if (_vehicle && _vehicle->parameterManager()->parameterExists(componentId, name)) { - Fact* fact = _vehicle->parameterManager()->getParameter(componentId, name); + Fact *const fact = _vehicle->parameterManager()->getParameter(componentId, name); QQmlEngine::setObjectOwnership(fact, QQmlEngine::CppOwnership); return fact; - } else { - if (reportMissing) { - _reportMissingParameter(componentId, name); - } - return nullptr; } + + if (reportMissing) { + _reportMissingParameter(componentId, name); + } + + return nullptr; } -bool FactPanelController::parameterExists(int componentId, const QString& name) +bool FactPanelController::parameterExists(int componentId, const QString &name) const { - return _vehicle ? _vehicle->parameterManager()->parameterExists(componentId, name) : false; + return (_vehicle ? _vehicle->parameterManager()->parameterExists(componentId, name) : false); } -void FactPanelController::getMissingParameters(QStringList rgNames) +void FactPanelController::getMissingParameters(const QStringList &rgNames) { - for (const QString& name: rgNames) { + for (const QString &name: rgNames) { _missingParameterWaitList.append(name); _vehicle->parameterManager()->refreshParameter(MAV_COMP_ID_AUTOPILOT1, name); } @@ -91,12 +95,12 @@ void FactPanelController::getMissingParameters(QStringList rgNames) _missingParametersTimer.start(); } -void FactPanelController::_checkForMissingParameters(void) +void FactPanelController::_checkForMissingParameters() { - QStringList waitList = _missingParameterWaitList; - for (const QString& name: waitList) { + const QStringList waitList = _missingParameterWaitList; + for (const QString &name: waitList) { if (_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_AUTOPILOT1, name)) { - _missingParameterWaitList.removeOne(name); + (void) _missingParameterWaitList.removeOne(name); } } diff --git a/src/FactSystem/FactControls/FactPanelController.h b/src/FactSystem/FactControls/FactPanelController.h index b5d32dc654a..c3dd208a755 100644 --- a/src/FactSystem/FactControls/FactPanelController.h +++ b/src/FactSystem/FactControls/FactPanelController.h @@ -7,16 +7,12 @@ * ****************************************************************************/ - #pragma once -/// @file -/// @author Don Gagne - +#include #include #include #include -#include Q_DECLARE_LOGGING_CATEGORY(FactPanelControllerLog) @@ -24,42 +20,43 @@ class AutoPilotPlugin; class Vehicle; class Fact; -/// FactPanelController is used for handling missing Facts from C++ code. +/// Used for handling missing Facts from C++ code. class FactPanelController : public QObject { Q_OBJECT Q_MOC_INCLUDE("Vehicle.h") Q_MOC_INCLUDE("Fact.h") + Q_PROPERTY(Vehicle *vehicle MEMBER _vehicle CONSTANT) + public: FactPanelController(QObject *parent = nullptr); + ~FactPanelController(); - Q_PROPERTY(Vehicle* vehicle MEMBER _vehicle CONSTANT) - - Q_INVOKABLE Fact* getParameterFact (int componentId, const QString& name, bool reportMissing = true); - Q_INVOKABLE bool parameterExists (int componentId, const QString& name); + Q_INVOKABLE Fact *getParameterFact(int componentId, const QString &name, bool reportMissing = true) const; + Q_INVOKABLE bool parameterExists(int componentId, const QString &name) const; /// Queries the vehicle for parameters which were not available on initial download but should be available now. /// Signals missingParametersAvailable when done. Only works for MAV_COMP_ID_AUTOPILOT1 parameters. - Q_INVOKABLE void getMissingParameters(QStringList rgNames); + Q_INVOKABLE void getMissingParameters(const QStringList &rgNames); signals: - void missingParametersAvailable(void); + void missingParametersAvailable(); protected: /// Checks for existence of the specified parameters - /// @return true: all parameters exists, false: parameters missing and reported - bool _allParametersExists(int componentId, QStringList names); + /// @return true: all parameters exists, false: parameters missing and reported + bool _allParametersExists(int componentId, const QStringList &names) const; /// Report a missing parameter - void _reportMissingParameter(int componentId, const QString& name); + void _reportMissingParameter(int componentId, const QString &name) const; - Vehicle* _vehicle = nullptr; - AutoPilotPlugin* _autopilot = nullptr; + Vehicle *_vehicle = nullptr; + AutoPilotPlugin *_autopilot = nullptr; private slots: - void _checkForMissingParameters(void); + void _checkForMissingParameters(); private: QStringList _missingParameterWaitList; - QTimer _missingParametersTimer; + QTimer _missingParametersTimer; };