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
cc0080b0
Commit
cc0080b0
authored
Jul 01, 2020
by
DonLakeFlyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parent
d2bfb99a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
JsonHelper.cc
src/JsonHelper.cc
+16
-0
JsonHelper.h
src/JsonHelper.h
+6
-0
No files found.
src/JsonHelper.cc
View file @
cc0080b0
...
...
@@ -225,11 +225,27 @@ bool JsonHelper::isJsonFile(const QByteArray& bytes, QJsonDocument& jsonDoc, QSt
if
(
parseError
.
error
==
QJsonParseError
::
NoError
)
{
return
true
;
}
else
{
int
startPos
=
qMax
(
0
,
parseError
.
offset
-
100
);
int
length
=
qMin
(
bytes
.
count
()
-
startPos
,
200
);
qDebug
()
<<
QStringLiteral
(
"Json read error '%1'"
).
arg
(
bytes
.
mid
(
startPos
,
length
).
constData
());
errorString
=
parseError
.
errorString
();
return
false
;
}
}
bool
JsonHelper
::
isJsonFile
(
const
QString
&
fileName
,
QJsonDocument
&
jsonDoc
,
QString
&
errorString
)
{
QFile
jsonFile
(
fileName
);
if
(
!
jsonFile
.
open
(
QFile
::
ReadOnly
))
{
errorString
=
tr
(
"File open failed: file:error %1 %2"
).
arg
(
jsonFile
.
fileName
()).
arg
(
jsonFile
.
errorString
());
return
false
;
}
QByteArray
jsonBytes
=
jsonFile
.
readAll
();
jsonFile
.
close
();
return
isJsonFile
(
jsonBytes
,
jsonDoc
,
errorString
);
}
bool
JsonHelper
::
validateInternalQGCJsonFile
(
const
QJsonObject
&
jsonObject
,
const
QString
&
expectedFileType
,
int
minSupportedVersion
,
...
...
src/JsonHelper.h
View file @
cc0080b0
...
...
@@ -26,6 +26,12 @@ class JsonHelper
Q_DECLARE_TR_FUNCTIONS
(
JsonHelper
)
public:
/// Determines is the specified file is a json file
/// @return true: file is json, false: file is not json
static
bool
isJsonFile
(
const
QString
&
fileName
,
///< filename
QJsonDocument
&
jsonDoc
,
///< returned json document
QString
&
errorString
);
///< error on parse failure
/// Determines is the specified data is a json file
/// @return true: file is json, false: file is not json
static
bool
isJsonFile
(
const
QByteArray
&
bytes
,
///< json bytes
...
...
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