Skip to content

Commit

Permalink
Add New CommandLineParser Utility
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Oct 19, 2024
1 parent 6407b70 commit 4d12128
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 152 deletions.
4 changes: 1 addition & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ find_package(Qt6
)

qt_add_library(QGC STATIC
CmdLineOptParser.cc
CmdLineOptParser.h
QGCApplication.cc
QGCApplication.h
QGCConfig.h
Expand Down Expand Up @@ -94,7 +92,6 @@ target_link_libraries(QGC
Settings
Terrain
# UI
Utilities
UTMSP
Vehicle
VehicleSetup
Expand All @@ -105,6 +102,7 @@ target_link_libraries(QGC
Qt6::Core
Qt6::CorePrivate
Qt6::Widgets
Utilities
)

if(QGC_CUSTOM_BUILD)
Expand Down
56 changes: 0 additions & 56 deletions src/CmdLineOptParser.cc

This file was deleted.

31 changes: 0 additions & 31 deletions src/CmdLineOptParser.h

This file was deleted.

38 changes: 8 additions & 30 deletions src/QGCApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "Audio/AudioOutput.h"
#include "QGCConfig.h"
#include "QGCApplication.h"
#include "CmdLineOptParser.h"
#include "UDPLink.h"
#include "LinkManager.h"
#include "MAVLinkProtocol.h"
Expand Down Expand Up @@ -138,37 +137,23 @@ static QObject* shapeFileHelperSingletonFactory(QQmlEngine*, QJSEngine*)
return new ShapeFileHelper;
}

QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
QGCApplication::QGCApplication(int &argc, char* argv[])
: QApplication(argc, argv)
, _runningUnitTests(unitTesting)
{
_msecsElapsedTime.start();

QGCCommandLineParser::parseCommandLine(_cmdLineOptions);

// Setup for network proxy support
QNetworkProxyFactory::setUseSystemConfiguration(true);

// Parse command line options
bool fClearSettingsOptions = false; // Clear stored settings
bool fClearCache = false; // Clear parameter/airframe caches
bool logging = false; // Turn on logging
QString loggingOptions;

CmdLineOpt_t rgCmdLineOptions[] = {
{ "--clear-settings", &fClearSettingsOptions, nullptr },
{ "--clear-cache", &fClearCache, nullptr },
{ "--logging", &logging, &loggingOptions },
{ "--fake-mobile", &_fakeMobile, nullptr },
{ "--log-output", &_logOutput, nullptr },
// Add additional command line option flags here
};

ParseCmdLineOptions(argc, argv, rgCmdLineOptions, sizeof(rgCmdLineOptions)/sizeof(rgCmdLineOptions[0]), false);

// Set up timer for delayed missing fact display
_missingParamsDelayedDisplayTimer.setSingleShot(true);
_missingParamsDelayedDisplayTimer.setInterval(_missingParamsDelayedDisplayTimerTimeout);
connect(&_missingParamsDelayedDisplayTimer, &QTimer::timeout, this, &QGCApplication::_missingParamsDisplay);

_runningUnitTests = _cmdLineOptions.runningUnitTests;

// Set application information
QString applicationName;
if (_runningUnitTests) {
Expand Down Expand Up @@ -202,14 +187,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
}

// The setting will delete all settings on this boot
fClearSettingsOptions |= settings.contains(_deleteAllSettingsKey);

if (_runningUnitTests) {
// Unit tests run with clean settings
fClearSettingsOptions = true;
}

if (fClearSettingsOptions) {
if (_cmdLineOptions.clearSettingsOptions || settings.contains(_deleteAllSettingsKey)) {
// User requested settings to be cleared on command line
settings.clear();

Expand All @@ -229,7 +207,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
}
settings.setValue(_settingsVersionKey, QGC_SETTINGS_VERSION);

if (fClearCache) {
if (_cmdLineOptions.clearCache) {
QDir dir(ParameterManager::parameterCacheDir());
dir.removeRecursively();
QFile airframe(cachedAirframeMetaDataFile());
Expand All @@ -239,7 +217,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
}

// Set up our logging filters
QGCLoggingCategoryRegister::instance()->setFilterRulesFromSettings(loggingOptions);
QGCLoggingCategoryRegister::instance()->setFilterRulesFromSettings(_cmdLineOptions.loggingOptions);

// We need to set language as early as possible prior to loading on JSON files.
setLanguage();
Expand Down
8 changes: 7 additions & 1 deletion src/QGCApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <QtCore/private/qthread_p.h>
#include <QtCore/private/qobject_p.h>

#include <QGCCommandLineParser.h>

// Work around circular header includes
class QQmlApplicationEngine;
class QGCToolbox;
Expand Down Expand Up @@ -60,7 +62,7 @@ class QGCApplication : public QApplication
{
Q_OBJECT
public:
QGCApplication(int &argc, char* argv[], bool unitTesting);
QGCApplication(int &argc, char* argv[]);
~QGCApplication();

/// @brief Sets the persistent flag to delete all settings the next time QGroundControl is started.
Expand Down Expand Up @@ -152,6 +154,8 @@ public slots:
// Although public, these methods are internal and should only be called by UnitTest code
QQmlApplicationEngine* qmlAppEngine() { return _qmlAppEngine; }

const QGCCommandLineParser::CommandLineParseResult* cmdLineOptions() { return &_cmdLineOptions; }

private slots:
void _missingParamsDisplay (void);
void _qgcCurrentStableVersionDownloadComplete (QString remoteFile, QString localFile, QString errorMsg);
Expand Down Expand Up @@ -192,6 +196,8 @@ private slots:

QList<QPair<QString /* title */, QString /* message */>> _delayedAppMessages;

QGCCommandLineParser::CommandLineParseResult _cmdLineOptions;

class CompressedSignalList {
Q_DISABLE_COPY(CompressedSignalList)

Expand Down
3 changes: 3 additions & 0 deletions src/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_subdirectory(Compression)
find_package(Qt6 REQUIRED COMPONENTS Bluetooth Core Gui Network Positioning Sensors Qml Xml)

qt_add_library(Utilities STATIC
DeviceInfo.cc
DeviceInfo.cc
DeviceInfo.h
JsonHelper.cc
Expand All @@ -15,6 +16,8 @@ qt_add_library(Utilities STATIC
QGC.h
QGCCachedFileDownload.cc
QGCCachedFileDownload.h
QGCCommandLineParser.cc
QGCCommandLineParser.h
QGCFileDownload.cc
QGCFileDownload.h
QGCLoggingCategory.cc
Expand Down
Loading

0 comments on commit 4d12128

Please sign in to comment.