From a5747c5bdf06cf413c71eec8891e64eca2f37b2f Mon Sep 17 00:00:00 2001 From: Holden Date: Tue, 14 Jan 2025 21:10:05 -0500 Subject: [PATCH] QGC: Remove Unused Functions --- src/AnalyzeView/MAVLinkChartController.cc | 4 +- src/AnalyzeView/MAVLinkMessageField.cc | 6 +- .../PX4/AirframeComponentController.cc | 4 +- src/FirmwarePlugin/FirmwarePlugin.cc | 6 +- src/QGCApplication.cc | 205 +++++++++--------- src/QGCApplication.h | 143 ++++++------ src/Utilities/QGC.cc | 35 +-- src/Utilities/QGC.h | 38 +--- src/VehicleSetup/Bootloader.cc | 8 +- src/main.cc | 11 +- 10 files changed, 197 insertions(+), 263 deletions(-) diff --git a/src/AnalyzeView/MAVLinkChartController.cc b/src/AnalyzeView/MAVLinkChartController.cc index 5c75d0f08dd..f1db052921d 100644 --- a/src/AnalyzeView/MAVLinkChartController.cc +++ b/src/AnalyzeView/MAVLinkChartController.cc @@ -10,7 +10,7 @@ #include "MAVLinkChartController.h" #include "MAVLinkInspectorController.h" #include "MAVLinkMessageField.h" -#include "QGC.h" +#include "QGCApplication.h" #include "QGCLoggingCategory.h" #include @@ -82,7 +82,7 @@ void MAVLinkChartController::updateXRange() return; } - const qint64 bootTime = static_cast(QGC::bootTimeMilliseconds()); + const qint64 bootTime = static_cast(qgcApp()->msecsSinceBoot()); _rangeXMax = QDateTime::fromMSecsSinceEpoch(bootTime); emit rangeXMaxChanged(); diff --git a/src/AnalyzeView/MAVLinkMessageField.cc b/src/AnalyzeView/MAVLinkMessageField.cc index 32963df309a..bfe73677b8f 100644 --- a/src/AnalyzeView/MAVLinkMessageField.cc +++ b/src/AnalyzeView/MAVLinkMessageField.cc @@ -10,7 +10,7 @@ #include "MAVLinkMessageField.h" #include "MAVLinkChartController.h" #include "MAVLinkMessage.h" -#include "QGC.h" +#include "QGCApplication.h" #include "QGCLoggingCategory.h" #include @@ -98,13 +98,13 @@ void QGCMAVLinkMessageField::updateValue(const QString &newValue, qreal v) const int count = _values.count(); if (count < (50 * 60)) { ///< Arbitrary limit of 1 minute of data at 50Hz for now - const QPointF p(QGC::bootTimeMilliseconds(), v); + const QPointF p(qgcApp()->msecsSinceBoot(), v); _values.append(p); } else { if (_dataIndex >= count) { _dataIndex = 0; } - _values[_dataIndex].setX(QGC::bootTimeMilliseconds()); + _values[_dataIndex].setX(qgcApp()->msecsSinceBoot()); _values[_dataIndex].setY(v); _dataIndex++; } diff --git a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc index 6ed4039f5e2..8334818afd4 100644 --- a/src/AutoPilotPlugins/PX4/AirframeComponentController.cc +++ b/src/AutoPilotPlugins/PX4/AirframeComponentController.cc @@ -12,11 +12,11 @@ #include "MultiVehicleManager.h" #include "QGCApplication.h" #include "LinkManager.h" -#include "QGC.h" #include "Fact.h" #include "Vehicle.h" #include "ParameterManager.h" +#include #include #include #include @@ -123,7 +123,7 @@ void AirframeComponentController::_rebootAfterStackUnwind(void) _vehicle->sendMavCommand(_vehicle->defaultComponentId(), MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, true /* showError */, 1.0f); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (unsigned i = 0; i < 2000; i++) { - QGC::SLEEP::usleep(500); + QThread::usleep(500); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } QGuiApplication::restoreOverrideCursor(); diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 7ff67bad34c..ba826ff7f4a 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -18,10 +18,10 @@ #include "VehicleCameraControl.h" #include "VehicleComponent.h" #include "MAVLinkProtocol.h" -#include "QGC.h" #include "QGCLoggingCategory.h" #include +#include QGC_LOGGING_CATEGORY(FirmwarePluginLog, "FirmwarePluginLog") @@ -356,7 +356,7 @@ bool FirmwarePlugin::_armVehicleAndValidate(Vehicle* vehicle) vehicleArmed = true; break; } - QGC::SLEEP::msleep(100); + QThread::msleep(100); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } @@ -381,7 +381,7 @@ bool FirmwarePlugin::_setFlightModeAndValidate(Vehicle* vehicle, const QString& flightModeChanged = true; break; } - QGC::SLEEP::msleep(100); + QThread::msleep(100); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } if (flightModeChanged) { diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 3ae0bdfdf56..8bf24953ee5 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -88,7 +88,7 @@ QGC_LOGGING_CATEGORY(QGCApplicationLog, "qgc.qgcapplication") // Qml Singleton factories -static QObject* shapeFileHelperSingletonFactory(QQmlEngine*, QJSEngine*) +static QObject *shapeFileHelperSingletonFactory(QQmlEngine*, QJSEngine*) { return new ShapeFileHelper; } @@ -98,7 +98,7 @@ static QObject *mavlinkSingletonFactory(QQmlEngine*, QJSEngine*) return new QGCMAVLink(); } -QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) +QGCApplication::QGCApplication(int &argc, char *argv[], bool unitTesting) : QApplication(argc, argv) , _runningUnitTests(unitTesting) { @@ -122,12 +122,12 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) // Add additional command line option flags here }; - ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), false); + ParseCmdLineOptions(argc, argv, rgCmdLineOptions, std::size(rgCmdLineOptions), false); // Set up timer for delayed missing fact display _missingParamsDelayedDisplayTimer.setSingleShot(true); _missingParamsDelayedDisplayTimer.setInterval(_missingParamsDelayedDisplayTimerTimeout); - connect(&_missingParamsDelayedDisplayTimer, &QTimer::timeout, this, &QGCApplication::_missingParamsDisplay); + (void) connect(&_missingParamsDelayedDisplayTimer, &QTimer::timeout, this, &QGCApplication::_missingParamsDisplay); // Set application information QString applicationName; @@ -250,9 +250,11 @@ void QGCApplication::setLanguage() qCWarning(LocalizationLog) << "Error loading json localization for" << _locale.name(); } } - if(_qmlAppEngine) { + + if (_qmlAppEngine) { _qmlAppEngine->retranslate(); } + emit languageChanged(_locale); } @@ -265,8 +267,6 @@ void QGCApplication::init() { SettingsManager::instance()->init(); - // Register our Qml objects - LinkManager::registerQmlTypes(); ParameterManager::registerQmlTypes(); QGroundControlQmlGlobal::registerQmlTypes(); @@ -283,27 +283,27 @@ void QGCApplication::init() Viewer3DManager::registerQmlTypes(); #endif - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "GimbalController", "Reference only"); + qmlRegisterUncreatableType("QGroundControl.Vehicle", 1, 0, "GimbalController", "Reference only"); -#if !defined(QGC_DISABLE_MAVLINK_INSPECTOR) - qmlRegisterUncreatableType("QGroundControl", 1, 0, "MAVLinkChart", "Reference only"); - qmlRegisterType ("QGroundControl.Controllers", 1, 0, "MAVLinkInspectorController"); +#ifndef QGC_DISABLE_MAVLINK_INSPECTOR + qmlRegisterUncreatableType("QGroundControl", 1, 0, "MAVLinkChart", "Reference only"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "MAVLinkInspectorController"); #endif - qmlRegisterType ("QGroundControl.Controllers", 1, 0, "GeoTagController"); - qmlRegisterType ("QGroundControl.Controllers", 1, 0, "LogDownloadController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "GeoTagController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "LogDownloadController"); qmlRegisterType("QGroundControl.Controllers", 1, 0, "MAVLinkConsoleController"); qmlRegisterUncreatableType("QGroundControl.AutoPilotPlugin", 1, 0, "AutoPilotPlugin", "Reference only"); - qmlRegisterType("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController"); - qmlRegisterType("QGroundControl.Controllers", 1, 0, "SyslinkComponentController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "SyslinkComponentController"); qmlRegisterUncreatableType("QGroundControl.AutoPilotPlugin", 1, 0, "VehicleComponent", "Reference only"); #ifndef NO_SERIAL_LINK - qmlRegisterType("QGroundControl.Controllers", 1, 0, "FirmwareUpgradeController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "FirmwareUpgradeController"); #endif - qmlRegisterType("QGroundControl.Controllers", 1, 0, "JoystickConfigController"); + qmlRegisterType("QGroundControl.Controllers", 1, 0, "JoystickConfigController"); qmlRegisterSingletonType("QGroundControl.ShapeFileHelper", 1, 0, "ShapeFileHelper", shapeFileHelperSingletonFactory); @@ -313,10 +313,11 @@ void QGCApplication::init() // Although this should really be in _initForNormalAppBoot putting it here allowws us to create unit tests which pop up more easily if(QFontDatabase::addApplicationFont(":/fonts/opensans") < 0) { - qWarning() << "Could not load /fonts/opensans font"; + qCWarning(QGCApplicationLog) << "Could not load /fonts/opensans font"; } + if(QFontDatabase::addApplicationFont(":/fonts/opensans-demibold") < 0) { - qWarning() << "Could not load /fonts/opensans-demibold font"; + qCWarning(QGCApplicationLog) << "Could not load /fonts/opensans-demibold font"; } if (!_runningUnitTests) { @@ -349,7 +350,7 @@ void QGCApplication::_initForNormalAppBoot() VideoManager::instance()->init(); // Image provider for Optical Flow - _qmlAppEngine->addImageProvider(qgcImageProviderId, new QGCImageProvider()); + _qmlAppEngine->addImageProvider(_qgcImageProviderId, new QGCImageProvider()); // Safe to show popup error messages now that main window is created _showErrorsInToolbar = true; @@ -365,12 +366,12 @@ void QGCApplication::_initForNormalAppBoot() const QString line = permFile.readLine(); if (line.contains("dialout") && !line.contains(getenv("USER"))) { permFile.close(); - showAppMessage(QString( - tr("The current user does not have the correct permissions to access serial devices. " - "You should also remove modemmanager since it also interferes.

