QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MissionCommandList.cc
Go to the documentation of this file.
2#include "JsonHelper.h"
5
6#include <QtCore/QJsonArray>
7
8MissionCommandList::MissionCommandList(const QString& jsonFilename, bool baseCommandList, QObject* parent)
9 : QObject(parent)
10{
11 _loadMavCmdInfoJson(jsonFilename, baseCommandList);
12}
13
14void MissionCommandList::_loadMavCmdInfoJson(const QString& jsonFilename, bool baseCommandList)
15{
16 if (jsonFilename.isEmpty()) {
17 return;
18 }
19
20 qCDebug(MissionCommandsLog) << "Loading" << jsonFilename;
21
22 QString errorString;
23 int version;
24 QJsonObject jsonObject = JsonHelper::openInternalQGCJsonFile(jsonFilename, qgcFileType, 1, 1, version, errorString);
25 if (!errorString.isEmpty()) {
26 qWarning() << "Internal Error: " << errorString;
27 return;
28 }
29
30 QJsonValue jsonValue = jsonObject.value(_mavCmdInfoJsonKey);
31 if (!jsonValue.isArray()) {
32 qWarning() << jsonFilename << "mavCmdInfo not array";
33 return;
34 }
35
36 // Iterate over MissionCommandUIInfo objects
37 QJsonArray jsonArray = jsonValue.toArray();
38 for(QJsonValue info: jsonArray) {
39 if (!info.isObject()) {
40 qWarning() << jsonFilename << "mavCmdArray should contain objects";
41 return;
42 }
43
45
46 QString uiInfoErrorString;
47 if (!uiInfo->loadJsonInfo(info.toObject(), baseCommandList, uiInfoErrorString)) {
48 uiInfo->deleteLater();
49 qWarning() << jsonFilename << uiInfoErrorString;
50 return;
51 }
52
53 // Update list of known categories
54 QString newCategory = uiInfo->category();
55 if (!newCategory.isEmpty() && !_categories.contains(newCategory)) {
56 _categories.append(newCategory);
57 }
58
59 _infoMap[uiInfo->command()] = uiInfo;
60 }
61
62 // Build id list
63 for (MAV_CMD id: _infoMap.keys()) {
64 _ids << id;
65 }
66}
67
69{
70 if (!_infoMap.contains(command)) {
71 return nullptr;
72 }
73
74 return _infoMap[command];
75}
QString errorString
MissionCommandUIInfo * getUIInfo(MAV_CMD command) const
Returns the ui info for specified command, NULL if command not found.
static constexpr const char * qgcFileType
MissionCommandList(const QString &jsonFilename, bool baseCommandList, QObject *parent=nullptr)
bool loadJsonInfo(const QJsonObject &jsonObject, bool requireFullObject, QString &errorString)
QString category(void) const
QJsonObject openInternalQGCJsonFile(const QString &jsonFilename, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
returned error string if validation fails