QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
JsonParsing.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QJsonDocument>
4#include <QtCore/QJsonObject>
5#include <QtCore/QJsonValue>
6#include <QtCore/QStringList>
7
8class QTranslator;
9
10namespace JsonParsing {
11
12constexpr const char *jsonVersionKey = "version";
13constexpr const char *jsonFileTypeKey = "fileType";
14
15
17bool isJsonFile(const QString& fileName, QJsonDocument& jsonDoc, QString& errorString);
18
20bool isJsonFile(const QByteArray& bytes, QJsonDocument& jsonDoc, QString& errorString);
21
23bool validateRequiredKeys(const QJsonObject& jsonObject, const QStringList& keys, QString& errorString);
24
27bool validateKeyTypes(const QJsonObject& jsonObject, const QStringList& keys, const QList<QJsonValue::Type>& types,
28 QString& errorString);
29
31 const char *key;
32 QJsonValue::Type type;
33 bool required;
34};
35
37bool validateKeys(const QJsonObject& jsonObject, const QList<KeyValidateInfo>& keyInfo, QString& errorString);
38
40bool validateKeysStrict(const QJsonObject& jsonObject, const QList<KeyValidateInfo>& keyInfo, QString& errorString);
41
43double possibleNaNJsonValue(const QJsonValue& value);
44
46QTranslator *translator();
47
49void saveQGCJsonFileHeader(QJsonObject &jsonObject, const QString &fileType, int version);
50
53bool validateExternalQGCJsonFile(const QJsonObject &jsonObject,
54 const QString &expectedFileType,
55 int minSupportedVersion,
56 int maxSupportedVersion,
57 int &version,
58 QString &errorString);
59
62bool validateInternalQGCJsonFile(const QJsonObject &jsonObject,
63 const QString &expectedFileType,
64 int minSupportedVersion,
65 int maxSupportedVersion,
66 int &version,
67 QString &errorString);
68
72QJsonObject openInternalQGCJsonFile(const QString &jsonFilename,
73 const QString &expectedFileType,
74 int minSupportedVersion,
75 int maxSupportedVersion,
76 int &version,
77 QString &errorString,
78 const QStringList &defaultTranslateKeys = {},
79 const QStringList &defaultArrayIDKeys = {});
80
81} // namespace JsonParsing
QString errorString
bool validateExternalQGCJsonFile(const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
bool validateKeyTypes(const QJsonObject &jsonObject, const QStringList &keys, const QList< QJsonValue::Type > &types, QString &errorString)
bool validateInternalQGCJsonFile(const QJsonObject &jsonObject, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString)
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 isJsonFile(const QByteArray &bytes, QJsonDocument &jsonDoc, QString &errorString)
Determines whether an in-memory byte buffer contains parseable JSON content.
constexpr const char * jsonFileTypeKey
Definition JsonParsing.h:13
QJsonObject openInternalQGCJsonFile(const QString &jsonFilename, const QString &expectedFileType, int minSupportedVersion, int maxSupportedVersion, int &version, QString &errorString, const QStringList &defaultTranslateKeys, const QStringList &defaultArrayIDKeys)
double possibleNaNJsonValue(const QJsonValue &value)
Returns NaN if the value is null, or the value converted to double otherwise.
void saveQGCJsonFileHeader(QJsonObject &jsonObject, const QString &fileType, int version)
Saves the standard QGC file header (groundStation, fileType, version) into the json object.
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.
constexpr const char * jsonVersionKey
Definition JsonParsing.h:12
bool validateRequiredKeys(const QJsonObject &jsonObject, const QStringList &keys, QString &errorString)
Validates that all listed keys are present in the object.
bool required
true: key must be present
Definition JsonParsing.h:33
QJsonValue::Type type
required type for key, QJsonValue::Null specifies double with possible NaN
Definition JsonParsing.h:32
const char * key
json key name
Definition JsonParsing.h:31