" - "If you are using Ubuntu, execute the following commands to fix these issues:
" - "
sudo usermod -a -G dialout $USER
" - "sudo apt-get remove modemmanager
"))); + showAppMessage(tr( + "The current user does not have the correct permissions to access serial devices. " + "You should also remove modemmanager since it also interferes.

" + "If you are using Ubuntu, execute the following commands to fix these issues:
" + "
sudo usermod -a -G dialout $USER
" + "sudo apt-get remove modemmanager
")); break; } } @@ -391,42 +392,27 @@ void QGCApplication::_initForNormalAppBoot() JoystickManager::instance()->init(); if (_settingsUpgraded) { - showAppMessage(QString(tr("The format for %1 saved settings has been modified. " - "Your saved settings have been reset to defaults.")).arg(applicationName())); + showAppMessage(tr("The format for %1 saved settings has been modified. " + "Your saved settings have been reset to defaults.").arg(applicationName())); } // Connect links with flag AutoconnectLink LinkManager::instance()->startAutoConnectedLinks(); } -void QGCApplication::deleteAllSettingsNextBoot(void) +void QGCApplication::deleteAllSettingsNextBoot() { QSettings settings; settings.setValue(_deleteAllSettingsKey, true); } -void QGCApplication::clearDeleteAllSettingsNextBoot(void) +void QGCApplication::clearDeleteAllSettingsNextBoot() { QSettings settings; settings.remove(_deleteAllSettingsKey); } -void QGCApplication::informationMessageBoxOnMainThread(const QString& /*title*/, const QString& msg) -{ - showAppMessage(msg); -} - -void QGCApplication::warningMessageBoxOnMainThread(const QString& /*title*/, const QString& msg) -{ - showAppMessage(msg); -} - -void QGCApplication::criticalMessageBoxOnMainThread(const QString& /*title*/, const QString& msg) -{ - showAppMessage(msg); -} - -void QGCApplication::reportMissingParameter(int componentId, const QString& name) +void QGCApplication::reportMissingParameter(int componentId, const QString &name) { const QPair missingParam(componentId, name); @@ -436,41 +422,44 @@ void QGCApplication::reportMissingParameter(int componentId, const QString& name _missingParamsDelayedDisplayTimer.start(); } -/// Called when the delay timer fires to show the missing parameters warning -void QGCApplication::_missingParamsDisplay(void) +void QGCApplication::_missingParamsDisplay() { - if (_missingParams.count()) { - QString params; - for (QPair& missingParam: _missingParams) { - const QString param = QStringLiteral("%1:%2").arg(missingParam.first).arg(missingParam.second); - if (params.isEmpty()) { - params += param; - } else { - params += QStringLiteral(", %1").arg(param); - } + if (_missingParams.isEmpty()) { + return; + } + QString params; + for (QPair& missingParam: _missingParams) { + const QString param = QStringLiteral("%1:%2").arg(missingParam.first).arg(missingParam.second); + if (params.isEmpty()) { + params += param; + } else { + params += QStringLiteral(", %1").arg(param); } - _missingParams.clear(); - showAppMessage(tr("Parameters are missing from firmware. You may be running a version of firmware which is not fully supported or your firmware has a bug in it. Missing params: %1").arg(params)); } + _missingParams.clear(); + + showAppMessage(tr("Parameters are missing from firmware. You may be running a version of firmware which is not fully supported or your firmware has a bug in it. Missing params: %1").arg(params)); } -QObject* QGCApplication::_rootQmlObject() +QObject *QGCApplication::_rootQmlObject() { if (_qmlAppEngine && _qmlAppEngine->rootObjects().size()) { return _qmlAppEngine->rootObjects()[0]; } + return nullptr; } -void QGCApplication::showCriticalVehicleMessage(const QString& message) +void QGCApplication::showCriticalVehicleMessage(const QString &message) { // PreArm messages are handled by Vehicle and shown in Map if (message.startsWith(QStringLiteral("PreArm")) || message.startsWith(QStringLiteral("preflight"), Qt::CaseInsensitive)) { return; } - QObject* rootQmlObject = _rootQmlObject(); + + QObject *const rootQmlObject = _rootQmlObject(); if (rootQmlObject && _showErrorsInToolbar) { QVariant varReturn; QVariant varMessage = QVariant::fromValue(message); @@ -483,15 +472,15 @@ void QGCApplication::showCriticalVehicleMessage(const QString& message) } } -void QGCApplication::showAppMessage(const QString& message, const QString& title) +void QGCApplication::showAppMessage(const QString &message, const QString &title) { - QString dialogTitle = title.isEmpty() ? applicationName() : title; + const QString dialogTitle = title.isEmpty() ? applicationName() : title; - QObject* rootQmlObject = _rootQmlObject(); + QObject *const rootQmlObject = _rootQmlObject(); if (rootQmlObject) { QVariant varReturn; QVariant varMessage = QVariant::fromValue(message); - QMetaObject::invokeMethod(_rootQmlObject(), "_showMessageDialog", Q_RETURN_ARG(QVariant, varReturn), Q_ARG(QVariant, dialogTitle), Q_ARG(QVariant, varMessage)); + QMetaObject::invokeMethod(rootQmlObject, "_showMessageDialog", Q_RETURN_ARG(QVariant, varReturn), Q_ARG(QVariant, dialogTitle), Q_ARG(QVariant, varMessage)); } else if (runningUnitTests()) { // Unit tests can run without UI qCDebug(QGCApplicationLog) << "QGCApplication::showAppMessage unittest title:message" << dialogTitle << message; @@ -502,7 +491,7 @@ void QGCApplication::showAppMessage(const QString& message, const QString& title } } -void QGCApplication::showRebootAppMessage(const QString& message, const QString& title) +void QGCApplication::showRebootAppMessage(const QString &message, const QString &title) { static QTime lastRebootMessage; @@ -510,7 +499,7 @@ void QGCApplication::showRebootAppMessage(const QString& message, const QString& const QTime previousTime = lastRebootMessage; lastRebootMessage = currentTime; - if (previousTime.isValid() && previousTime.msecsTo(currentTime) < 60 * 1000 * 2) { + if (previousTime.isValid() && (previousTime.msecsTo(currentTime) < (60 * 1000 * 2))) { // Debounce reboot messages return; } @@ -518,7 +507,7 @@ void QGCApplication::showRebootAppMessage(const QString& message, const QString& showAppMessage(message, title); } -void QGCApplication::_showDelayedAppMessages(void) +void QGCApplication::_showDelayedAppMessages() { if (_rootQmlObject()) { for (const QPair& appMsg: _delayedAppMessages) { @@ -530,17 +519,18 @@ void QGCApplication::_showDelayedAppMessages(void) } } -QQuickWindow* QGCApplication::mainRootWindow() +QQuickWindow *QGCApplication::mainRootWindow() { - if(!_mainRootWindow) { + if (!_mainRootWindow) { _mainRootWindow = qobject_cast(_rootQmlObject()); } + return _mainRootWindow; } void QGCApplication::showSetupView() { - if(_rootQmlObject()) { + if (_rootQmlObject()) { QVariant arg = ""; QMetaObject::invokeMethod(_rootQmlObject(), "showVehicleSetupTool", Q_ARG(QVariant, arg)); } @@ -548,27 +538,33 @@ void QGCApplication::showSetupView() void QGCApplication::qmlAttemptWindowClose() { - if(_rootQmlObject()) { + if (_rootQmlObject()) { QMetaObject::invokeMethod(_rootQmlObject(), "attemptWindowClose"); } } void QGCApplication::_checkForNewVersion() { - if (!_runningUnitTests) { - if (_parseVersionText(applicationVersion(), _majorVersion, _minorVersion, _buildVersion)) { - const QString versionCheckFile = QGCCorePlugin::instance()->stableVersionCheckFileUrl(); - if (!versionCheckFile.isEmpty()) { - QGCFileDownload* download = new QGCFileDownload(this); - connect(download, &QGCFileDownload::downloadComplete, this, &QGCApplication::_qgcCurrentStableVersionDownloadComplete); - download->download(versionCheckFile); - } - } + if (_runningUnitTests) { + return; + } + + if (!_parseVersionText(applicationVersion(), _majorVersion, _minorVersion, _buildVersion)) { + return; + } + + const QString versionCheckFile = QGCCorePlugin::instance()->stableVersionCheckFileUrl(); + if (!versionCheckFile.isEmpty()) { + QGCFileDownload *const download = new QGCFileDownload(this); + (void) connect(download, &QGCFileDownload::downloadComplete, this, &QGCApplication::_qgcCurrentStableVersionDownloadComplete); + download->download(versionCheckFile); } } -void QGCApplication::_qgcCurrentStableVersionDownloadComplete(QString /*remoteFile*/, QString localFile, QString errorMsg) +void QGCApplication::_qgcCurrentStableVersionDownloadComplete(const QString &remoteFile, const QString &localFile, const QString &errorMsg) { + Q_UNUSED(remoteFile); + if (errorMsg.isEmpty()) { QFile versionFile(localFile); if (versionFile.open(QIODevice::ReadOnly)) { @@ -580,8 +576,8 @@ void QGCApplication::_qgcCurrentStableVersionDownloadComplete(QString /*remoteFi int majorVersion, minorVersion, buildVersion; if (_parseVersionText(version, majorVersion, minorVersion, buildVersion)) { if (_majorVersion < majorVersion || - (_majorVersion == majorVersion && _minorVersion < minorVersion) || - (_majorVersion == majorVersion && _minorVersion == minorVersion && _buildVersion < buildVersion)) { + ((_majorVersion == majorVersion) && (_minorVersion < minorVersion)) || + ((_majorVersion == majorVersion) && (_minorVersion == minorVersion) && (_buildVersion < buildVersion))) { showAppMessage(tr("There is a newer version of %1 available. You can download it from %2.").arg(applicationName()).arg(QGCCorePlugin::instance()->stableDownloadLocation()), tr("New Version Available")); } } @@ -593,7 +589,7 @@ void QGCApplication::_qgcCurrentStableVersionDownloadComplete(QString /*remoteFi sender()->deleteLater(); } -bool QGCApplication::_parseVersionText(const QString& versionString, int& majorVersion, int& minorVersion, int& buildVersion) +bool QGCApplication::_parseVersionText(const QString &versionString, int &majorVersion, int &minorVersion, int &buildVersion) { static const QRegularExpression regExp("v(\\d+)\\.(\\d+)\\.(\\d+)"); const QRegularExpressionMatch match = regExp.match(versionString); @@ -607,53 +603,53 @@ bool QGCApplication::_parseVersionText(const QString& versionString, int& majorV return false; } -QString QGCApplication::cachedParameterMetaDataFile(void) +QString QGCApplication::cachedParameterMetaDataFile() { QSettings settings; const QDir parameterDir = QFileInfo(settings.fileName()).dir(); return parameterDir.filePath(QStringLiteral("ParameterFactMetaData.xml")); } -QString QGCApplication::cachedAirframeMetaDataFile(void) +QString QGCApplication::cachedAirframeMetaDataFile() { QSettings settings; const QDir airframeDir = QFileInfo(settings.fileName()).dir(); return airframeDir.filePath(QStringLiteral("PX4AirframeFactMetaData.xml")); } -/// Returns a signal index that is can be compared to QMetaCallEvent.signalId -int QGCApplication::CompressedSignalList::_signalIndex(const QMetaMethod & method) +int QGCApplication::CompressedSignalList::_signalIndex(const QMetaMethod &method) { if (method.methodType() != QMetaMethod::Signal) { - qCWarning(QGCApplicationLog) << "Internal error: QGCApplication::CompressedSignalList::_signalIndex not a signal" << method.methodType(); + qCWarning(QGCApplicationLog) << "Internal error:" << Q_FUNC_INFO << "not a signal" << method.methodType(); return -1; } int index = -1; - const QMetaObject* metaObject = method.enclosingMetaObject(); + const QMetaObject *metaObject = method.enclosingMetaObject(); for (int i=0; i<=method.methodIndex(); i++) { if (metaObject->method(i).methodType() != QMetaMethod::Signal) { continue; } index++; } + return index; } -void QGCApplication::CompressedSignalList::add(const QMetaMethod & method) +void QGCApplication::CompressedSignalList::add(const QMetaMethod &method) { - const QMetaObject* metaObject = method.enclosingMetaObject(); - int signalIndex = _signalIndex(method); + const QMetaObject *metaObject = method.enclosingMetaObject(); + const int signalIndex = _signalIndex(method); if (signalIndex != -1 && !contains(metaObject, signalIndex)) { _signalMap[method.enclosingMetaObject()].insert(signalIndex); } } -void QGCApplication::CompressedSignalList::remove(const QMetaMethod & method) +void QGCApplication::CompressedSignalList::remove(const QMetaMethod &method) { const int signalIndex = _signalIndex(method); - const QMetaObject* metaObject = method.enclosingMetaObject(); + const QMetaObject *const metaObject = method.enclosingMetaObject(); if (signalIndex != -1 && _signalMap.contains(metaObject) && _signalMap[metaObject].contains(signalIndex)) { _signalMap[metaObject].remove(signalIndex); @@ -663,28 +659,28 @@ void QGCApplication::CompressedSignalList::remove(const QMetaMethod & method) } } -bool QGCApplication::CompressedSignalList::contains(const QMetaObject* metaObject, int signalIndex) +bool QGCApplication::CompressedSignalList::contains(const QMetaObject *metaObject, int signalIndex) { return _signalMap.contains(metaObject) && _signalMap[metaObject].contains(signalIndex); } -void QGCApplication::addCompressedSignal(const QMetaMethod & method) +void QGCApplication::addCompressedSignal(const QMetaMethod &method) { _compressedSignals.add(method); } -void QGCApplication::removeCompressedSignal(const QMetaMethod & method) +void QGCApplication::removeCompressedSignal(const QMetaMethod &method) { _compressedSignals.remove(method); } -bool QGCApplication::compressEvent(QEvent*event, QObject* receiver, QPostEventList* postedEvents) +bool QGCApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) { if (event->type() != QEvent::MetaCall) { return QApplication::compressEvent(event, receiver, postedEvents); } - const QMetaCallEvent* mce = static_cast(event); + const QMetaCallEvent *mce = static_cast(event); if (!mce->sender() || !_compressedSignals.contains(mce->sender()->metaObject(), mce->signalId())) { return QApplication::compressEvent(event, receiver, postedEvents); } @@ -735,12 +731,13 @@ bool QGCApplication::event(QEvent *e) return true; } } + return QApplication::event(e); } -QGCImageProvider* QGCApplication::qgcImageProvider() +QGCImageProvider *QGCApplication::qgcImageProvider() { - return dynamic_cast(_qmlAppEngine->imageProvider(qgcImageProviderId)); + return dynamic_cast(_qmlAppEngine->imageProvider(_qgcImageProviderId)); } void QGCApplication::shutdown() diff --git a/src/QGCApplication.h b/src/QGCApplication.h index 5b37f403a06..aa5488d26e1 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -58,121 +58,116 @@ class QGCApplication; class QGCApplication : public QApplication { Q_OBJECT + + /// Unit Test have access to creating and destroying singletons + friend class UnitTest; public: - QGCApplication(int &argc, char* argv[], bool unitTesting); + QGCApplication(int &argc, char *argv[], bool unitTesting); ~QGCApplication(); /// @brief Sets the persistent flag to delete all settings the next time QGroundControl is started. - void deleteAllSettingsNextBoot(void); + void deleteAllSettingsNextBoot(); /// @brief Clears the persistent flag to delete all settings the next time QGroundControl is started. - void clearDeleteAllSettingsNextBoot(void); + void clearDeleteAllSettingsNextBoot(); /// @brief Returns true if unit tests are being run - bool runningUnitTests(void) const{ return _runningUnitTests; } + bool runningUnitTests() const { return _runningUnitTests; } /// @brief Returns true if Qt debug output should be logged to a file - bool logOutput(void) const{ return _logOutput; } + bool logOutput() const { return _logOutput; } /// Used to report a missing Parameter. Warning will be displayed to user. Method may be called /// multiple times. - void reportMissingParameter(int componentId, const QString& name); + void reportMissingParameter(int componentId, const QString &name); /// @return true: Fake ui into showing mobile interface - bool fakeMobile(void) const { return _fakeMobile; } + bool fakeMobile() const { return _fakeMobile; } - void setLanguage(); - QQuickWindow* mainRootWindow(); - uint64_t msecsSinceBoot(void) { return _msecsElapsedTime.elapsed(); } - QString numberToString(quint64 number); - QString bigSizeToString(quint64 size); - QString bigSizeMBToString(quint64 size_MB); + void setLanguage(); + QQuickWindow *mainRootWindow(); + uint64_t msecsSinceBoot() const { return _msecsElapsedTime.elapsed(); } + QString numberToString(quint64 number); + QString bigSizeToString(quint64 size); + QString bigSizeMBToString(quint64 size_MB); /// Registers the signal such that only the last duplicate signal added is left in the queue. - void addCompressedSignal(const QMetaMethod & method); + void addCompressedSignal(const QMetaMethod &method); - void removeCompressedSignal(const QMetaMethod & method); + void removeCompressedSignal(const QMetaMethod &method); - bool event(QEvent *e) override; + bool event(QEvent *e) final; - static QString cachedParameterMetaDataFile(void); - static QString cachedAirframeMetaDataFile(void); + static QString cachedParameterMetaDataFile(); + static QString cachedAirframeMetaDataFile(); -public slots: - /// You can connect to this slot to show an information message box from a different thread. - void informationMessageBoxOnMainThread(const QString& title, const QString& msg); +public: + /// @brief Perform initialize which is common to both normal application running and unit tests. + void init(); + void shutdown(); - /// You can connect to this slot to show a warning message box from a different thread. - void warningMessageBoxOnMainThread(const QString& title, const QString& msg); + // Although public, these methods are internal and should only be called by UnitTest code + QQmlApplicationEngine *qmlAppEngine() const { return _qmlAppEngine; } - /// You can connect to this slot to show a critical message box from a different thread. - void criticalMessageBoxOnMainThread(const QString& title, const QString& msg); +signals: + void languageChanged(const QLocale locale); +public slots: void showSetupView(); void qmlAttemptWindowClose(); /// Get current language - const QLocale getCurrentLanguage() { return _locale; } + QLocale getCurrentLanguage() const { return _locale; } /// Show non-modal vehicle message to the user - void showCriticalVehicleMessage(const QString& message); + void showCriticalVehicleMessage(const QString &message); /// Show modal application message to the user - void showAppMessage(const QString& message, const QString& title = QString()); + void showAppMessage(const QString &message, const QString &title = QString()); /// Show modal application message to the user about the need for a reboot. Multiple messages will be supressed if they occur /// one after the other. - void showRebootAppMessage(const QString& message, const QString& title = QString()); + void showRebootAppMessage(const QString &message, const QString &title = QString()); - QGCImageProvider* qgcImageProvider(); - -signals: - void languageChanged(const QLocale locale); - -public: - /// @brief Perform initialize which is common to both normal application running and unit tests. - void init(); - void shutdown(); - - // Although public, these methods are internal and should only be called by UnitTest code - QQmlApplicationEngine* qmlAppEngine() { return _qmlAppEngine; } + QGCImageProvider *qgcImageProvider(); private slots: - void _missingParamsDisplay (void); - void _qgcCurrentStableVersionDownloadComplete (QString remoteFile, QString localFile, QString errorMsg); - bool _parseVersionText (const QString& versionString, int& majorVersion, int& minorVersion, int& buildVersion); - void _showDelayedAppMessages (void); + /// Called when the delay timer fires to show the missing parameters warning + void _missingParamsDisplay(); + void _qgcCurrentStableVersionDownloadComplete(const QString &remoteFile, const QString &localFile, const QString &errorMsg); + static bool _parseVersionText(const QString &versionString, int &majorVersion, int &minorVersion, int &buildVersion); + void _showDelayedAppMessages(); private: /// @brief Initialize the application for normal application boot. Or in other words we are not going to run unit tests. void _initForNormalAppBoot(); - QObject* _rootQmlObject(); + QObject *_rootQmlObject(); void _checkForNewVersion(); // Overrides from QApplication - bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) override; - - bool _runningUnitTests; ///< true: running unit tests, false: normal app - static const int _missingParamsDelayedDisplayTimerTimeout = 1000; ///< Timeout to wait for next missing fact to come in before display - QTimer _missingParamsDelayedDisplayTimer; ///< Timer use to delay missing fact display - QList> _missingParams; ///< List of missing parameter component id:name - - QQmlApplicationEngine* _qmlAppEngine = nullptr; - bool _logOutput = false; ///< true: Log Qt debug output to file - bool _fakeMobile = false; ///< true: Fake ui into displaying mobile interface - bool _settingsUpgraded = false; ///< true: Settings format has been upgrade to new version - int _majorVersion = 0; - int _minorVersion = 0; - int _buildVersion = 0; - QQuickWindow* _mainRootWindow = nullptr; - QTranslator _qgcTranslatorSourceCode; ///< translations for source code C++/Qml - QTranslator _qgcTranslatorQtLibs; ///< tranlsations for Qt libraries - QLocale _locale; - bool _error = false; - bool _showErrorsInToolbar = false; - QElapsedTimer _msecsElapsedTime; + bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final; + + bool _runningUnitTests = false; ///< true: running unit tests, false: normal app + static constexpr int _missingParamsDelayedDisplayTimerTimeout = 1000; ///< Timeout to wait for next missing fact to come in before display + QTimer _missingParamsDelayedDisplayTimer; ///< Timer use to delay missing fact display + QList> _missingParams; ///< List of missing parameter component id:name + + QQmlApplicationEngine *_qmlAppEngine = nullptr; + bool _logOutput = false; ///< true: Log Qt debug output to file + bool _fakeMobile = false; ///< true: Fake ui into displaying mobile interface + bool _settingsUpgraded = false; ///< true: Settings format has been upgrade to new version + int _majorVersion = 0; + int _minorVersion = 0; + int _buildVersion = 0; + QQuickWindow *_mainRootWindow = nullptr; + QTranslator _qgcTranslatorSourceCode; ///< translations for source code C++/Qml + QTranslator _qgcTranslatorQtLibs; ///< tranlsations for Qt libraries + QLocale _locale; + bool _error = false; + bool _showErrorsInToolbar = false; + QElapsedTimer _msecsElapsedTime; QList> _delayedAppMessages; @@ -182,12 +177,13 @@ private slots: public: CompressedSignalList() {} - void add (const QMetaMethod & method); - void remove (const QMetaMethod & method); - bool contains (const QMetaObject * metaObject, int signalIndex); + void add(const QMetaMethod &method); + void remove(const QMetaMethod &method); + bool contains(const QMetaObject *metaObject, int signalIndex); private: - static int _signalIndex(const QMetaMethod & method); + /// Returns a signal index that is can be compared to QMetaCallEvent.signalId + static int _signalIndex(const QMetaMethod &method); QMap > _signalMap; }; @@ -197,8 +193,5 @@ private slots: const QString _settingsVersionKey = QStringLiteral("SettingsVersion"); ///< Settings key which hold settings version const QString _deleteAllSettingsKey = QStringLiteral("DeleteAllSettingsNextBoot"); ///< If this settings key is set on boot, all settings will be deleted - const QString qgcImageProviderId = QStringLiteral("QGCImages"); - - /// Unit Test have access to creating and destroying singletons - friend class UnitTest; + const QString _qgcImageProviderId = QStringLiteral("QGCImages"); }; diff --git a/src/Utilities/QGC.cc b/src/Utilities/QGC.cc index 70b07419705..69a562b8043 100644 --- a/src/Utilities/QGC.cc +++ b/src/Utilities/QGC.cc @@ -15,39 +15,11 @@ #include -namespace QGC -{ - -static quint64 gBootTime = 0; - -void initTimer() -{ - gBootTime = groundTimeMilliseconds(); -} - -quint64 bootTimeMilliseconds() -{ - return groundTimeMilliseconds() - gBootTime; -} - -quint64 groundTimeUsecs() -{ - return groundTimeMilliseconds() * 1000; -} - -quint64 groundTimeMilliseconds() -{ - return static_cast(QDateTime::currentMSecsSinceEpoch()); -} - -qreal groundTimeSeconds() -{ - return static_cast(groundTimeMilliseconds()) / 1000.0f; -} +namespace QGC { float limitAngleToPMPIf(double angle) { - if (angle > -20*M_PI && angle < 20*M_PI) + if ((angle > (-20*M_PI)) && (angle < (20*M_PI))) { while (angle > ((float)M_PI+FLT_EPSILON)) { @@ -70,7 +42,7 @@ float limitAngleToPMPIf(double angle) double limitAngleToPMPId(double angle) { - if (angle > -20*M_PI && angle < 20*M_PI) + if ((angle > (-20*M_PI)) && (angle < (20*M_PI))) { if (angle < -M_PI) { @@ -137,6 +109,7 @@ quint32 crc32(const quint8 *src, unsigned len, unsigned state) for (unsigned i = 0; i < len; i++) { state = crctab[(state ^ src[i]) & 0xff] ^ (state >> 8); } + return state; } diff --git a/src/Utilities/QGC.h b/src/Utilities/QGC.h index 01aefd59433..0511687625a 100644 --- a/src/Utilities/QGC.h +++ b/src/Utilities/QGC.h @@ -9,45 +9,17 @@ #pragma once -#include - -namespace QGC -{ - -/** - * @brief Get the current ground time in microseconds. - * @note This does not have microsecond precision, it is limited to millisecond precision. - */ -quint64 groundTimeUsecs(); -/** @brief Get the current ground time in milliseconds */ -quint64 groundTimeMilliseconds(); -/** - * @brief Get the current ground time in fractional seconds - * @note Precision is limited to milliseconds. - */ -qreal groundTimeSeconds(); -/** @brief Returns the angle limited to -pi - pi */ +#include + +namespace QGC { + float limitAngleToPMPIf(double angle); -/** @brief Returns the angle limited to -pi - pi */ -double limitAngleToPMPId(double angle); -/** @brief Records boot time (called from main) */ -void initTimer(); -/** @brief Get the ground time since boot in milliseconds */ -quint64 bootTimeMilliseconds(); +double limitAngleToPMPId(double angle); /// Returns true if the two values are equal or close. Correctly handles 0 and NaN values. bool fuzzyCompare(double value1, double value2); -class SLEEP : public QThread -{ - Q_OBJECT -public: - using QThread::sleep; - using QThread::msleep; - using QThread::usleep; -}; - quint32 crc32(const quint8 *src, unsigned len, unsigned state); } diff --git a/src/VehicleSetup/Bootloader.cc b/src/VehicleSetup/Bootloader.cc index 90e0d5afb1b..d63541a50bc 100644 --- a/src/VehicleSetup/Bootloader.cc +++ b/src/VehicleSetup/Bootloader.cc @@ -11,8 +11,10 @@ #include "QGCLoggingCategory.h" #include "FirmwareImage.h" #include "QGC.h" -#include + #include +#include +#include /// This class manages interactions with the bootloader Bootloader::Bootloader(bool sikRadio, QObject *parent) @@ -40,7 +42,7 @@ bool Bootloader::open(const QString portName) if (_sikRadio) { // Radios are slow to start up - QGC::SLEEP::msleep(1000); + QThread::msleep(1000); } return true; } @@ -204,7 +206,7 @@ bool Bootloader::reboot(void) } _port.flush(); if (success) { - QGC::SLEEP::msleep(1000); + QThread::msleep(1000); } return success; } diff --git a/src/main.cc b/src/main.cc index 548358b622e..e4acd9710c6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -114,9 +114,6 @@ int main(int argc, char *argv[]) #endif #endif - //-- Record boot time - QGC::initTimer(); - #ifdef Q_OS_UNIX //Force writing to the console on UNIX/BSD devices if (!qEnvironmentVariableIsSet("QT_LOGGING_TO_CONSOLE")) { @@ -197,10 +194,10 @@ int main(int argc, char *argv[]) QGCApplication app(argc, argv, runUnitTests); - #ifdef Q_OS_LINUX - std::signal(SIGINT, sigHandler); - std::signal(SIGTERM, sigHandler); - #endif +#ifdef Q_OS_LINUX + std::signal(SIGINT, sigHandler); + std::signal(SIGTERM, sigHandler); +#endif app.init();