Skip to content

Commit 19fc139

Browse files
committed
Utilities: Implement QCommandLineParser
1 parent 41991b8 commit 19fc139

14 files changed

+453
-225
lines changed

src/Android/AndroidInterface.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ bool checkStoragePermissions()
118118
futurePermissionResult = QtAndroidPrivate::requestPermission(permission);
119119
permissionResult = futurePermissionResult.result();
120120
if (permissionResult == QtAndroidPrivate::PermissionResult::Denied) {
121+
qCWarning(AndroidInterfaceLog) << "Denied:" << permission;
121122
return false;
122123
}
123124
}
124125
}
125126

127+
qCDebug(AndroidInterfaceLog) << "checkStoragePermissions Accepted";
126128
return true;
127129
}
128130

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ add_subdirectory(QtLocationPlugin)
4646
target_sources(${CMAKE_PROJECT_NAME}
4747
PRIVATE
4848
main.cc
49-
CmdLineOptParser.cc
50-
CmdLineOptParser.h
5149
pch.h
5250
QGCApplication.cc
5351
QGCApplication.h

src/CmdLineOptParser.cc

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/CmdLineOptParser.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/QGCApplication.cc

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include "QGCLogging.h"
2929
#include "AudioOutput.h"
30-
#include "CmdLineOptParser.h"
3130
#include "FollowMe.h"
3231
#include "JoystickManager.h"
3332
#include "JsonHelper.h"
@@ -36,11 +35,13 @@
3635
#include "MultiVehicleManager.h"
3736
#include "ParameterManager.h"
3837
#include "PositionManager.h"
38+
#include "QGCCommandLineParser.h"
3939
#include "QGCCorePlugin.h"
4040
#include "QGCFileDownload.h"
4141
#include "QGCImageProvider.h"
4242
#include "QGCLoggingCategory.h"
4343
#include "SettingsManager.h"
44+
#include "MavlinkSettings.h"
4445
#include "AppSettings.h"
4546
#include "UDPLink.h"
4647
#include "Vehicle.h"
@@ -53,32 +54,22 @@
5354

5455
QGC_LOGGING_CATEGORY(QGCApplicationLog, "qgc.qgcapplication")
5556

56-
QGCApplication::QGCApplication(int &argc, char *argv[], bool unitTesting, bool simpleBootTest)
57+
QGCApplication::QGCApplication(int &argc, char *argv[], const QGCCommandLineParser::CommandLineParseResult &cli)
5758
: QApplication(argc, argv)
58-
, _runningUnitTests(unitTesting)
59-
, _simpleBootTest(simpleBootTest)
59+
, _runningUnitTests(cli.runningUnitTests)
60+
, _simpleBootTest(cli.simpleBootTest)
61+
, _fakeMobile(cli.fakeMobile)
62+
, _logOutput(cli.logOutput)
63+
, _systemId(cli.systemId.value_or(0))
6064
{
6165
_msecsElapsedTime.start();
6266

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

66-
// Parse command line options
67-
bool fClearSettingsOptions = false; // Clear stored settings
68-
bool fClearCache = false; // Clear parameter/airframe caches
69-
bool logging = false; // Turn on logging
70-
QString loggingOptions;
71-
72-
CmdLineOpt_t rgCmdLineOptions[] = {
73-
{ "--clear-settings", &fClearSettingsOptions, nullptr },
74-
{ "--clear-cache", &fClearCache, nullptr },
75-
{ "--logging", &logging, &loggingOptions },
76-
{ "--fake-mobile", &_fakeMobile, nullptr },
77-
{ "--log-output", &_logOutput, nullptr },
78-
// Add additional command line option flags here
79-
};
80-
81-
ParseCmdLineOptions(argc, argv, rgCmdLineOptions, std::size(rgCmdLineOptions), false);
70+
bool fClearSettingsOptions = cli.clearSettingsOptions; // Clear stored settings
71+
const bool fClearCache = cli.clearCache; // Clear parameter/airframe caches
72+
const QString loggingOptions = cli.loggingOptions.value_or(QString(""));
8273

8374
// Set up timer for delayed missing fact display
8475
_missingParamsDelayedDisplayTimer.setSingleShot(true);
@@ -87,7 +78,7 @@ QGCApplication::QGCApplication(int &argc, char *argv[], bool unitTesting, bool s
8778

8879
// Set application information
8980
QString applicationName;
90-
if (_runningUnitTests || simpleBootTest) {
81+
if (_runningUnitTests || _simpleBootTest) {
9182
// We don't want unit tests to use the same QSettings space as the normal app. So we tweak the app
9283
// name. Also we want to run unit tests with clean settings every time.
9384
applicationName = QStringLiteral("%1_unittest").arg(QGC_APP_NAME);
@@ -117,7 +108,7 @@ QGCApplication::QGCApplication(int &argc, char *argv[], bool unitTesting, bool s
117108
// The setting will delete all settings on this boot
118109
fClearSettingsOptions |= settings.contains(_deleteAllSettingsKey);
119110

120-
if (_runningUnitTests || simpleBootTest) {
111+
if (_runningUnitTests || _simpleBootTest) {
121112
// Unit tests run with clean settings
122113
fClearSettingsOptions = true;
123114
}
@@ -219,13 +210,17 @@ QGCApplication::~QGCApplication()
219210
void QGCApplication::init()
220211
{
221212
SettingsManager::instance()->init();
213+
if (_systemId > 0) {
214+
qCDebug(QGCApplicationLog) << "Setting MAVLink System ID to:" << _systemId;
215+
SettingsManager::instance()->mavlinkSettings()->gcsMavlinkSystemID()->setRawValue(_systemId);
216+
}
222217

223218
// Although this should really be in _initForNormalAppBoot putting it here allowws us to create unit tests which pop up more easily
224-
if(QFontDatabase::addApplicationFont(":/fonts/opensans") < 0) {
219+
if (QFontDatabase::addApplicationFont(":/fonts/opensans") < 0) {
225220
qCWarning(QGCApplicationLog) << "Could not load /fonts/opensans font";
226221
}
227222

228-
if(QFontDatabase::addApplicationFont(":/fonts/opensans-demibold") < 0) {
223+
if (QFontDatabase::addApplicationFont(":/fonts/opensans-demibold") < 0) {
229224
qCWarning(QGCApplicationLog) << "Could not load /fonts/opensans-demibold font";
230225
}
231226

src/QGCApplication.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include <QtCore/QTranslator>
1818
#include <QtWidgets/QApplication>
1919

20+
namespace QGCCommandLineParser {
21+
struct CommandLineParseResult;
22+
}
23+
2024
class QQmlApplicationEngine;
2125
class QQuickWindow;
2226
class QGCImageProvider;
@@ -50,7 +54,7 @@ class QGCApplication : public QApplication
5054
/// Unit Test have access to creating and destroying singletons
5155
friend class UnitTest;
5256
public:
53-
QGCApplication(int &argc, char *argv[], bool unitTesting, bool simpleBootTest);
57+
QGCApplication(int &argc, char *argv[], const QGCCommandLineParser::CommandLineParseResult &args);
5458
~QGCApplication();
5559

5660
/// Sets the persistent flag to delete all settings the next time QGroundControl is started.
@@ -140,14 +144,15 @@ private slots:
140144

141145
bool _runningUnitTests = false;
142146
bool _simpleBootTest = false;
147+
bool _fakeMobile = false; ///< true: Fake ui into displaying mobile interface
148+
bool _logOutput = false; ///< true: Log Qt debug output to file
149+
quint8 _systemId = 0; ///< MAVLink system ID, 0 means not set
143150

144151
static constexpr int _missingParamsDelayedDisplayTimerTimeout = 1000; ///< Timeout to wait for next missing fact to come in before display
145152
QTimer _missingParamsDelayedDisplayTimer; ///< Timer use to delay missing fact display
146153
QList<QPair<int,QString>> _missingParams; ///< List of missing parameter component id:name
147154

148155
QQmlApplicationEngine *_qmlAppEngine = nullptr;
149-
bool _logOutput = false; ///< true: Log Qt debug output to file
150-
bool _fakeMobile = false; ///< true: Fake ui into displaying mobile interface
151156
bool _settingsUpgraded = false; ///< true: Settings format has been upgrade to new version
152157
int _majorVersion = 0;
153158
int _minorVersion = 0;

src/Utilities/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ target_sources(${CMAKE_PROJECT_NAME}
1414
Platform.h
1515
QGC.cc
1616
QGC.h
17+
QGCCommandLineParser.cc
18+
QGCCommandLineParser.h
1719
QGCLogging.cc
1820
QGCLogging.h
1921
QGCLoggingCategory.cc

src/Utilities/Platform.cc

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
#include <QtCore/QCoreApplication>
1313
#include <QtCore/QProcessEnvironment>
1414

15+
#include "QGCCommandLineParser.h"
16+
17+
#ifdef Q_OS_ANDROID
18+
#include "AndroidInterface.h"
19+
#endif
20+
1521
#if !defined(Q_OS_IOS) && !defined(Q_OS_ANDROID)
16-
#include "SignalHandler.h"
22+
#include "SignalHandler.h"
1723
#endif
1824

1925
#if defined(Q_OS_MACOS)
@@ -126,7 +132,7 @@ void setWindowsErrorModes(bool quietWindowsAsserts)
126132

127133
} // namespace
128134

129-
void Platform::setupPreApp(bool quietWindowsAsserts)
135+
void Platform::setupPreApp(const QGCCommandLineParser::CommandLineParseResult &cli)
130136
{
131137
#ifdef Q_OS_UNIX
132138
if (!qEnvironmentVariableIsSet("QT_ASSUME_STDERR_HAS_CONSOLE")) {
@@ -138,15 +144,27 @@ void Platform::setupPreApp(bool quietWindowsAsserts)
138144
#endif
139145

140146
#ifdef Q_OS_WIN
147+
// (void) qputenv("QT_OPENGL_BUGLIST", ":/opengl/resources/opengl/buglist.json");
141148
if (!qEnvironmentVariableIsSet("QT_WIN_DEBUG_CONSOLE")) {
142149
(void) qputenv("QT_WIN_DEBUG_CONSOLE", "attach");
143150
}
144-
setWindowsErrorModes(quietWindowsAsserts);
151+
setWindowsErrorModes(cli.quietWindowsAsserts);
145152
#endif
146153

147154
#ifdef Q_OS_MACOS
148155
disableAppNapViaInfoDict();
149156
#endif
157+
158+
if (cli.useDesktopGL) {
159+
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
160+
}
161+
162+
if (cli.useSwRast) {
163+
QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
164+
}
165+
166+
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
167+
QCoreApplication::setAttribute(Qt::AA_CompressTabletEvents);
150168
}
151169

152170
void Platform::setupPostApp()
@@ -155,4 +173,8 @@ void Platform::setupPostApp()
155173
SignalHandler* signalHandler = new SignalHandler(QCoreApplication::instance());
156174
(void) signalHandler->setupSignalHandlers();
157175
#endif
176+
177+
#ifdef Q_OS_ANDROID
178+
AndroidInterface::checkStoragePermissions();
179+
#endif
158180
}

src/Utilities/Platform.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
#pragma once
1111

12+
namespace QGCCommandLineParser {
13+
struct CommandLineParseResult;
14+
}
15+
1216
namespace Platform {
1317

1418
// Call before constructing Q(Core)Application.
15-
void setupPreApp(bool quietWindowsAsserts);
19+
void setupPreApp(const QGCCommandLineParser::CommandLineParseResult &cli);
1620

1721
// Call after Q(Core)Application exists and logging is installed.
1822
void setupPostApp();

0 commit comments

Comments
 (0)