QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCApplication.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QElapsedTimer>
4#include <QtCore/QLoggingCategory>
5#include <QtCore/QMap>
6#include <QtCore/QSet>
7#include <QtCore/QTime>
8#include <QtCore/QTimer>
9#include <QtCore/QTranslator>
10#include <QtGui/QGuiApplication>
11
15
16class QQmlApplicationEngine;
17class QQuickWindow;
19class QGCApplication;
20class QEvent;
21class QPostEventList;
22class QMetaMethod;
23struct QMetaObject;
24
25#if defined(qApp)
26#undef qApp
27#endif
28#define qApp (static_cast<QGCApplication*>(QGuiApplication::instance()))
29
30#if defined(qGuiApp)
31#undef qGuiApp
32#endif
33#define qGuiApp (static_cast<QGCApplication*>(QGuiApplication::instance()))
34
35#define qgcApp() qApp
36
39class QGCApplication : public QGuiApplication
40{
41 Q_OBJECT
42
44 friend class UnitTest;
45public:
46 QGCApplication(int &argc, char *argv[], const QGCCommandLineParser::CommandLineParseResult &args);
48
49 bool runningUnitTests() const { return _runningUnitTests; }
50 bool simpleBootTest() const { return _simpleBootTest; }
51 bool bootTestPassed() const { return _bootTestPassed; }
52
54 bool logOutput() const { return _logOutput; }
55
58 void reportMissingParameter(int componentId, const QString &name);
59
61 bool fakeMobile() const { return _fakeMobile; }
62
63 void setLanguage();
64 QQuickWindow *mainRootWindow();
65 uint64_t msecsSinceBoot() const { return _msecsElapsedTime.elapsed(); }
66
68 void addCompressedSignal(const QMetaMethod &method);
69
70 void removeCompressedSignal(const QMetaMethod &method);
71
72 bool event(QEvent *e) final;
73
74 static QString cachedParameterMetaDataFile();
75 static QString cachedAirframeMetaDataFile();
76
77public:
79 void init();
80 void shutdown();
81
83 QQmlApplicationEngine *qmlAppEngine() const { return _qmlAppEngine; }
86 void setQmlAppEngine(QQmlApplicationEngine *engine)
87 {
88 _qmlAppEngine = engine;
89 _mainRootWindow = nullptr; // cached from the previous engine's root object
90 _uiTestMode = (engine != nullptr);
91 }
94 void resetRebootMessageDebounce() { _lastRebootMessageTime = QTime(); }
95
96signals:
97 void languageChanged(const QLocale &locale);
98
99public slots:
101
103 QLocale getCurrentLanguage() const { return _locale; }
104
106 void showCriticalVehicleMessage(const QString &message);
107
109 void showAppMessage(const QString &message, const QString &title = QString());
110
113 void showRebootAppMessage(const QString &message, const QString &title = QString());
114
116 void showRebootVehicleMessage(const QString &message, const QString &title = QString());
117
119
120private slots:
122 void _missingParamsDisplay();
123 void _qgcCurrentStableVersionDownloadComplete(bool success, const QString &localFile, const QString &errorMsg);
124 static bool _parseVersionText(const QString &versionString, int &majorVersion, int &minorVersion, int &buildVersion);
125 void _showDelayedAppMessages();
126
127private:
128 bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final;
129
130 bool _initVideo();
131
132 bool _initQmlRootWindow();
133
135 void _initForNormalAppBoot();
136
137 QObject *_rootQmlObject();
138 void _checkForNewVersion();
139 bool _rebootMessageDebounced();
140
141 bool _runningUnitTests = false;
142 bool _simpleBootTest = false;
143 bool _uiTestMode = false;
144 bool _fakeMobile = false;
145 bool _logOutput = false;
146 quint8 _systemId = 0;
147 QTime _lastRebootMessageTime;
148
149 static constexpr int _missingParamsDelayedDisplayTimerTimeout = 1000;
150 QTimer _missingParamsDelayedDisplayTimer;
151 QList<QPair<int,QString>> _missingParams;
152
153 QQmlApplicationEngine *_qmlAppEngine = nullptr;
154 bool _settingsUpgraded = false;
155 int _majorVersion = 0;
156 int _minorVersion = 0;
157 int _buildVersion = 0;
158 QQuickWindow *_mainRootWindow = nullptr;
159 QTranslator _qgcTranslatorSourceCode;
160 QTranslator _qgcTranslatorQtLibs;
161 QLocale _locale;
162 bool _error = false;
163 bool _showErrorsInToolbar = false;
164 QElapsedTimer _msecsElapsedTime;
165 bool _videoManagerInitialized = false;
166 bool _bootTestPassed = true;
167
168 QList<QPair<QString /* title */, QString /* message */>> _delayedAppMessages;
169
170 class CompressedSignalList
171 {
172 public:
173 CompressedSignalList() {}
174 void add(const QMetaMethod &method);
175 void remove(const QMetaMethod &method);
176 bool contains(const QMetaObject *metaObject, int signalIndex);
177
178 private:
180 static int _signalIndex(const QMetaMethod &method);
181
182 QMap<const QMetaObject*, QSet<int>> _signalMap;
183
184 Q_DISABLE_COPY(CompressedSignalList)
185 };
186
187 CompressedSignalList _compressedSignals;
188
189 const QString _settingsVersionKey = QStringLiteral("SettingsVersion");
190
191 const QString _qgcImageProviderId = QStringLiteral("QGCImages");
192};
193
194Q_DECLARE_LOGGING_CATEGORY(QGCAppMessageLog)
The main application and management class.
void qmlAttemptWindowClose()
void reportMissingParameter(int componentId, const QString &name)
void showRebootAppMessage(const QString &message, const QString &title=QString())
bool logOutput() const
Returns true if Qt debug output should be logged to a file.
void init()
Perform initialize which is common to both normal application running and unit tests.
bool fakeMobile() const
static QString cachedParameterMetaDataFile()
QQuickWindow * mainRootWindow()
void removeCompressedSignal(const QMetaMethod &method)
void languageChanged(const QLocale &locale)
static QString cachedAirframeMetaDataFile()
void addCompressedSignal(const QMetaMethod &method)
Registers the signal such that only the last duplicate signal added is left in the queue.
QQmlApplicationEngine * qmlAppEngine() const
Although public, these methods are internal and should only be called by UnitTest code.
friend class UnitTest
Unit Test have access to creating and destroying singletons.
void showCriticalVehicleMessage(const QString &message)
Show non-modal vehicle message to the user.
bool runningUnitTests() const
QGCImageProvider * qgcImageProvider()
void setQmlAppEngine(QQmlApplicationEngine *engine)
uint64_t msecsSinceBoot() const
bool simpleBootTest() const
void resetRebootMessageDebounce()
void showAppMessage(const QString &message, const QString &title=QString())
Show modal application message to the user.
void showRebootVehicleMessage(const QString &message, const QString &title=QString())
Same as showRebootAppMessage() but the dialog also includes a button which reboots the active vehicle...
bool bootTestPassed() const
QLocale getCurrentLanguage() const
Get current language.
bool event(QEvent *e) final
This is used to expose images from ImageProtocolHandler.
Result of parsing command-line arguments.