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

Classes

struct  KeyValidateInfo
 

Functions

bool validateRequiredKeys (const QJsonObject &jsonObject, const QStringList &keys, QString &errorString)
 Validates that all listed keys are present in the object.
 
bool validateKeyTypes (const QJsonObject &jsonObject, const QStringList &keys, const QList< QJsonValue::Type > &types, QString &errorString)
 
bool isJsonFile (const QByteArray &bytes, QJsonDocument &jsonDoc, QString &errorString)
 Determines whether an in-memory byte buffer contains parseable JSON content.
 
bool isJsonFile (const QString &fileName, QJsonDocument &jsonDoc, QString &errorString)
 Determines whether a file path contains parseable JSON content.
 
double possibleNaNJsonValue (const QJsonValue &value)
 Returns NaN if the value is null, or the value converted to double otherwise.
 
bool validateKeys (const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
 Validates that all required keys are present and that listed keys have the expected type.
 
bool validateKeysStrict (const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
 Validates keys like validateKeys but also rejects any keys not listed in keyInfo.
 
QTranslator * translator ()
 Translator used by openInternalQGCJsonFile for localized strings.
 
void saveQGCJsonFileHeader (QJsonObject &jsonObject, const QString &fileType, int version)
 Saves the standard QGC file header (groundStation, fileType, version) into the json object.
 
bool validateInternalQGCJsonFile (const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
 
bool validateExternalQGCJsonFile (const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
 
QJsonObject openInternalQGCJsonFile (const QString &jsonFilename, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString, const QStringList &defaultTranslateKeys, const QStringList &defaultArrayIDKeys)
 

Variables

constexpr const char * jsonVersionKey = "version"
 
constexpr const char * jsonFileTypeKey = "fileType"
 

Function Documentation

◆ isJsonFile() [1/2]

bool JsonParsing::isJsonFile ( const QByteArray &  bytes,
QJsonDocument &  jsonDoc,
QString &  errorString 
)

◆ isJsonFile() [2/2]

bool JsonParsing::isJsonFile ( const QString &  fileName,
QJsonDocument &  jsonDoc,
QString &  errorString 
)

Determines whether a file path contains parseable JSON content.

Definition at line 114 of file JsonParsing.cc.

References errorString, isJsonFile(), and QGCCompression::readFile().

◆ openInternalQGCJsonFile()

QJsonObject JsonParsing::openInternalQGCJsonFile ( const QString &  jsonFilename,
const QString &  expectedFileType,
int  minSupportedVersion,
int  maxSupportedVersion,
int &  version,
QString &  errorString,
const QStringList &  defaultTranslateKeys = {},
const QStringList &  defaultArrayIDKeys = {} 
)

Opens, validates, and translates an internal QGC json file.

Parameters
defaultTranslateKeysKeys to translate when translateKeys is absent from the JSON.
defaultArrayIDKeysArray ID keys to use when _arrayIDKeys is absent from the JSON.

Definition at line 334 of file JsonParsing.cc.

References errorString, QGCCompression::parseCompressedJson(), QGCCompression::readFile(), and validateInternalQGCJsonFile().

Referenced by FactMetaData::createMapFromJsonFile(), CameraMetaData::parseCameraMetaData(), and PowerModulePresetController::powerModulePresets().

◆ possibleNaNJsonValue()

double JsonParsing::possibleNaNJsonValue ( const QJsonValue &  value)

Returns NaN if the value is null, or the value converted to double otherwise.

Definition at line 124 of file JsonParsing.cc.

Referenced by MissionItem::load(), SimpleMissionItem::load(), GeoJsonHelper::loadGeoCoordinate(), GeoJsonHelper::loadGeoJsonCoordinate(), and MissionCommandUIInfo::loadJsonInfo().

◆ saveQGCJsonFileHeader()

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

Saves the standard QGC file header (groundStation, fileType, version) into the json object.

Definition at line 276 of file JsonParsing.cc.

References jsonFileTypeKey, and jsonVersionKey.

Referenced by PlanMasterController::saveToJson().

◆ translator()

QTranslator * JsonParsing::translator ( )

Translator used by openInternalQGCJsonFile for localized strings.

Definition at line 271 of file JsonParsing.cc.

Referenced by QGCApplication::setLanguage().

◆ validateExternalQGCJsonFile()

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

Validates the standard parts of an external QGC json file (Plan file, ...). Checks groundStation, fileType, and version keys.

Definition at line 318 of file JsonParsing.cc.

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

Referenced by PlanMasterController::loadFromFile().

◆ validateInternalQGCJsonFile()

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

Validates the standard parts of an internal QGC json file (FactMetaData, ...). Checks fileType and version keys.

Definition at line 283 of file JsonParsing.cc.

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

Referenced by openInternalQGCJsonFile(), and validateExternalQGCJsonFile().

◆ validateKeys()

◆ validateKeysStrict()

bool JsonParsing::validateKeysStrict ( const QJsonObject &  jsonObject,
const QList< KeyValidateInfo > &  keyInfo,
QString &  errorString 
)

Validates keys like validateKeys but also rejects any keys not listed in keyInfo.

Definition at line 156 of file JsonParsing.cc.

References errorString, and validateKeys().

Referenced by PowerModulePresetController::powerModulePresets().

◆ validateKeyTypes()

bool JsonParsing::validateKeyTypes ( const QJsonObject &  jsonObject,
const QStringList &  keys,
const QList< QJsonValue::Type > &  types,
QString &  errorString 
)

Validates value types for listed keys that are present in the object. QJsonValue::Null as expected type means "double value with possible NaN".

Definition at line 68 of file JsonParsing.cc.

References errorString.

Referenced by MissionCommandUIInfo::loadJsonInfo(), and validateKeys().

◆ validateRequiredKeys()

bool JsonParsing::validateRequiredKeys ( const QJsonObject &  jsonObject,
const QStringList &  keys,
QString &  errorString 
)

Validates that all listed keys are present in the object.

Definition at line 47 of file JsonParsing.cc.

References errorString.

Referenced by QGCMapPolygon::loadFromJson(), QGCMapPolyline::loadFromJson(), MissionCommandUIInfo::loadJsonInfo(), and validateKeys().

Variable Documentation

◆ jsonFileTypeKey

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

Definition at line 13 of file JsonParsing.h.

Referenced by saveQGCJsonFileHeader(), and validateInternalQGCJsonFile().

◆ jsonVersionKey