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 "GPXwptTagHandler.h" 0007 0008 #include "MarbleDebug.h" 0009 0010 #include "GPXElementDictionary.h" 0011 #include "GeoParser.h" 0012 #include "GeoDataDocument.h" 0013 #include "GeoDataPlacemark.h" 0014 #include "GeoDataPoint.h" 0015 0016 namespace Marble 0017 { 0018 namespace gpx 0019 { 0020 GPX_DEFINE_TAG_HANDLER(wpt) 0021 0022 GeoNode* GPXwptTagHandler::parse(GeoParser& parser) const 0023 { 0024 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1String(gpxTag_wpt))); 0025 0026 GeoStackItem parentItem = parser.parentElement(); 0027 if (parentItem.represents(gpxTag_gpx)) 0028 { 0029 GeoDataDocument* doc = parentItem.nodeAs<GeoDataDocument>(); 0030 GeoDataPlacemark *placemark = new GeoDataPlacemark; 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().toFloat(); 0040 } 0041 tmp = attributes.value(QLatin1String(gpxTag_lon)); 0042 if ( !tmp.isEmpty() ) 0043 { 0044 lon = tmp.toString().toFloat(); 0045 } 0046 placemark->setCoordinate( lon, lat, 0, GeoDataCoordinates::Degree ); 0047 placemark->setRole(QStringLiteral("Waypoint")); 0048 0049 placemark->setStyle(doc->style(QStringLiteral("waypoint"))); 0050 0051 doc->append(placemark); 0052 return placemark; 0053 } 0054 return nullptr; 0055 } 0056 0057 } // namespace gpx 0058 0059 } // namespace Marble