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/QTimer>
8#include <QtCore/QTranslator>
9#include <QtGui/QGuiApplication>
10
14
15class QQmlApplicationEngine;
16class QQuickWindow;
18class QGCApplication;
19class QEvent;
20class QPostEventList;
21class QMetaMethod;
22struct QMetaObject;
23
24#if defined(qApp)
25#undef qApp
26#endif
27#define qApp (static_cast<QGCApplication*>(QGuiApplication::instance()))
28
29#if defined(qGuiApp)
30#undef qGuiApp
31#endif
32#define qGuiApp (static_cast<QGCApplication*>(QGuiApplication::instance()))
33
34#define qgcApp() qApp
35
38class QGCApplication : public QGuiApplication
39{
40 Q_OBJECT
41
43 friend class UnitTest;
44public:
45 QGCApplication(int &argc, char *argv[], const QGCCommandLineParser::CommandLineParseResult &args);
47
48 bool runningUnitTests() const { return _runningUnitTests; }
49 bool simpleBootTest() const { return _simpleBootTest; }
50 bool bootTestPassed() const { return _bootTestPassed; }
51
53 bool logOutput() const { return _logOutput; }
54
57 void reportMissingParameter(int componentId, const QString &name);
58
60 bool fakeMobile() const { return _fakeMobile; }
61
62 void setLanguage();
63 QQuickWindow *mainRootWindow();
64 uint64_t msecsSinceBoot() const { return _msecsElapsedTime.elapsed(); }
65
67 void addCompressedSignal(const QMetaMethod &method);
68
69 void removeCompressedSignal(const QMetaMethod &method);
70
71 bool event(QEvent *e) final;
72
73 static QString cachedParameterMetaDataFile();
74 static QString cachedAirframeMetaDataFile();
75
76public:
78 void init();
79 void shutdown();
80
82 QQmlApplicationEngine *qmlAppEngine() const { return _qmlAppEngine; }
83
84signals:
85 void languageChanged(const QLocale &locale);
86
87public slots:
88 void showVehicleConfig();
89
91
93 QLocale getCurrentLanguage() const { return _locale; }
94
96 void showCriticalVehicleMessage(const QString &message);
97
99 void showAppMessage(const QString &message, const QString &title = QString());
100
103 void showRebootAppMessage(const QString &message, const QString &title = QString());
104
106
107private slots:
109 void _missingParamsDisplay();
110 void _qgcCurrentStableVersionDownloadComplete(bool success, const QString &localFile, const QString &errorMsg);
111 static bool _parseVersionText(const QString &versionString, int &majorVersion, int &minorVersion, int &buildVersion);
112 void _showDelayedAppMessages();
113
114private:
115 bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final;
116
117 bool _initVideo();
118
119 bool _initQmlRootWindow();
120
122 void _initForNormalAppBoot();
123
124 QObject *_rootQmlObject();
125 void _checkForNewVersion();
126
127 bool _runningUnitTests = false;
128 bool _simpleBootTest = false;
129 bool _fakeMobile = false;
130 bool _logOutput = false;
131 quint8 _systemId = 0;
132
133 static constexpr int _missingParamsDelayedDisplayTimerTimeout = 1000;
134 QTimer _missingParamsDelayedDisplayTimer;
135 QList<QPair<int,QString>> _missingParams;
136
137 QQmlApplicationEngine *_qmlAppEngine = nullptr;
138 bool _settingsUpgraded = false;
139 int _majorVersion = 0;
140 int _minorVersion = 0;
141 int _buildVersion = 0;
142 QQuickWindow *_mainRootWindow = nullptr;
143 QTranslator _qgcTranslatorSourceCode;
144 QTranslator _qgcTranslatorQtLibs;
145 QLocale _locale;
146 bool _error = false;
147 bool _showErrorsInToolbar = false;
148 QElapsedTimer _msecsElapsedTime;
149 bool _videoManagerInitialized = false;
150 bool _bootTestPassed = true;
151
152 QList<QPair<QString /* title */, QString /* message */>> _delayedAppMessages;
153
154 class CompressedSignalList
155 {
156 public:
157 CompressedSignalList() {}
158 void add(const QMetaMethod &method);
159 void remove(const QMetaMethod &method);
160 bool contains(const QMetaObject *metaObject, int signalIndex);
161
162 private:
164 static int _signalIndex(const QMetaMethod &method);
165
166 QMap<const QMetaObject*, QSet<int>> _signalMap;
167
168 Q_DISABLE_COPY(CompressedSignalList)
169 };
170
171 CompressedSignalList _compressedSignals;
172
173 const QString _settingsVersionKey = QStringLiteral("SettingsVersion");
174
175 const QString _qgcImageProviderId = QStringLiteral("QGCImages");
176};
177
178Q_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()
uint64_t msecsSinceBoot() const
bool simpleBootTest() const
void showAppMessage(const QString &message, const QString &title=QString())
Show modal application message to the user.
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.