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
7bbadf68
Unverified
Commit
7bbadf68
authored
Nov 07, 2018
by
Don Gagne
Committed by
GitHub
Nov 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6987 from DonLakeFlyer/KMLLoad
KML: Better file load error messages
parents
c5396510
c99cdb2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
KMLFileHelper.cc
src/KMLFileHelper.cc
+10
-8
KMLFileHelper.h
src/KMLFileHelper.h
+3
-0
No files found.
src/KMLFileHelper.cc
View file @
7bbadf68
...
...
@@ -11,6 +11,8 @@
#include <QFile>
const
char
*
KMLFileHelper
::
_errorPrefix
=
QT_TR_NOOP
(
"KML file load failed. %1"
);
QDomDocument
KMLFileHelper
::
loadFile
(
const
QString
&
kmlFile
,
QString
&
errorString
)
{
QFile
file
(
kmlFile
);
...
...
@@ -18,12 +20,12 @@ QDomDocument KMLFileHelper::loadFile(const QString& kmlFile, QString& errorStrin
errorString
.
clear
();
if
(
!
file
.
exists
())
{
errorString
=
tr
(
"File not found: %1"
).
arg
(
kmlFile
);
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"File not found: %1"
).
arg
(
kmlFile
)
);
return
QDomDocument
();
}
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
))
{
errorString
=
tr
(
"Unable to open file: %1 error: $%2"
).
arg
(
kmlFile
).
arg
(
file
.
errorString
(
));
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"Unable to open file: %1 error: $%2"
).
arg
(
kmlFile
).
arg
(
file
.
errorString
()
));
return
QDomDocument
();
}
...
...
@@ -31,7 +33,7 @@ QDomDocument KMLFileHelper::loadFile(const QString& kmlFile, QString& errorStrin
QString
errorMessage
;
int
errorLine
;
if
(
!
doc
.
setContent
(
&
file
,
&
errorMessage
,
&
errorLine
))
{
errorString
=
tr
(
"Unable to parse KML file: %1 error: %2 line: %3"
).
arg
(
kmlFile
).
arg
(
errorMessage
).
arg
(
errorLine
);
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"Unable to parse KML file: %1 error: %2 line: %3"
).
arg
(
kmlFile
).
arg
(
errorMessage
).
arg
(
errorLine
)
);
return
QDomDocument
();
}
...
...
@@ -67,7 +69,7 @@ KMLFileHelper::KMLFileContents KMLFileHelper::determineFileContents(const QStrin
return
Polyline
;
}
errorString
=
tr
(
"No known type found in KML file."
);
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"No supported type found in KML file."
)
);
return
Error
;
}
...
...
@@ -83,13 +85,13 @@ bool KMLFileHelper::loadPolygonFromFile(const QString& kmlFile, QList<QGeoCoordi
QDomNodeList
rgNodes
=
domDocument
.
elementsByTagName
(
"Polygon"
);
if
(
rgNodes
.
count
()
==
0
)
{
errorString
=
tr
(
"Unable to find Polygon node in KML"
);
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"Unable to find Polygon node in KML"
)
);
return
false
;
}
QDomNode
coordinatesNode
=
rgNodes
.
item
(
0
).
namedItem
(
"outerBoundaryIs"
).
namedItem
(
"LinearRing"
).
namedItem
(
"coordinates"
);
if
(
coordinatesNode
.
isNull
())
{
errorString
=
tr
(
"Internal error: Unable to find coordinates node in KML"
);
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"Internal error: Unable to find coordinates node in KML"
)
);
return
false
;
}
...
...
@@ -144,13 +146,13 @@ bool KMLFileHelper::loadPolylineFromFile(const QString& kmlFile, QList<QGeoCoord
QDomNodeList
rgNodes
=
domDocument
.
elementsByTagName
(
"LineString"
);
if
(
rgNodes
.
count
()
==
0
)
{
errorString
=
tr
(
"Unable to find LineString node in KML"
);
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"Unable to find LineString node in KML"
)
);
return
false
;
}
QDomNode
coordinatesNode
=
rgNodes
.
item
(
0
).
namedItem
(
"coordinates"
);
if
(
coordinatesNode
.
isNull
())
{
errorString
=
tr
(
"Internal error: Unable to find coordinates node in KML"
);
errorString
=
QString
(
_errorPrefix
).
arg
(
tr
(
"Internal error: Unable to find coordinates node in KML"
)
);
return
false
;
}
...
...
src/KMLFileHelper.h
View file @
7bbadf68
...
...
@@ -34,4 +34,7 @@ public:
static
QDomDocument
loadFile
(
const
QString
&
kmlFile
,
QString
&
errorString
);
static
bool
loadPolygonFromFile
(
const
QString
&
kmlFile
,
QList
<
QGeoCoordinate
>&
vertices
,
QString
&
errorString
);
static
bool
loadPolylineFromFile
(
const
QString
&
kmlFile
,
QList
<
QGeoCoordinate
>&
coords
,
QString
&
errorString
);
private:
static
const
char
*
_errorPrefix
;
};
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