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
117private slots:
119 void _missingParamsDisplay();
120 void _showDelayedAppMessages();
121
122private:
123 bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final;
124
125 bool _initVideo();
126
127 bool _initQmlRootWindow();
128
130 void _initForNormalAppBoot();
131
132 QObject *_rootQmlObject();
133 bool _rebootMessageDebounced();
134
135 bool _runningUnitTests = false;
136 bool _simpleBootTest = false;
137 bool _uiTestMode = false;
138 bool _fakeMobile = false;
139 bool _logOutput = false;
140 quint8 _systemId = 0;
141 QTime _lastRebootMessageTime;
142
143 static constexpr int _missingParamsDelayedDisplayTimerTimeout = 1000;
144 QTimer _missingParamsDelayedDisplayTimer;
145 QList<QPair<int,QString>> _missingParams;
146
147 QQmlApplicationEngine *_qmlAppEngine = nullptr;
148 bool _settingsUpgraded = false;
149 QQuickWindow *_mainRootWindow = nullptr;
150 QTranslator _qgcTranslatorSourceCode;
151 QTranslator _qgcTranslatorQtLibs;
152 QLocale _locale;
153 bool _error = false;
154 bool _showErrorsInToolbar = false;
155 QElapsedTimer _msecsElapsedTime;
156 bool _videoManagerInitialized = false;
157 bool _bootTestPassed = true;
158
159 QList<QPair<QString /* title */, QString /* message */>> _delayedAppMessages;
160
161 class CompressedSignalList
162 {
163 public:
164 CompressedSignalList() {}
165 void add(const QMetaMethod &method);
166 void remove(const QMetaMethod &method);
167 bool contains(const QMetaObject *metaObject, int signalIndex);
168
169 private:
171 static int _signalIndex(const QMetaMethod &method);
172
173 QMap<const QMetaObject*, QSet<int>> _signalMap;
174
175 Q_DISABLE_COPY(CompressedSignalList)
176 };
177
178 CompressedSignalList _compressedSignals;
179
180 const QString _settingsVersionKey = QStringLiteral("SettingsVersion");
181
182 const QString _qgcImageProviderId = QStringLiteral("QGCImages");
183};
184
185Q_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.
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.