QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
JsonHelper.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QLoggingCategory>
4#include <QtCore/QJsonObject>
5#include <QtCore/QVariantList>
6#include <QtPositioning/QGeoCoordinate>
7
9class QTranslator;
10
11Q_DECLARE_LOGGING_CATEGORY(JsonHelperLog)
12
13
15namespace JsonHelper
16{
17 QTranslator *translator();
18
20 void saveQGCJsonFileHeader(QJsonObject &jsonObject,
21 const QString &fileType,
22 int version);
23
29 bool validateExternalQGCJsonFile(const QJsonObject &jsonObject,
30 const QString &expectedFileType,
31 int minSupportedVersion,
32 int maxSupportedVersion,
33 int &version,
34 QString &errorString);
35
40 bool validateInternalQGCJsonFile(const QJsonObject &jsonObject,
41 const QString &expectedFileType,
42 int minSupportedVersion,
43 int maxSupportedVersion,
44 int &version,
45 QString &errorString);
46
47 // Opens, validates and translates an internal QGC json file.
48 // @return Json root object for file. Empty QJsonObject if error.
49 QJsonObject openInternalQGCJsonFile(const QString &jsonFilename,
50 const QString &expectedFileType,
51 int minSupportedVersion,
52 int maxSupportedVersion,
53 int &version,
54 QString &errorString);
55
57 const char *key;
58 QJsonValue::Type type;
59 bool required;
60 };
61
62 bool validateKeys(const QJsonObject& jsonObject, const QList<KeyValidateInfo>& keyInfo, QString& errorString);
63
67 bool loadGeoCoordinate(const QJsonValue &jsonValue,
68 bool altitudeRequired,
69 QGeoCoordinate &coordinate,
70 QString &errorString,
71 bool geoJsonFormat = false);
72
75 void saveGeoCoordinate(const QGeoCoordinate &coordinate,
76 bool writeAltitude,
77 QJsonValue &jsonValue,
78 bool geoJsonFormat = false);
79
82 bool loadGeoCoordinateArray(const QJsonValue &jsonValue,
83 bool altitudeRequired,
84 QVariantList &rgVarPoints,
85 QString &errorString);
86 bool loadGeoCoordinateArray(const QJsonValue &jsonValue,
87 bool altitudeRequired,
88 QList<QGeoCoordinate> &rgPoints,
89 QString &errorString);
90
92 void saveGeoCoordinateArray(const QVariantList &rgVarPoints,
93 bool writeAltitude,
94 QJsonValue &jsonValue);
95 void saveGeoCoordinateArray(const QList<QGeoCoordinate> &rgPoints,
96 bool writeAltitude,
97 QJsonValue &jsonValue);
98
100 bool loadPolygon(const QJsonArray &polygonArray,
101 QmlObjectListModel &list,
102 QObject *parent,
103 QString &errorString);
104
106 void savePolygon(const QmlObjectListModel &list,
107 QJsonArray &polygonArray);
108
109 constexpr const char *jsonVersionKey = "version";
110 constexpr const char *jsonFileTypeKey = "fileType";
111};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
QString errorString
bool validateExternalQGCJsonFile(const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
returned error string if validation fails
void saveGeoCoordinateArray(const QVariantList &rgVarPoints, bool writeAltitude, QJsonValue &jsonValue)
Saves a list of QGeoCoordinates to a json array.
bool loadGeoCoordinateArray(const QJsonValue &jsonValue, bool altitudeRequired, QVariantList &rgVarPoints, QString &errorString)
returned error string if load failure
QJsonObject openInternalQGCJsonFile(const QString &jsonFilename, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
returned error string if validation fails
constexpr const char * jsonVersionKey
Definition JsonHelper.h:109
QTranslator * translator()
bool loadPolygon(const QJsonArray &polygonArray, QmlObjectListModel &list, QObject *parent, QString &errorString)
Loads a polygon from an array.
bool validateKeys(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
void saveQGCJsonFileHeader(QJsonObject &jsonObject, const QString &fileType, int version)
Saves the standard file header the json object.
constexpr const char * jsonFileTypeKey
Definition JsonHelper.h:110
void savePolygon(const QmlObjectListModel &list, QJsonArray &polygonArray)
Saves a polygon to a json array.
bool validateInternalQGCJsonFile(const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
returned error string if validation fails
void saveGeoCoordinate(const QGeoCoordinate &coordinate, bool writeAltitude, QJsonValue &jsonValue, bool geoJsonFormat=false)
bool loadGeoCoordinate(const QJsonValue &jsonValue, bool altitudeRequired, QGeoCoordinate &coordinate, QString &errorString, bool geoJsonFormat=false)
if true, use [lon, lat], [lat, lon] otherwise
bool required
true: key must be present
Definition JsonHelper.h:59
const char * key
json key name
Definition JsonHelper.h:57
QJsonValue::Type type
required type for key, QJsonValue::Null specifies double with possible NaN
Definition JsonHelper.h:58