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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Anders Lund <anders@alweb.dk>
0004 //
0005 
0006 #include "GPXlinkTagHandler.h"
0007 
0008 #include "MarbleDebug.h"
0009 
0010 #include "GPXElementDictionary.h"
0011 #include "GeoParser.h"
0012 #include "GeoDataPlacemark.h"
0013 #include "GeoDataData.h"
0014 #include "GeoDataExtendedData.h"
0015 
0016 namespace Marble
0017 {
0018 namespace gpx
0019 {
0020 GPX_DEFINE_TAG_HANDLER_11(link)
0021 
0022 // Gpx link provides a linke related to the object, and is inserted into the
0023 // waypoint description as this seems to be the simplest means to make it
0024 // available to the user.
0025 // In addition, link properties are saved to extendedData.
0026 // there are text and type properties, type being ignored for now.
0027 GeoNode* GPXlinkTagHandler::parse(GeoParser& parser) const
0028 {
0029     Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1String(gpxTag_link)));
0030 
0031     GeoStackItem parentItem = parser.parentElement();
0032     if (parentItem.represents(gpxTag_wpt))
0033     {
0034         GeoDataPlacemark* placemark = parentItem.nodeAs<GeoDataPlacemark>();
0035 
0036         QXmlStreamAttributes attributes = parser.attributes();
0037         QString href = attributes.value(QLatin1String("href")).toString();
0038         QString text = href;
0039         if (parser.readNextStartElement())
0040         {
0041             text = parser.readElementText();
0042         }
0043 
0044         const QString link = QStringLiteral("Link: <a href=\"%1\">%2</a>")
0045             .arg(href).arg(text);
0046 
0047         QString desc = placemark->description();
0048         if (!desc.isEmpty())
0049         {
0050             desc += QLatin1String("<br/>");
0051         }
0052 
0053         placemark->setDescription(desc.append(link));
0054         placemark->setDescriptionCDATA(true);
0055     }
0056 
0057     return nullptr;
0058 }
0059 
0060 } // namespace gpx
0061 
0062 } // namespace Marble