QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
JsonHelper Namespace Reference

Classes

struct  KeyValidateInfo
 

Functions

QStringList _addDefaultLocKeys (QJsonObject &jsonObject)
 
QJsonObject _translateRoot (QJsonObject &jsonObject, const QString &translateContext, const QStringList &translateKeys)
 
QJsonObject _translateObject (QJsonObject &jsonObject, const QString &translateContext, const QStringList &translateKeys)
 
QJsonArray _translateArray (QJsonArray &jsonArray, const QString &translateContext, const QStringList &translateKeys)
 
QTranslator * translator ()
 
void saveQGCJsonFileHeader (QJsonObject &jsonObject, const QString &fileType, int version)
 Saves the standard file header the json object.
 
bool validateExternalQGCJsonFile (const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
 returned error string if validation fails
 
bool validateInternalQGCJsonFile (const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
 returned error string if validation fails
 
QJsonObject openInternalQGCJsonFile (const QString &jsonFilename, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
 returned error string if validation fails
 
bool validateKeys (const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
 
bool loadGeoCoordinate (const QJsonValue &jsonValue, bool altitudeRequired, QGeoCoordinate &coordinate, QString &errorString, bool geoJsonFormat=false)
 if true, use [lon, lat], [lat, lon] otherwise
 
void saveGeoCoordinate (const QGeoCoordinate &coordinate, bool writeAltitude, QJsonValue &jsonValue, bool geoJsonFormat=false)
 
bool loadGeoCoordinateArray (const QJsonValue &jsonValue, bool altitudeRequired, QVariantList &rgVarPoints, QString &errorString)
 returned error string if load failure
 
bool loadGeoCoordinateArray (const QJsonValue &jsonValue, bool altitudeRequired, QList< QGeoCoordinate > &rgPoints, QString &errorString)
 returned error string if load failure
 
void saveGeoCoordinateArray (const QVariantList &rgVarPoints, bool writeAltitude, QJsonValue &jsonValue)
 Saves a list of QGeoCoordinates to a json array.
 
void saveGeoCoordinateArray (const QList< QGeoCoordinate > &rgPoints, bool writeAltitude, QJsonValue &jsonValue)
 json value to save to
 
bool loadPolygon (const QJsonArray &polygonArray, QmlObjectListModel &list, QObject *parent, QString &errorString)
 Loads a polygon from an array.
 
void savePolygon (const QmlObjectListModel &list, QJsonArray &polygonArray)
 Saves a polygon to a json array.
 

Variables

constexpr const char * _translateKeysKey = "translateKeys"
 
constexpr const char * _arrayIDKeysKey = "_arrayIDKeys"
 
constexpr const char * _jsonGroundStationKey = "groundStation"
 
constexpr const char * _jsonGroundStationValue = "QGroundControl"
 
constexpr const char * jsonVersionKey = "version"
 
constexpr const char * jsonFileTypeKey = "fileType"
 

Detailed Description

Json manipulation helper class. Primarily used for parsing and processing Fact metadata.

Function Documentation

◆ _addDefaultLocKeys()

QStringList JsonHelper::_addDefaultLocKeys ( QJsonObject &  jsonObject)

◆ _translateArray()

QJsonArray JsonHelper::_translateArray ( QJsonArray &  jsonArray,
const QString &  translateContext,
const QStringList &  translateKeys 
)

Definition at line 116 of file JsonHelper.cc.

References _translateObject().

Referenced by _translateObject().

◆ _translateObject()

QJsonObject JsonHelper::_translateObject ( QJsonObject &  jsonObject,
const QString &  translateContext,
const QStringList &  translateKeys 
)

Definition at line 76 of file JsonHelper.cc.

References _translateArray(), _translateObject(), and translator().

Referenced by _translateArray(), _translateObject(), and _translateRoot().

◆ _translateRoot()

QJsonObject JsonHelper::_translateRoot ( QJsonObject &  jsonObject,
const QString &  translateContext,
const QStringList &  translateKeys 
)

Definition at line 70 of file JsonHelper.cc.

References _translateObject().

Referenced by openInternalQGCJsonFile().

◆ loadGeoCoordinate()

bool JsonHelper::loadGeoCoordinate ( const QJsonValue &  jsonValue,
bool  altitudeRequired,
QGeoCoordinate &  coordinate,
QString &  errorString,
bool  geoJsonFormat = false 
)

if true, use [lon, lat], [lat, lon] otherwise

Loads a QGeoCoordinate Stored as array [ lat, lon, alt ]

Returns
false: validation failed
Parameters
jsonValuejson value to load from
altitudeRequiredtrue: altitude must be specified
coordinatereturned QGeoCordinate
errorStringreturned error string if load failure

Definition at line 132 of file JsonHelper.cc.

References errorString, and JsonParsing::possibleNaNJsonValue().

Referenced by LandingComplexItem::_load(), GeoFenceController::load(), QGCMapCircle::loadFromJson(), loadGeoCoordinateArray(), GeoJsonHelper::loadGeoJsonCoordinate(), and loadPolygon().

◆ loadGeoCoordinateArray() [1/2]

bool JsonHelper::loadGeoCoordinateArray ( const QJsonValue &  jsonValue,
bool  altitudeRequired,
QList< QGeoCoordinate > &  rgPoints,
QString &  errorString 
)

returned error string if load failure

Parameters
jsonValuejson value which contains points
altitudeRequiredtrue: altitude field must be specified
rgPointsreturned points

Definition at line 304 of file JsonHelper.cc.

References errorString, and loadGeoCoordinateArray().

◆ loadGeoCoordinateArray() [2/2]

bool JsonHelper::loadGeoCoordinateArray ( const QJsonValue &  jsonValue,
bool  altitudeRequired,
QVariantList &  rgVarPoints,
QString &  errorString 
)

returned error string if load failure

Loads a list of QGeoCoordinates from a json array

Returns
false: validation failed
Parameters
jsonValuejson value which contains points
altitudeRequiredtrue: altitude field must be specified
rgVarPointsreturned points

Definition at line 282 of file JsonHelper.cc.

References errorString, and loadGeoCoordinate().

Referenced by TransectStyleComplexItem::_load(), RallyPointController::load(), QGCMapPolygon::loadFromJson(), QGCMapPolyline::loadFromJson(), and loadGeoCoordinateArray().

◆ loadPolygon()

bool JsonHelper::loadPolygon ( const QJsonArray &  polygonArray,
QmlObjectListModel list,
QObject *  parent,
QString &  errorString 
)

Loads a polygon from an array.

returned error string if load failure

Parameters
polygonArrayArray of coordinates
listEmpty list to add vertices to
parentparent for newly allocated QGCQGeoCoordinates

Definition at line 368 of file JsonHelper.cc.

References QmlObjectListModel::append(), QmlObjectListModel::clearAndDeleteContents(), errorString, and loadGeoCoordinate().

◆ openInternalQGCJsonFile()

QJsonObject JsonHelper::openInternalQGCJsonFile ( const QString &  jsonFilename,
const QString &  expectedFileType,
int  minSupportedVersion,
int  maxSupportedVersion,
int &  version,
QString &  errorString 
)

returned error string if validation fails

Parameters
jsonFilenameJson file to open
expectedFileTypecorrect file type for file
minSupportedVersionminimum supported version
maxSupportedVersionmaximum supported major version
versionreturned file version

Definition at line 239 of file JsonHelper.cc.

References _addDefaultLocKeys(), _translateRoot(), errorString, QGCNetworkHelper::parseCompressedJson(), QGCFileHelper::readFile(), and validateInternalQGCJsonFile().

Referenced by FactMetaData::createMapFromJsonFile().

◆ saveGeoCoordinate()

void JsonHelper::saveGeoCoordinate ( const QGeoCoordinate &  coordinate,
bool  writeAltitude,
QJsonValue &  jsonValue,
bool  geoJsonFormat = false 
)

Saves a QGeoCoordinate Stored as array [ lat, lon, alt ]

Parameters
coordinateQGeoCoordinate to save
writeAltitudetrue: write altitude to json
jsonValuejson value to save to

Definition at line 170 of file JsonHelper.cc.

Referenced by LandingComplexItem::_save(), GeoFenceController::save(), MissionController::save(), RallyPointController::save(), saveGeoCoordinateArray(), GeoJsonHelper::saveGeoJsonCoordinate(), and savePolygon().

◆ saveGeoCoordinateArray() [1/2]

void JsonHelper::saveGeoCoordinateArray ( const QList< QGeoCoordinate > &  rgPoints,
bool  writeAltitude,
QJsonValue &  jsonValue 
)

json value to save to

Parameters
rgPointspoints to save
writeAltitudetrue: write altitide value

Definition at line 333 of file JsonHelper.cc.

References saveGeoCoordinateArray().

◆ saveGeoCoordinateArray() [2/2]

void JsonHelper::saveGeoCoordinateArray ( const QVariantList &  rgVarPoints,
bool  writeAltitude,
QJsonValue &  jsonValue 
)

Saves a list of QGeoCoordinates to a json array.

json value to save to

Parameters
rgVarPointspoints to save
writeAltitudetrue: write altitide value

Definition at line 321 of file JsonHelper.cc.

References saveGeoCoordinate().

Referenced by TransectStyleComplexItem::_save(), saveGeoCoordinateArray(), QGCMapPolygon::saveToJson(), and QGCMapPolyline::saveToJson().

◆ savePolygon()

void JsonHelper::savePolygon ( const QmlObjectListModel list,
QJsonArray &  polygonArray 
)

Saves a polygon to a json array.

Array to save into

Parameters
listList which contains vertices

Definition at line 383 of file JsonHelper.cc.

References QmlObjectListModel::count(), saveGeoCoordinate(), and QmlObjectListModel::value().

◆ saveQGCJsonFileHeader()

void JsonHelper::saveQGCJsonFileHeader ( QJsonObject &  jsonObject,
const QString &  fileType,
int  version 
)

Saves the standard file header the json object.

version number for file

Parameters
jsonObjectroot json object
fileTypefile type for file

Definition at line 275 of file JsonHelper.cc.

References _jsonGroundStationKey, _jsonGroundStationValue, jsonFileTypeKey, and jsonVersionKey.

Referenced by PlanMasterController::saveToJson().

◆ translator()

QTranslator * JsonHelper::translator ( )

Definition at line 127 of file JsonHelper.cc.

References s_jsonTranslator.

Referenced by _translateObject(), and QGCApplication::setLanguage().

◆ validateExternalQGCJsonFile()

bool JsonHelper::validateExternalQGCJsonFile ( const QJsonObject &  jsonObject,
const QString &  expectedFileType,
int  minSupportedVersion,
int  maxSupportedVersion,
int &  version,
QString &  errorString 
)

returned error string if validation fails

Validates the standard parts of an external QGC json file (Plan file, ...): jsonFileTypeKey - Required and checked to be equal to expectedFileType jsonVersionKey - Required and checked to be below supportedMajorVersion, supportedMinorVersion jsonGroundStationKey - Required and checked to be string type

Returns
false: validation failed, errorString set
Parameters
jsonObjectjson object to validate
expectedFileTypecorrect file type for file
minSupportedVersionminimum supported version
maxSupportedVersionmaximum supported major version
versionreturned file version

Definition at line 223 of file JsonHelper.cc.

References _jsonGroundStationKey, errorString, validateInternalQGCJsonFile(), and validateKeys().

Referenced by PlanMasterController::loadFromFile().

◆ validateInternalQGCJsonFile()

bool JsonHelper::validateInternalQGCJsonFile ( const QJsonObject &  jsonObject,
const QString &  expectedFileType,
int  minSupportedVersion,
int  maxSupportedVersion,
int &  version,
QString &  errorString 
)

returned error string if validation fails

Validates the standard parts of a internal QGC json file (FactMetaData, ...): jsonFileTypeKey - Required and checked to be equal to expectedFileType jsonVersionKey - Required and checked to be below supportedMajorVersion, supportedMinorVersion

Returns
false: validation failed, errorString set
Parameters
jsonObjectjson object to validate
expectedFileTypecorrect file type for file
minSupportedVersionminimum supported version
maxSupportedVersionmaximum supported major version
versionreturned file version

Definition at line 188 of file JsonHelper.cc.

References errorString, jsonFileTypeKey, jsonVersionKey, and validateKeys().

Referenced by openInternalQGCJsonFile(), and validateExternalQGCJsonFile().

◆ validateKeys()

Variable Documentation

◆ _arrayIDKeysKey

constexpr const char* JsonHelper::_arrayIDKeysKey = "_arrayIDKeys"
constexpr

Definition at line 32 of file JsonHelper.cc.

Referenced by _addDefaultLocKeys().

◆ _jsonGroundStationKey

constexpr const char* JsonHelper::_jsonGroundStationKey = "groundStation"
constexpr

Definition at line 33 of file JsonHelper.cc.

Referenced by saveQGCJsonFileHeader(), and validateExternalQGCJsonFile().

◆ _jsonGroundStationValue

constexpr const char* JsonHelper::_jsonGroundStationValue = "QGroundControl"
constexpr

Definition at line 34 of file JsonHelper.cc.

Referenced by saveQGCJsonFileHeader().

◆ _translateKeysKey

constexpr const char* JsonHelper::_translateKeysKey = "translateKeys"
constexpr

Definition at line 31 of file JsonHelper.cc.

Referenced by _addDefaultLocKeys().

◆ jsonFileTypeKey

constexpr const char* JsonHelper::jsonFileTypeKey = "fileType"
constexpr

◆ jsonVersionKey