|
|
|
@ -12,6 +12,8 @@
@@ -12,6 +12,8 @@
|
|
|
|
|
#include <QFile> |
|
|
|
|
#include <QVariant> |
|
|
|
|
|
|
|
|
|
const char* KMLFileHelper::_errorPrefix = QT_TR_NOOP("KML file load failed. %1"); |
|
|
|
|
|
|
|
|
|
QDomDocument KMLFileHelper::loadFile(const QString& kmlFile, QString& errorString) |
|
|
|
|
{ |
|
|
|
|
QFile file(kmlFile); |
|
|
|
@ -19,12 +21,12 @@ QDomDocument KMLFileHelper::loadFile(const QString& kmlFile, QString& errorStrin
@@ -19,12 +21,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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -32,7 +34,7 @@ QDomDocument KMLFileHelper::loadFile(const QString& kmlFile, QString& errorStrin
@@ -32,7 +34,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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -68,7 +70,7 @@ KMLFileHelper::KMLFileContents KMLFileHelper::determineFileContents(const QStrin
@@ -68,7 +70,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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -84,13 +86,13 @@ bool KMLFileHelper::loadPolygonFromFile(const QString& kmlFile, QList<QGeoCoordi
@@ -84,13 +86,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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -145,13 +147,13 @@ bool KMLFileHelper::loadPolylineFromFile(const QString& kmlFile, QList<QGeoCoord
@@ -145,13 +147,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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|