File indexing completed on 2024-05-12 03:51:44

0001 /*
0002     SPDX-FileCopyrightText: 2009 Thibaut GRIDEL <tgridel@free.fr>
0003     SPDX-License-Identifier: LGPL-2.1-or-later
0004 */
0005 
0006 #include "GPXtrkptTagHandler.h"
0007 
0008 #include "MarbleDebug.h"
0009 
0010 #include "GPXElementDictionary.h"
0011 #include "GeoParser.h"
0012 #include "GeoDataLineString.h"
0013 #include "GeoDataCoordinates.h"
0014 #include "GeoDataTrack.h"
0015 
0016 namespace Marble
0017 {
0018 namespace gpx
0019 {
0020 GPX_DEFINE_TAG_HANDLER(trkpt)
0021 
0022 GeoNode* GPXtrkptTagHandler::parse(GeoParser& parser) const
0023 {
0024     Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1String(gpxTag_trkpt)));
0025 
0026     GeoStackItem parentItem = parser.parentElement();
0027     if (parentItem.represents(gpxTag_trkseg))
0028     {
0029         GeoDataTrack* track = parentItem.nodeAs<GeoDataTrack>();
0030         GeoDataCoordinates coord;
0031 
0032         QXmlStreamAttributes attributes = parser.attributes();
0033         QStringRef tmp;
0034         qreal lat = 0;
0035         qreal lon = 0;
0036         tmp = attributes.value(QLatin1String(gpxTag_lat));
0037         if ( !tmp.isEmpty() )
0038         {
0039             lat = tmp.toString().toDouble();
0040         }
0041         tmp = attributes.value(QLatin1String(gpxTag_lon));
0042         if ( !tmp.isEmpty() )
0043         {
0044             lon = tmp.toString().toDouble();
0045         }
0046         coord.set(lon, lat, 0, GeoDataCoordinates::Degree);
0047         track->appendCoordinates( coord );
0048 
0049         return track;
0050     }
0051     return nullptr;
0052 }
0053 
0054 } // namespace gpx
0055 
0056 } // namespace Marble