From 57a171ee8c7c21c97faae76695f7c7fdacb9adb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 11 Oct 2017 22:41:01 +0200 Subject: [PATCH] Fixed broaken loading of KML files with multitracks and folder element outside document element --- src/kmlparser.cpp | 18 ++++++++++++++++++ src/kmlparser.h | 1 + 2 files changed, 19 insertions(+) diff --git a/src/kmlparser.cpp b/src/kmlparser.cpp index bca65464..c28def54 100644 --- a/src/kmlparser.cpp +++ b/src/kmlparser.cpp @@ -251,6 +251,16 @@ void KMLParser::track(TrackData &track) _reader.raiseError(mismatchError); } +void KMLParser::multiTrack(TrackData &t) +{ + while (_reader.readNextStartElement()) { + if (_reader.name() == "Track") + track(t); + else + _reader.skipCurrentElement(); + } +} + void KMLParser::multiGeometry(QList &tracks, QList &waypoints, const QString &name, const QString &desc, const QDateTime timestamp) @@ -308,6 +318,12 @@ void KMLParser::placemark(QList &tracks, QList &waypoints) t.setName(name); t.setDescription(desc); track(t); + } else if (_reader.name() == "MultiTrack") { + tracks.append(TrackData()); + TrackData &t = tracks.last(); + t.setName(name); + t.setDescription(desc); + multiTrack(t); } else _reader.skipCurrentElement(); } @@ -344,6 +360,8 @@ void KMLParser::kml(QList &tracks, QList &waypoints) document(tracks, waypoints); else if (_reader.name() == "Placemark") placemark(tracks, waypoints); + else if (_reader.name() == "Folder") + folder(tracks, waypoints); else _reader.skipCurrentElement(); } diff --git a/src/kmlparser.h b/src/kmlparser.h index 54aa4062..de197aba 100644 --- a/src/kmlparser.h +++ b/src/kmlparser.h @@ -23,6 +23,7 @@ private: void multiGeometry(QList &tracks, QList &waypoints, const QString &name, const QString &desc, const QDateTime timestamp); void track(TrackData &track); + void multiTrack(TrackData &t); void lineString(TrackData &track); void point(Waypoint &waypoint); bool pointCoordinates(Waypoint &waypoint);