QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGroundControlQmlGlobal.cc
Go to the documentation of this file.
2
3#include "QGCCorePlugin.h"
4#include "LinkManager.h"
5#include "MAVLinkProtocol.h"
7#include "AppSettings.h"
8#include "FlightMapSettings.h"
9#include "SettingsManager.h"
10#include "PositionManager.h"
11#include "QGCMapEngineManager.h"
12#include "ADSBVehicleManager.h"
13#include "AudioOutput.h"
14#include "NTRIPManager.h"
15#include "MAVLinkSigningKeys.h"
16#include "MissionCommandTree.h"
17#include "VideoManager.h"
18#include "MultiVehicleManager.h"
20#ifndef QGC_NO_SERIAL_LINK
21#include "GPSManager.h"
22#include "GPSRtk.h"
23#endif
24#ifdef QT_DEBUG
25#include "MockLink.h"
26#endif
27
28#include <QtCore/QLineF>
29#include <QtCore/QSettings>
30#include <QtGui/QClipboard>
31#include <QtGui/QGuiApplication>
32
33#include "QGCLoggingCategory.h"
34
35QGC_LOGGING_CATEGORY(GuidedActionsControllerLog, "QMLControls.GuidedActionsController")
36
37QGeoCoordinate QGroundControlQmlGlobal::_coord = QGeoCoordinate(0.0,0.0);
38double QGroundControlQmlGlobal::_zoom = 2;
39
41 : QObject(parent)
42 , _mapEngineManager(QGCMapEngineManager::instance())
43 , _adsbVehicleManager(ADSBVehicleManager::instance())
44 , _ntripManager(NTRIPManager::instance())
45 , _qgcPositionManager(QGCPositionManager::instance())
46 , _missionCommandTree(MissionCommandTree::instance())
47 , _mavlinkSigningKeys(MAVLinkSigningKeys::instance())
48 , _videoManager(VideoManager::instance())
49 , _linkManager(LinkManager::instance())
50 , _multiVehicleManager(MultiVehicleManager::instance())
51 , _settingsManager(SettingsManager::instance())
52 , _corePlugin(QGCCorePlugin::instance())
53 , _globalPalette(new QGCPalette(this))
54#ifndef QGC_NO_SERIAL_LINK
55 , _gpsRtkFactGroup(GPSManager::instance()->gpsRtk()->gpsRtkFactGroup())
56#endif
57{
58 // We clear the parent on this object since we run into shutdown problems caused by hybrid qml app. Instead we let it leak on shutdown.
59 // setParent(nullptr);
60
61 // Load last coordinates and zoom from config file
62 QSettings settings;
63 settings.beginGroup(_flightMapPositionSettingsGroup);
64 _coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey, _coord.latitude()).toDouble());
65 _coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey, _coord.longitude()).toDouble());
66 _zoom = settings.value(_flightMapZoomSettingsKey, _zoom).toDouble();
67 _flightMapPositionSettledTimer.setSingleShot(true);
68 _flightMapPositionSettledTimer.setInterval(1000);
69 (void) connect(&_flightMapPositionSettledTimer, &QTimer::timeout, this, []() {
70 // When they settle, save flightMapPosition and Zoom to the config file
71 QSettings settingsInner;
72 settingsInner.beginGroup(_flightMapPositionSettingsGroup);
73 settingsInner.setValue(_flightMapPositionLatitudeSettingsKey, _coord.latitude());
74 settingsInner.setValue(_flightMapPositionLongitudeSettingsKey, _coord.longitude());
75 settingsInner.setValue(_flightMapZoomSettingsKey, _zoom);
76 });
77 connect(this, &QGroundControlQmlGlobal::flightMapPositionChanged, this, [this](QGeoCoordinate){
78 if (!_flightMapPositionSettledTimer.isActive()) {
79 _flightMapPositionSettledTimer.start();
80 }
81 });
82 connect(this, &QGroundControlQmlGlobal::flightMapZoomChanged, this, [this](double){
83 if (!_flightMapPositionSettledTimer.isActive()) {
84 _flightMapPositionSettledTimer.start();
85 }
86 });
87}
88
92
93void QGroundControlQmlGlobal::saveGlobalSetting (const QString& key, const QString& value)
94{
95 QSettings settings;
96 settings.beginGroup(kQmlGlobalKeyName);
97 settings.setValue(key, value);
98}
99
100QString QGroundControlQmlGlobal::loadGlobalSetting (const QString& key, const QString& defaultValue)
101{
102 QSettings settings;
103 settings.beginGroup(kQmlGlobalKeyName);
104 return settings.value(key, defaultValue).toString();
105}
106
107void QGroundControlQmlGlobal::saveBoolGlobalSetting (const QString& key, bool value)
108{
109 QSettings settings;
110 settings.beginGroup(kQmlGlobalKeyName);
111 settings.setValue(key, value);
112}
113
114bool QGroundControlQmlGlobal::loadBoolGlobalSetting (const QString& key, bool defaultValue)
115{
116 QSettings settings;
117 settings.beginGroup(kQmlGlobalKeyName);
118 return settings.value(key, defaultValue).toBool();
119}
120
121#ifdef QT_DEBUG
122static MockConfiguration::Options _mockLinkOptions(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity, bool apmStartFreshParams = false)
123{
124 MockConfiguration::Options options = MockConfiguration::OptionNone;
125 options.setFlag(MockConfiguration::OptionSendStatusText, sendStatusText);
126 options.setFlag(MockConfiguration::OptionEnableCamera, enableCamera);
127 options.setFlag(MockConfiguration::OptionEnableGimbal, enableGimbal);
128 options.setFlag(MockConfiguration::OptionEnableProximity, enableProximity);
129 options.setFlag(MockConfiguration::OptionAPMStartFreshParams, apmStartFreshParams);
130 return options;
131}
132#endif
133
134void QGroundControlQmlGlobal::startPX4MockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity, int videoStreamType)
135{
136#ifdef QT_DEBUG
137 MockLink::startPX4MockLink(_mockLinkOptions(sendStatusText, enableCamera, enableGimbal, enableProximity), MockConfiguration::FailNone, MockConfiguration::videoStreamTypeFromInt(videoStreamType));
138#else
139 Q_UNUSED(sendStatusText);
140 Q_UNUSED(enableCamera);
141 Q_UNUSED(enableGimbal);
142 Q_UNUSED(enableProximity);
143 Q_UNUSED(videoStreamType);
144#endif
145}
146
147void QGroundControlQmlGlobal::startGenericMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity, int videoStreamType)
148{
149#ifdef QT_DEBUG
150 MockLink::startGenericMockLink(_mockLinkOptions(sendStatusText, enableCamera, enableGimbal, enableProximity), MockConfiguration::FailNone, MockConfiguration::videoStreamTypeFromInt(videoStreamType));
151#else
152 Q_UNUSED(sendStatusText);
153 Q_UNUSED(enableCamera);
154 Q_UNUSED(enableGimbal);
155 Q_UNUSED(enableProximity);
156 Q_UNUSED(videoStreamType);
157#endif
158}
159
160void QGroundControlQmlGlobal::startAPMArduCopterMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity, bool apmStartFreshParams, int videoStreamType)
161{
162#ifdef QT_DEBUG
163 MockLink::startAPMArduCopterMockLink(_mockLinkOptions(sendStatusText, enableCamera, enableGimbal, enableProximity, apmStartFreshParams), MockConfiguration::FailNone, MockConfiguration::videoStreamTypeFromInt(videoStreamType));
164#else
165 Q_UNUSED(sendStatusText);
166 Q_UNUSED(enableCamera);
167 Q_UNUSED(enableGimbal);
168 Q_UNUSED(enableProximity);
169 Q_UNUSED(apmStartFreshParams);
170 Q_UNUSED(videoStreamType);
171#endif
172}
173
174void QGroundControlQmlGlobal::startAPMArduPlaneMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity, bool apmStartFreshParams, int videoStreamType)
175{
176#ifdef QT_DEBUG
177 MockLink::startAPMArduPlaneMockLink(_mockLinkOptions(sendStatusText, enableCamera, enableGimbal, enableProximity, apmStartFreshParams), MockConfiguration::FailNone, MockConfiguration::videoStreamTypeFromInt(videoStreamType));
178#else
179 Q_UNUSED(sendStatusText);
180 Q_UNUSED(enableCamera);
181 Q_UNUSED(enableGimbal);
182 Q_UNUSED(enableProximity);
183 Q_UNUSED(apmStartFreshParams);
184 Q_UNUSED(videoStreamType);
185#endif
186}
187
188void QGroundControlQmlGlobal::startAPMArduSubMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity, bool apmStartFreshParams, int videoStreamType)
189{
190#ifdef QT_DEBUG
191 MockLink::startAPMArduSubMockLink(_mockLinkOptions(sendStatusText, enableCamera, enableGimbal, enableProximity, apmStartFreshParams), MockConfiguration::FailNone, MockConfiguration::videoStreamTypeFromInt(videoStreamType));
192#else
193 Q_UNUSED(sendStatusText);
194 Q_UNUSED(enableCamera);
195 Q_UNUSED(enableGimbal);
196 Q_UNUSED(enableProximity);
197 Q_UNUSED(apmStartFreshParams);
198 Q_UNUSED(videoStreamType);
199#endif
200}
201
202void QGroundControlQmlGlobal::startAPMArduRoverMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity, bool apmStartFreshParams, int videoStreamType)
203{
204#ifdef QT_DEBUG
205 MockLink::startAPMArduRoverMockLink(_mockLinkOptions(sendStatusText, enableCamera, enableGimbal, enableProximity, apmStartFreshParams), MockConfiguration::FailNone, MockConfiguration::videoStreamTypeFromInt(videoStreamType));
206#else
207 Q_UNUSED(sendStatusText);
208 Q_UNUSED(enableCamera);
209 Q_UNUSED(enableGimbal);
210 Q_UNUSED(enableProximity);
211 Q_UNUSED(apmStartFreshParams);
212 Q_UNUSED(videoStreamType);
213#endif
214}
215
217{
218#ifdef QT_DEBUG
219 QList<SharedLinkInterfacePtr> sharedLinks = LinkManager::instance()->links();
220
221 for (int i=0; i<sharedLinks.count(); i++) {
222 LinkInterface* link = sharedLinks[i].get();
223 MockLink* mockLink = qobject_cast<MockLink*>(link);
224 if (mockLink) {
225 mockLink->disconnect();
226 return;
227 }
228 }
229#endif
230}
231
236
238{
239 if (singleFirmwareSupport()) {
240 return FirmwarePluginManager::instance()->supportedVehicleClasses(FirmwarePluginManager::instance()->supportedFirmwareClasses()[0]).count() == 1;
241 }
242
243 return false;
244}
245
250
255
256bool QGroundControlQmlGlobal::linesIntersect(QPointF line1A, QPointF line1B, QPointF line2A, QPointF line2B)
257{
258 QPointF intersectPoint;
259
260 auto intersect = QLineF(line1A, line1B).intersects(QLineF(line2A, line2B), &intersectPoint);
261
262 return intersect == QLineF::BoundedIntersection &&
263 intersectPoint != line1A && intersectPoint != line1B;
264}
265
266void QGroundControlQmlGlobal::setFlightMapPosition(QGeoCoordinate& coordinate)
267{
268 if (coordinate != flightMapPosition()) {
269 _coord.setLatitude(coordinate.latitude());
270 _coord.setLongitude(coordinate.longitude());
271 emit flightMapPositionChanged(coordinate);
272 }
273}
274
276{
277 if (zoom != flightMapZoom()) {
278 _zoom = zoom;
279 emit flightMapZoomChanged(zoom);
280 }
281}
282
284{
285 QString versionStr = QCoreApplication::applicationVersion();
286 if(QSysInfo::buildAbi().contains("32"))
287 {
288 versionStr += QStringLiteral(" %1").arg(tr("32 bit"));
289 }
290 else if(QSysInfo::buildAbi().contains("64"))
291 {
292 versionStr += QStringLiteral(" %1").arg(tr("64 bit"));
293 }
294 return versionStr;
295}
296
298{
299 switch (altFrame) {
301 return QString();
303 return tr("Rel");
305 return tr("AMSL");
307 return tr("AGLC");
309 return tr("AGL");
311 return tr("Mixed");
312 }
313
314 // Should never get here but makes some compilers happy
315 return QString();
316}
317
319{
320 switch (altFrame) {
322 return QString();
324 return tr("Relative (%1)").arg(altitudeFrameExtraUnits(altFrame));
326 return tr("Absolute (%1)").arg(altitudeFrameExtraUnits(altFrame));
328 return tr("Above Terrain Calced (%1)").arg(altitudeFrameExtraUnits(altFrame));
330 return tr("Above Terrain (%1)").arg(altitudeFrameExtraUnits(altFrame));
332 return tr("Mixed");
333 }
334
335 // Should never get here but makes some compilers happy
336 return QString();
337}
338
340 QObject* owner,
341 const QString& title,
342 const QString& text,
343 int buttons,
344 QJSValue acceptFunction,
345 QJSValue closeFunction)
346{
347 emit showMessageDialogRequested(owner, title, text, buttons, acceptFunction, closeFunction);
348}
349
354
356{
357 QGuiApplication::clipboard()->setText(text);
358}
359
361{
362 return _settingsManager->flightMapSettings()->elevationMapProvider()->rawValue().toString();
363}
364
366{
367 return _settingsManager->flightMapSettings()->elevationMapProvider()->rawValue().toString();
368}
369
374
379
381{
382 return QCoreApplication::applicationName();
383}
384
385
#define QGC_LOGGING_CATEGORY(name, categoryStr)
static constexpr const char * parameterFileExtension
static constexpr const char * telemetryFileExtension
void testAudioOutput()
Tests the audio output. Will stop current output before test.
static AudioOutput * instance()
bool firmwareClassSupported(QGCMAVLink::FirmwareClass_t firmwareClass)
Returns true if the specified firmware class is supported by the system.
QList< QGCMAVLink::FirmwareClass_t > supportedFirmwareClasses()
Returns list of firmwares which are supported by the system.
QList< QGCMAVLink::VehicleClass_t > supportedVehicleClasses(QGCMAVLink::FirmwareClass_t firmwareClass)
Returns the list of supported vehicle types for the specified firmware.
static FirmwarePluginManager * instance()
static GPSManager * instance()
Definition GPSManager.cc:23
The link interface defines the interface for all links used to communicate with the ground station ap...
Manage communication links The Link Manager organizes the physical Links. It can manage arbitrary lin...
Definition LinkManager.h:32
static LinkManager * instance()
QList< SharedLinkInterfacePtr > links()
Bag of named MAVLink signing keys; correct key per vehicle is auto-detected from incoming signed pack...
Manages a hierarchy of MissionCommandUIInfo.
static VideoStreamType videoStreamTypeFromInt(int value)
Extension mechanism for generic, non-firmware-specific customization of QGC.
QGCPalette is used in QML ui to expose color properties for the QGC palette.
Definition QGCPalette.h:83
void setFlightMapPosition(QGeoCoordinate &coordinate)
QString telemetryFileExtension(void) const
Q_INVOKABLE void startGenericMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity=false, int videoStreamType=0)
void showMessageDialogRequested(QObject *owner, QString title, QString text, int buttons, QJSValue acceptFunction, QJSValue closeFunction)
void flightMapPositionChanged(QGeoCoordinate flightMapPosition)
Q_INVOKABLE QString loadGlobalSetting(const QString &key, const QString &defaultValue)
Q_INVOKABLE void startAPMArduCopterMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity=false, bool apmStartFreshParams=false, int videoStreamType=0)
Q_INVOKABLE void startAPMArduRoverMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity=false, bool apmStartFreshParams=false, int videoStreamType=0)
Q_INVOKABLE QString altitudeFrameExtraUnits(AltitudeFrame altFrame)
String shown in the FactTextField.extraUnits ui.
static QGeoCoordinate flightMapPosition()
void flightMapZoomChanged(double flightMapZoom)
Q_INVOKABLE void stopOneMockLink(void)
Q_INVOKABLE bool loadBoolGlobalSetting(const QString &key, bool defaultValue)
QString parameterFileExtension(void) const
Q_INVOKABLE bool linesIntersect(QPointF xLine1, QPointF yLine1, QPointF xLine2, QPointF yLine2)
Q_INVOKABLE void startPX4MockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity=false, int videoStreamType=0)
Q_INVOKABLE void saveBoolGlobalSetting(const QString &key, bool value)
Q_INVOKABLE QString altitudeFrameShortDescription(AltitudeFrame altFrame)
String shown when a user needs to select an altitude frame.
Q_INVOKABLE void showMessageDialog(QObject *owner, const QString &title, const QString &text, int buttons=kDefaultMessageDialogButtons, QJSValue acceptFunction=QJSValue(), QJSValue closeFunction=QJSValue())
static Q_INVOKABLE void copyToClipboard(const QString &text)
Copy text to the system clipboard.
Q_INVOKABLE void startAPMArduSubMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity=false, bool apmStartFreshParams=false, int videoStreamType=0)
Q_INVOKABLE void startAPMArduPlaneMockLink(bool sendStatusText, bool enableCamera, bool enableGimbal, bool enableProximity=false, bool apmStartFreshParams=false, int videoStreamType=0)
Q_INVOKABLE void saveGlobalSetting(const QString &key, const QString &value)
Provides access to all app settings.
FlightMapSettings * flightMapSettings() const