QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCCorePlugin.cc
Go to the documentation of this file.
1#include "QGCCorePlugin.h"
2#include "AppSettings.h"
3#ifdef Q_OS_ANDROID
4#include "Viewer3DSettings.h"
5#ifndef QGC_NO_SERIAL_LINK
7#endif
8#endif
9#include "FactMetaData.h"
11#include "QGCMAVLink.h"
13#include "InstrumentValueData.h"
14#include "JoystickManager.h"
15#include "QGCLoggingCategory.h"
16#include "QGCOptions.h"
17#include "QmlComponentInfo.h"
18#include "QmlObjectListModel.h"
19#include "SettingsManager.h"
20#include "VideoReceiver.h"
21#include "VideoBackend.h"
22#include "SurveyPlanCreator.h"
25#include "SurveyComplexItem.h"
30#include "Vehicle.h"
31#include "BlankPlanCreator.h"
32#include "ComplexMissionItem.h"
34
35#ifdef QGC_CUSTOM_BUILD
36#include CUSTOMHEADER
37#endif
38
39#include <QtCore/QApplicationStatic>
40#include <QtCore/QFile>
41#include <QtQml/QQmlApplicationEngine>
42#include <QtQml/QQmlContext>
43#include <QtQuick/QQuickItem>
44
45QGC_LOGGING_CATEGORY(QGCCorePluginLog, "API.QGCCorePlugin");
46
47#ifndef QGC_CUSTOM_BUILD
48Q_APPLICATION_STATIC(QGCCorePlugin, _qgcCorePluginInstance);
49#endif
50
52 : QObject(parent)
53 , _defaultOptions(new QGCOptions(this))
54 , _emptyCustomMapItems(new QmlObjectListModel(this))
55{
56 qCDebug(QGCCorePluginLog) << this;
57}
58
60{
61 qCDebug(QGCCorePluginLog) << this;
62}
63
65{
66#ifndef QGC_CUSTOM_BUILD
67 return _qgcCorePluginInstance();
68#else
69 return CUSTOMCLASS::instance();
70#endif
71}
72
73const QVariantList &QGCCorePlugin::analyzePages()
74{
75 // Log Viewer is excluded on mobile (Android/iOS) because parsing large log files
76 // (e.g. 900 MB ULog files with 1000+ fields) exhausts the mobile heap, causing
77 // OOM crashes. Proper mobile support requires time-bucketed downsampling and will
78 // be addressed in a future major release.
79#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
80 static const QVariantList analyzeList = {
81#else
82 static const QVariantList analyzeList = {
83 QVariant::fromValue(new QmlComponentInfo(
84 tr("Log Viewer"),
85 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/LogViewer/LogViewerPage.qml")),
86 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/MAVLinkInspector.svg")))),
87#endif
88 QVariant::fromValue(new QmlComponentInfo(
89 tr("Onboard Logs"),
90 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/OnboardLogs/OnboardLogPage.qml")),
91 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/OnboardLogIcon.svg")), nullptr,
92 true /* requiresVehicle */)),
93 QVariant::fromValue(new QmlComponentInfo(
94 tr("GeoTag Images"),
95 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/GeoTag/GeoTagPage.qml")),
96 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/GeoTag/GeoTagIcon.svg")))),
97 QVariant::fromValue(new QmlComponentInfo(
98 tr("Video Recordings"),
99 QUrl::fromUserInput(
100 QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/VideoRecordings/VideoRecordingsPage.qml")),
101 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/camera_video.svg")))),
102 QVariant::fromValue(new QmlComponentInfo(
103 tr("MAVLink Console"),
104 QUrl::fromUserInput(
105 QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/MAVLinkConsole/MAVLinkConsolePage.qml")),
106 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/MAVLinkConsoleIcon.svg")), nullptr,
107 true /* requiresVehicle */)),
108 QVariant::fromValue(new QmlComponentInfo(
109 tr("MAVLink Inspector"),
110 QUrl::fromUserInput(
111 QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/MAVLinkInspector/MAVLinkInspectorPage.qml")),
112 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/MAVLinkInspector.svg")), nullptr,
113 true /* requiresVehicle */)),
114 QVariant::fromValue(new QmlComponentInfo(
115 tr("Vibration"),
116 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/Vibration/VibrationPage.qml")),
117 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/VibrationPageIcon")), nullptr,
118 true /* requiresVehicle */)),
119 };
120
121 return analyzeList;
122}
123
125{
126 return _defaultOptions;
127}
128
130{
131 return _emptyCustomMapItems;
132}
133
135{
136 return _emptyCustomMapItems;
137}
138
139void QGCCorePlugin::adjustSettingMetaData(const QString &settingsGroup, FactMetaData &metaData, bool &userVisible)
140{
141#ifdef Q_OS_ANDROID
142 // 3D view rendering is too flaky on Android GPUs/drivers; force the
143 // feature off. Hiding the setting also forces it to its default value
144 // (false) regardless of any previously saved user setting.
145 if ((settingsGroup == Viewer3DSettings::settingsGroup) && (metaData.name() == Viewer3DSettings::enabledName)) {
146 userVisible = false;
147 return;
148 }
149#endif
150
151 if (settingsGroup == AppSettings::settingsGroup) {
152 if (metaData.name() == AppSettings::indoorPaletteName) {
153 QVariant outdoorPalette;
154#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
155 outdoorPalette = 0;
156#else
157 outdoorPalette = 1;
158#endif
159 metaData.setRawDefaultValue(outdoorPalette);
160 return;
161 }
162#ifndef Q_OS_ANDROID
163 else if (metaData.name() == AppSettings::androidDontSaveToSDCardName) {
164 userVisible = false;
165 return;
166 }
167#endif
168 else if (metaData.name() == AppSettings::androidUsePosixSerialName) {
169#if defined(Q_OS_ANDROID) && !defined(QGC_NO_SERIAL_LINK)
170 // Only show when the device actually exposes accessible serial device nodes
172#else
173 userVisible = false;
174#endif
175 return;
176 }
177 }
178}
179
181{
182 return tr("WARNING: You are about to enter Advanced Mode. "
183 "If used incorrectly, this may cause your vehicle to malfunction thus voiding your warranty. "
184 "You should do so only if instructed by customer support. "
185 "Are you sure you want to enable Advanced Mode?");
186}
187
192
194{
195 return true;
196}
197
199{
200#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
202#else
204#endif
205
206 if (factValueGrid->specificVehicleForCard()) {
207 bool includeFWValues = factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassFixedWing || factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassVTOL || factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassAirship;
208
209 factValueGrid->setFontSize(defaultFontSize);
210 factValueGrid->appendColumn();
211 factValueGrid->appendColumn();
212
213 int rowIndex = 0;
214 int colIndex = 0;
215
216 // first cell
217 QmlObjectListModel* column = factValueGrid->columns()->value<QmlObjectListModel*>(colIndex++);
218 InstrumentValueData* value = column->value<InstrumentValueData*>(rowIndex);
219 value->setFact("Vehicle", "AltitudeRelative");
220 value->setIcon("arrow-thick-up.svg");
221 value->setText(value->fact()->shortDescription());
222 value->setShowUnits(true);
223
224 // second cell
225 column = factValueGrid->columns()->value<QmlObjectListModel*>(colIndex++);
226 value = column->value<InstrumentValueData*>(rowIndex);
227 if (includeFWValues) {
228 value->setFact("Vehicle", "AirSpeed");
229 value->setText("AirSpd");
230 value->setShowUnits(true);
231 } else {
232 value->setFact("Vehicle", "GroundSpeed");
233 value->setIcon("arrow-simple-right.svg");
234 value->setText(value->fact()->shortDescription());
235 value->setShowUnits(true);
236 }
237 } else {
238 const bool includeFWValues = ((factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassFixedWing) || (factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassVTOL) || (factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassAirship));
239
240 factValueGrid->setFontSize(defaultFontSize);
241
242 (void) factValueGrid->appendColumn();
243 (void) factValueGrid->appendColumn();
244 (void) factValueGrid->appendColumn();
245 if (includeFWValues) {
246 (void) factValueGrid->appendColumn();
247 }
248 factValueGrid->appendRow();
249
250 int rowIndex = 0;
251 QmlObjectListModel *column = factValueGrid->columns()->value<QmlObjectListModel*>(0);
252
253 InstrumentValueData *value = column->value<InstrumentValueData*>(rowIndex++);
254 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("AltitudeRelative"));
255 value->setIcon(QStringLiteral("arrow-thick-up.svg"));
256 value->setText(value->fact()->shortDescription());
257 value->setShowUnits(true);
258
259 value = column->value<InstrumentValueData*>(rowIndex++);
260 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("DistanceToHome"));
261 value->setIcon(QStringLiteral("bookmark copy 3.svg"));
262 value->setText(value->fact()->shortDescription());
263 value->setShowUnits(true);
264
265 rowIndex = 0;
266 column = factValueGrid->columns()->value<QmlObjectListModel*>(1);
267
268 value = column->value<InstrumentValueData*>(rowIndex++);
269 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("ClimbRate"));
270 value->setIcon(QStringLiteral("arrow-simple-up.svg"));
271 value->setText(value->fact()->shortDescription());
272 value->setShowUnits(true);
273
274 value = column->value<InstrumentValueData*>(rowIndex++);
275 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("GroundSpeed"));
276 value->setIcon(QStringLiteral("arrow-simple-right.svg"));
277 value->setText(value->fact()->shortDescription());
278 value->setShowUnits(true);
279
280 if (includeFWValues) {
281 rowIndex = 0;
282 column = factValueGrid->columns()->value<QmlObjectListModel*>(2);
283
284 value = column->value<InstrumentValueData*>(rowIndex++);
285 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("AirSpeed"));
286 value->setText(QStringLiteral("AirSpd"));
287 value->setShowUnits(true);
288
289 value = column->value<InstrumentValueData*>(rowIndex++);
290 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("ThrottlePct"));
291 value->setText(QStringLiteral("Thr"));
292 value->setShowUnits(true);
293 }
294
295 rowIndex = 0;
296 column = factValueGrid->columns()->value<QmlObjectListModel*>(includeFWValues ? 3 : 2);
297
298 value = column->value<InstrumentValueData*>(rowIndex++);
299 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("FlightTime"));
300 value->setIcon(QStringLiteral("timer.svg"));
301 value->setText(value->fact()->shortDescription());
302 value->setShowUnits(false);
303
304 value = column->value<InstrumentValueData*>(rowIndex++);
305 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("FlightDistance"));
306 value->setIcon(QStringLiteral("travel-walk.svg"));
307 value->setText(value->fact()->shortDescription());
308 value->setShowUnits(true);
309 }
310}
311
312QQmlApplicationEngine *QGCCorePlugin::createQmlApplicationEngine(QObject *parent)
313{
314 QQmlApplicationEngine *const qmlEngine = new QQmlApplicationEngine(parent);
315 qmlEngine->addImportPath(QStringLiteral("qrc:/qml"));
316 qmlEngine->rootContext()->setContextProperty(QStringLiteral("joystickManager"), JoystickManager::instance());
317 return qmlEngine;
318}
319
320void QGCCorePlugin::destroyQmlApplicationEngine(QQmlApplicationEngine *qmlEngine)
321{
322 delete qmlEngine;
323}
324
325void QGCCorePlugin::createRootWindow(QQmlApplicationEngine *qmlEngine)
326{
327 qmlEngine->load(QUrl(QStringLiteral("qrc:/qml/QGroundControl/MainWindow.qml")));
328}
329
334
336{
337 static const QVariantList toolBarIndicatorList = QVariantList({
338 QVariant::fromValue(QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/Toolbar/GPSIndicator.qml"))),
339 QVariant::fromValue(
340 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/Toolbar/VideoStreamIndicator.qml"))),
341 });
342
343 return toolBarIndicatorList;
344}
345
347{
349 return { kInitialSetupPromptId };
350 }
351
352 return {};
353}
354
356{
357 QList<int> rgIdsToShow;
358
359 rgIdsToShow.append(firstRunPromptStdIds());
360 rgIdsToShow.append(firstRunPromptCustomIds());
361
362 const QList<int> rgAlreadyShownIds = AppSettings::firstRunPromptsIdsVariantToList(SettingsManager::instance()->appSettings()->firstRunPromptIdsShown()->rawValue());
363 for (int idToRemove: rgAlreadyShownIds) {
364 (void) rgIdsToShow.removeOne(idToRemove);
365 }
366
367 QVariantList rgVarIdsToShow;
368 for (int id: rgIdsToShow) {
369 rgVarIdsToShow.append(id);
370 }
371
372 return rgVarIdsToShow;
373}
374
376{
377 switch (id) {
379 return QStringLiteral("/qml/QGroundControl/FirstRunPromptDialogs/InitialSetupPrompt.qml");
380 default:
381 return QString();
382 }
383}
384
385void QGCCorePlugin::_setShowTouchAreas(bool show)
386{
387 if (show != _showTouchAreas) {
388 _showTouchAreas = show;
389 emit showTouchAreasChanged(show);
390 }
391}
392
393void QGCCorePlugin::_setShowAdvancedUI(bool show)
394{
395 if (show != _showAdvancedUI) {
396 _showAdvancedUI = show;
397 emit showAdvancedUIChanged(show);
398 }
399}
400
402{
403 auto makeEntry = [](const char* canonical, const QString& translated) {
404 QVariantMap entry;
405 entry[QStringLiteral("canonicalName")] = QString(canonical);
406 entry[QStringLiteral("translatedName")] = translated;
407 return entry;
408 };
409
410 QVariantList items;
411 items.append(makeEntry(SurveyComplexItem::canonicalName, SurveyComplexItem::tr(SurveyComplexItem::canonicalName)));
412 items.append(makeEntry(CorridorScanComplexItem::canonicalName, CorridorScanComplexItem::tr(CorridorScanComplexItem::canonicalName)));
413 if (vehicle->multiRotor() || vehicle->vtol()) {
414 items.append(makeEntry(StructureScanComplexItem::canonicalName, StructureScanComplexItem::tr(StructureScanComplexItem::canonicalName)));
415 }
416 // Note: Landing pattern items are not added here — they have their own dedicated button
417 return items;
418}
419
420QList<PlanCreator*> QGCCorePlugin::planCreators(PlanMasterController *planMasterController)
421{
422 return {
423 new SurveyPlanCreator(planMasterController),
424 new CorridorScanPlanCreator(planMasterController),
425 new StructureScanPlanCreator(planMasterController),
426 new BlankPlanCreator(planMasterController),
427 };
428}
429
431 const QString &complexItemType,
432 PlanMasterController *masterController,
433 bool flyView,
434 const QString &kmlOrShpFile)
435{
436 if (complexItemType == SurveyComplexItem::canonicalName || complexItemType == SurveyComplexItem::jsonComplexItemTypeValue) {
437 return new SurveyComplexItem(masterController, flyView, kmlOrShpFile);
438 } else if (complexItemType == CorridorScanComplexItem::canonicalName || complexItemType == CorridorScanComplexItem::jsonComplexItemTypeValue) {
439 return new CorridorScanComplexItem(masterController, flyView, kmlOrShpFile);
440 } else if (complexItemType == StructureScanComplexItem::canonicalName || complexItemType == StructureScanComplexItem::jsonComplexItemTypeValue) {
441 return new StructureScanComplexItem(masterController, flyView, kmlOrShpFile);
443 return new FixedWingLandingComplexItem(masterController, flyView);
444 } else if (complexItemType == VTOLLandingComplexItem::canonicalName || complexItemType == VTOLLandingComplexItem::jsonComplexItemTypeValue) {
445 return new VTOLLandingComplexItem(masterController, flyView);
446 }
447
448 qCWarning(QGCCorePluginLog) << "QGCCorePlugin::createComplexMissionItem - Unknown complex item type:" << complexItemType;
449 return nullptr;
450}
Q_APPLICATION_STATIC(QGCCorePlugin, _qgcCorePluginInstance)
#define QGC_LOGGING_CATEGORY(name, categoryStr)
static QList< int > firstRunPromptsIdsVariantToList(const QVariant &firstRunPromptIds)
static constexpr const char * canonicalName
static constexpr const char * jsonComplexItemTypeValue
Holds the meta data associated with a Fact.
void setRawDefaultValue(const QVariant &rawDefaultValue)
QString name() const
QmlObjectListModel * columns(void) const
void setFontSize(FontSize fontSize)
Q_INVOKABLE QmlObjectListModel * appendColumn(void)
Vehicle * specificVehicleForCard(void) const
QGCMAVLinkTypes::VehicleClass_t vehicleClass(void) const
Q_INVOKABLE void appendRow(void)
bool singleVehicleSupport()
Returns true if the system supports only a single firmware class with a single vehicle type.
static FirmwarePluginManager * instance()
static constexpr const char * jsonComplexItemTypeValue
static constexpr const char * canonicalName
Q_INVOKABLE void setFact(const QString &factGroupName, const QString &factName)
static JoystickManager * instance()
Master controller for mission, fence, rally.
Extension mechanism for generic, non-firmware-specific customization of QGC.
virtual ComplexMissionItem * createComplexMissionItem(const QString &complexItemType, PlanMasterController *masterController, bool flyView, const QString &kmlOrShpFile=QString())
virtual QList< int > firstRunPromptStdIds()
QGCCorePlugin(QObject *parent=nullptr)
virtual QVariantList complexMissionItemNames(Vehicle *vehicle)
void showTouchAreasChanged(bool showTouchAreas)
virtual ~QGCCorePlugin()
virtual void factValueGridCreateDefaultSettings(FactValueGrid *factValueGrid)
void showAdvancedUIChanged(bool showAdvancedUI)
virtual const QVariantList & toolBarIndicators()
virtual QList< int > firstRunPromptCustomIds()
virtual Q_INVOKABLE QString firstRunPromptResource(int id) const
Returns the resource which contains the specified first run prompt for display.
static constexpr int kInitialSetupPromptId
virtual QGCOptions * options()
virtual QQmlApplicationEngine * createQmlApplicationEngine(QObject *parent)
virtual bool showInitialSetupMeasurementUnits() const
virtual const QVariantList & analyzePages()
virtual bool showInitialSetupVehiclePreferences() const
virtual QString showAdvancedUIMessage() const
virtual void createRootWindow(QQmlApplicationEngine *qmlEngine)
Allows the plugin to override the creation of the root (native) window.
virtual VideoReceiver * createVideoReceiver(QObject *parent)
Allows the plugin to override the creation of VideoReceiver.
virtual const QmlObjectListModel * customGeoMapItems()
Q_INVOKABLE QVariantList firstRunPromptsToShow()
Returns the list of first run prompt ids which need to be displayed according to current settings.
virtual const QmlObjectListModel * customMapItems()
Allows custom builds to add custom items to the FlightMap. Objects put into QmlObjectListModel should...
virtual QList< PlanCreator * > planCreators(PlanMasterController *planMasterController)
virtual void adjustSettingMetaData(const QString &settingsGroup, FactMetaData &metaData, bool &userVisible)
virtual void destroyQmlApplicationEngine(QQmlApplicationEngine *qmlEngine)
static QGCCorePlugin * instance()
Represents a Qml component which can be loaded from a resource.
T value(int index) const
QString settingsGroup() const
static SettingsManager * instance()
static constexpr const char * canonicalName
static constexpr const char * jsonComplexItemTypeValue
static constexpr const char * jsonComplexItemTypeValue
static constexpr const char * canonicalName
static constexpr const char * canonicalName
static constexpr const char * jsonComplexItemTypeValue
bool vtol() const
Definition Vehicle.cc:1808
bool multiRotor() const
Definition Vehicle.cc:1803
static VideoBackend & instance()
virtual VideoReceiver * createReceiver(QObject *parent)=0
A receiver that can play: once initialize() has failed, one that needs no initialization.
bool hasPosixSerialPorts()
Whether the device has a serial port node that QGC may read and write.