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 "QGCLogging.h"
3#include "AppSettings.h"
4#include "MavlinkSettings.h"
5#include "FactMetaData.h"
6#ifdef QGC_GST_STREAMING
7#include "GStreamer.h"
8#endif
10#include "InstrumentValueData.h"
11#include "JoystickManager.h"
12#include "MAVLinkLib.h"
13#include "QGCLoggingCategory.h"
14#include "QGCOptions.h"
15#include "QmlComponentInfo.h"
16#include "QmlObjectListModel.h"
17#ifdef QGC_QT_STREAMING
19#endif
20#include "SettingsManager.h"
21#include "VideoReceiver.h"
22
23#ifdef QGC_CUSTOM_BUILD
24#include CUSTOMHEADER
25#endif
26
27#include <QtCore/QApplicationStatic>
28#include <QtCore/QFile>
29#include <QtQml/qqml.h>
30#include <QtQml/QQmlApplicationEngine>
31#include <QtQml/QQmlContext>
32#include <QtQuick/QQuickItem>
33
34QGC_LOGGING_CATEGORY(QGCCorePluginLog, "API.QGCCorePlugin");
35
36#ifndef QGC_CUSTOM_BUILD
37Q_APPLICATION_STATIC(QGCCorePlugin, _qgcCorePluginInstance);
38#endif
39
40QGCCorePlugin::QGCCorePlugin(QObject *parent)
41 : QObject(parent)
42 , _defaultOptions(new QGCOptions(this))
43 , _emptyCustomMapItems(new QmlObjectListModel(this))
44{
45 qCDebug(QGCCorePluginLog) << this;
46}
47
48QGCCorePlugin::~QGCCorePlugin()
49{
50 qCDebug(QGCCorePluginLog) << this;
51}
52
53QGCCorePlugin *QGCCorePlugin::instance()
54{
55#ifndef QGC_CUSTOM_BUILD
56 return _qgcCorePluginInstance();
57#else
58 return CUSTOMCLASS::instance();
59#endif
60}
61
62const QVariantList &QGCCorePlugin::analyzePages()
63{
64 static const QVariantList analyzeList = {
65 QVariant::fromValue(new QmlComponentInfo(
66 tr("Log Download"),
67 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/LogDownloadPage.qml")),
68 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/LogDownloadIcon.svg")))),
69 QVariant::fromValue(new QmlComponentInfo(
70 tr("GeoTag Images"),
71 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/GeoTag/GeoTagPage.qml")),
72 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/GeoTag/GeoTagIcon.svg")))),
73 QVariant::fromValue(new QmlComponentInfo(
74 tr("MAVLink Console"),
75 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/MAVLinkConsolePage.qml")),
76 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/MAVLinkConsoleIcon.svg")))),
77#ifndef QGC_DISABLE_MAVLINK_INSPECTOR
78 QVariant::fromValue(new QmlComponentInfo(
79 tr("MAVLink Inspector"),
80 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/MAVLinkInspectorPage.qml")),
81 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/MAVLinkInspector.svg")))),
82#endif
83 QVariant::fromValue(new QmlComponentInfo(
84 tr("Vibration"),
85 QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AnalyzeView/VibrationPage.qml")),
86 QUrl::fromUserInput(QStringLiteral("qrc:/qmlimages/VibrationPageIcon")))),
87 };
88
89 return analyzeList;
90}
91
92QGCOptions *QGCCorePlugin::options()
93{
94 return _defaultOptions;
95}
96
97const QmlObjectListModel *QGCCorePlugin::customMapItems()
98{
99 return _emptyCustomMapItems;
100}
101
102void QGCCorePlugin::adjustSettingMetaData(const QString &settingsGroup, FactMetaData &metaData, bool &visible)
103{
104#ifdef Q_OS_ANDROID
105 Q_UNUSED(visible);
106#endif
107
108 if (settingsGroup == AppSettings::settingsGroup) {
109 if (metaData.name() == AppSettings::indoorPaletteName) {
110 QVariant outdoorPalette;
111#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
112 outdoorPalette = 0;
113#else
114 outdoorPalette = 1;
115#endif
116 metaData.setRawDefaultValue(outdoorPalette);
117 return;
118 }
119#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
120 else if (metaData.name() == MavlinkSettings::telemetrySaveName) {
121 metaData.setRawDefaultValue(false);
122 return;
123 }
124#endif
125#ifndef Q_OS_ANDROID
126 else if (metaData.name() == AppSettings::androidDontSaveToSDCardName) {
127 visible = false;
128 return;
129 }
130#endif
131 }
132}
133
134QString QGCCorePlugin::showAdvancedUIMessage() const
135{
136 return tr("WARNING: You are about to enter Advanced Mode. "
137 "If used incorrectly, this may cause your vehicle to malfunction thus voiding your warranty. "
138 "You should do so only if instructed by customer support. "
139 "Are you sure you want to enable Advanced Mode?");
140}
141
142void QGCCorePlugin::factValueGridCreateDefaultSettings(FactValueGrid* factValueGrid)
143{
144#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
146#else
148#endif
149
150 if (factValueGrid->specificVehicleForCard()) {
151 bool includeFWValues = factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassFixedWing || factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassVTOL || factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassAirship;
152
153 factValueGrid->setFontSize(defaultFontSize);
154 factValueGrid->appendColumn();
155 factValueGrid->appendColumn();
156
157 int rowIndex = 0;
158 int colIndex = 0;
159
160 // first cell
161 QmlObjectListModel* column = factValueGrid->columns()->value<QmlObjectListModel*>(colIndex++);
162 InstrumentValueData* value = column->value<InstrumentValueData*>(rowIndex);
163 value->setFact("Vehicle", "AltitudeRelative");
164 value->setIcon("arrow-thick-up.svg");
165 value->setText(value->fact()->shortDescription());
166 value->setShowUnits(true);
167
168 // second cell
169 column = factValueGrid->columns()->value<QmlObjectListModel*>(colIndex++);
170 value = column->value<InstrumentValueData*>(rowIndex);
171 if (includeFWValues) {
172 value->setFact("Vehicle", "AirSpeed");
173 value->setText("AirSpd");
174 value->setShowUnits(true);
175 } else {
176 value->setFact("Vehicle", "GroundSpeed");
177 value->setIcon("arrow-simple-right.svg");
178 value->setText(value->fact()->shortDescription());
179 value->setShowUnits(true);
180 }
181 } else {
182 const bool includeFWValues = ((factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassFixedWing) || (factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassVTOL) || (factValueGrid->vehicleClass() == QGCMAVLink::VehicleClassAirship));
183
184 factValueGrid->setFontSize(defaultFontSize);
185
186 (void) factValueGrid->appendColumn();
187 (void) factValueGrid->appendColumn();
188 (void) factValueGrid->appendColumn();
189 if (includeFWValues) {
190 (void) factValueGrid->appendColumn();
191 }
192 factValueGrid->appendRow();
193
194 int rowIndex = 0;
195 QmlObjectListModel *column = factValueGrid->columns()->value<QmlObjectListModel*>(0);
196
197 InstrumentValueData *value = column->value<InstrumentValueData*>(rowIndex++);
198 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("AltitudeRelative"));
199 value->setIcon(QStringLiteral("arrow-thick-up.svg"));
200 value->setText(value->fact()->shortDescription());
201 value->setShowUnits(true);
202
203 value = column->value<InstrumentValueData*>(rowIndex++);
204 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("DistanceToHome"));
205 value->setIcon(QStringLiteral("bookmark copy 3.svg"));
206 value->setText(value->fact()->shortDescription());
207 value->setShowUnits(true);
208
209 rowIndex = 0;
210 column = factValueGrid->columns()->value<QmlObjectListModel*>(1);
211
212 value = column->value<InstrumentValueData*>(rowIndex++);
213 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("ClimbRate"));
214 value->setIcon(QStringLiteral("arrow-simple-up.svg"));
215 value->setText(value->fact()->shortDescription());
216 value->setShowUnits(true);
217
218 value = column->value<InstrumentValueData*>(rowIndex++);
219 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("GroundSpeed"));
220 value->setIcon(QStringLiteral("arrow-simple-right.svg"));
221 value->setText(value->fact()->shortDescription());
222 value->setShowUnits(true);
223
224 if (includeFWValues) {
225 rowIndex = 0;
226 column = factValueGrid->columns()->value<QmlObjectListModel*>(2);
227
228 value = column->value<InstrumentValueData*>(rowIndex++);
229 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("AirSpeed"));
230 value->setText(QStringLiteral("AirSpd"));
231 value->setShowUnits(true);
232
233 value = column->value<InstrumentValueData*>(rowIndex++);
234 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("ThrottlePct"));
235 value->setText(QStringLiteral("Thr"));
236 value->setShowUnits(true);
237 }
238
239 rowIndex = 0;
240 column = factValueGrid->columns()->value<QmlObjectListModel*>(includeFWValues ? 3 : 2);
241
242 value = column->value<InstrumentValueData*>(rowIndex++);
243 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("FlightTime"));
244 value->setIcon(QStringLiteral("timer.svg"));
245 value->setText(value->fact()->shortDescription());
246 value->setShowUnits(false);
247
248 value = column->value<InstrumentValueData*>(rowIndex++);
249 value->setFact(QStringLiteral("Vehicle"), QStringLiteral("FlightDistance"));
250 value->setIcon(QStringLiteral("travel-walk.svg"));
251 value->setText(value->fact()->shortDescription());
252 value->setShowUnits(true);
253 }
254}
255
256QQmlApplicationEngine *QGCCorePlugin::createQmlApplicationEngine(QObject *parent)
257{
258 QQmlApplicationEngine *const qmlEngine = new QQmlApplicationEngine(parent);
259 qmlEngine->addImportPath(QStringLiteral("qrc:/qml"));
260 qmlEngine->rootContext()->setContextProperty(QStringLiteral("joystickManager"), JoystickManager::instance());
261 qmlEngine->rootContext()->setContextProperty(QStringLiteral("debugMessageModel"), QGCLogging::instance());
262 return qmlEngine;
263}
264
265void QGCCorePlugin::createRootWindow(QQmlApplicationEngine *qmlEngine)
266{
267 qmlEngine->load(QUrl(QStringLiteral("qrc:/qml/QGroundControl/MainWindow.qml")));
268}
269
270VideoReceiver *QGCCorePlugin::createVideoReceiver(QObject *parent)
271{
272#ifdef QGC_GST_STREAMING
273 return GStreamer::createVideoReceiver(parent);
274#elif defined(QGC_QT_STREAMING)
276#else
277 return nullptr;
278#endif
279}
280
281void *QGCCorePlugin::createVideoSink(QQuickItem *widget, QObject *parent)
282{
283#ifdef QGC_GST_STREAMING
284 return GStreamer::createVideoSink(widget, parent);
285#elif defined(QGC_QT_STREAMING)
286 return QtMultimediaReceiver::createVideoSink(widget, parent);
287#else
288 Q_UNUSED(widget); Q_UNUSED(parent);
289 return nullptr;
290#endif
291}
292void QGCCorePlugin::releaseVideoSink(void *sink)
293{
294#ifdef QGC_GST_STREAMING
296#elif defined(QGC_QT_STREAMING)
298#else
299 Q_UNUSED(sink);
300#endif
301}
302
303const QVariantList &QGCCorePlugin::toolBarIndicators()
304{
305 static const QVariantList toolBarIndicatorList = QVariantList(
306 {
307 QVariant::fromValue(QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/Toolbar/RTKGPSIndicator.qml"))),
308 }
309 );
310
311 return toolBarIndicatorList;
312}
313
314QVariantList QGCCorePlugin::firstRunPromptsToShow()
315{
316 QList<int> rgIdsToShow;
317
318 rgIdsToShow.append(firstRunPromptStdIds());
319 rgIdsToShow.append(firstRunPromptCustomIds());
320
321 const QList<int> rgAlreadyShownIds = AppSettings::firstRunPromptsIdsVariantToList(SettingsManager::instance()->appSettings()->firstRunPromptIdsShown()->rawValue());
322 for (int idToRemove: rgAlreadyShownIds) {
323 (void) rgIdsToShow.removeOne(idToRemove);
324 }
325
326 QVariantList rgVarIdsToShow;
327 for (int id: rgIdsToShow) {
328 rgVarIdsToShow.append(id);
329 }
330
331 return rgVarIdsToShow;
332}
333
334QString QGCCorePlugin::firstRunPromptResource(int id) const
335{
336 switch (id) {
337 case kUnitsFirstRunPromptId:
338 return QStringLiteral("/qml/QGroundControl/FirstRunPromptDialogs/UnitsFirstRunPrompt.qml");
339 case kOfflineVehicleFirstRunPromptId:
340 return QStringLiteral("/qml/QGroundControl/FirstRunPromptDialogs/OfflineVehicleFirstRunPrompt.qml");
341 default:
342 return QString();
343 }
344}
345
346void QGCCorePlugin::_setShowTouchAreas(bool show)
347{
348 if (show != _showTouchAreas) {
349 _showTouchAreas = show;
350 emit showTouchAreasChanged(show);
351 }
352}
353
354void QGCCorePlugin::_setShowAdvancedUI(bool show)
355{
356 if (show != _showAdvancedUI) {
357 _showAdvancedUI = show;
358 emit showAdvancedUIChanged(show);
359 }
360}
Q_APPLICATION_STATIC(QGCCorePlugin, _qgcCorePluginInstance)
#define QGC_LOGGING_CATEGORY(name, categoryStr)
static const char * indoorPaletteName
Definition AppSettings.h:31
static const char * settingsGroup
Definition AppSettings.h:16
static QList< int > firstRunPromptsIdsVariantToList(const QVariant &firstRunPromptIds)
static const char * androidDontSaveToSDCardName
Definition AppSettings.h:33
void setRawDefaultValue(const QVariant &rawDefaultValue)
QString name() const
QmlObjectListModel * columns(void) const
void setFontSize(FontSize fontSize)
QmlObjectListModel * appendColumn(void)
Vehicle * specificVehicleForCard(void) const
QGCMAVLink::VehicleClass_t vehicleClass(void) const
void appendRow(void)
void setIcon(const QString &icon)
static const char * telemetrySaveName
void showTouchAreasChanged(bool showTouchAreas)
void showAdvancedUIChanged(bool showAdvancedUI)
static QGCLogging * instance()
Get the singleton instance.
Definition QGCLogging.cc:50
Represents a Qml component which can be loaded from a resource.
T value(int index) const
static VideoReceiver * createVideoReceiver(QObject *parent)
static void releaseVideoSink(void *sink)
static void * createVideoSink(QQuickItem *widget, QObject *parent=nullptr)
VideoReceiver * createVideoReceiver(QObject *parent)
Definition GStreamer.cc:572
void releaseVideoSink(void *sink)
Definition GStreamer.cc:566
void * createVideoSink(QQuickItem *widget, QObject *)
Definition GStreamer.cc:552