Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
de0169ab
Commit
de0169ab
authored
Sep 30, 2016
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new validateKeys support
parent
d24e93d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
JsonHelper.cc
src/JsonHelper.cc
+22
-0
JsonHelper.h
src/JsonHelper.h
+8
-0
No files found.
src/JsonHelper.cc
View file @
de0169ab
...
...
@@ -262,3 +262,25 @@ void JsonHelper::saveGeoCoordinateArray(const QList<QGeoCoordinate>& rgPoints
}
return
saveGeoCoordinateArray
(
rgVarPoints
,
writeAltitude
,
jsonValue
);
}
bool
JsonHelper
::
validateKeys
(
const
QJsonObject
&
jsonObject
,
const
QList
<
JsonHelper
::
KeyValidateInfo
>&
keyInfo
,
QString
&
errorString
)
{
QStringList
keyList
;
QList
<
QJsonValue
::
Type
>
typeList
;
for
(
int
i
=
0
;
i
<
keyInfo
.
count
();
i
++
)
{
if
(
keyInfo
[
i
].
required
)
{
keyList
.
append
(
keyInfo
[
i
].
key
);
}
}
if
(
!
validateRequiredKeys
(
jsonObject
,
keyList
,
errorString
))
{
return
false
;
}
keyList
.
clear
();
for
(
int
i
=
0
;
i
<
keyInfo
.
count
();
i
++
)
{
keyList
.
append
(
keyInfo
[
i
].
key
);
typeList
.
append
(
keyInfo
[
i
].
type
);
}
return
validateKeyTypes
(
jsonObject
,
keyList
,
typeList
,
errorString
);
}
src/JsonHelper.h
View file @
de0169ab
...
...
@@ -37,6 +37,14 @@ public:
static
bool
validateRequiredKeys
(
const
QJsonObject
&
jsonObject
,
const
QStringList
&
keys
,
QString
&
errorString
);
static
bool
validateKeyTypes
(
const
QJsonObject
&
jsonObject
,
const
QStringList
&
keys
,
const
QList
<
QJsonValue
::
Type
>&
types
,
QString
&
errorString
);
typedef
struct
{
const
char
*
key
;
///< json key name
QJsonValue
::
Type
type
;
///< type of key
bool
required
;
///< true: key must be present
}
KeyValidateInfo
;
static
bool
validateKeys
(
const
QJsonObject
&
jsonObject
,
const
QList
<
KeyValidateInfo
>&
keyInfo
,
QString
&
errorString
);
/// Loads a QGeoCoordinate
/// @return false: validation failed
static
bool
loadGeoCoordinate
(
const
QJsonValue
&
jsonValue
,
///< json value to load from
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment