Marble

GeoDataParser.cpp
1/*
2 SPDX-FileCopyrightText: 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7// Own
8#include "GeoDataParser.h"
9
10#include <QStringView>
11
12// Marble
13#include "MarbleDebug.h"
14
15// Geodata
16#include "GeoDataDocument.h"
17#include "GeoDocument.h"
18
19// TODO: GeoRSS support
20// #include "GeoRSSElementDictionary.h"
21
22// KML support
23#include "KmlElementDictionary.h"
24
25namespace Marble
26{
27
28GeoDataParser::GeoDataParser(GeoDataSourceType source)
29 : GeoParser(source)
30{
31}
32
33GeoDataParser::~GeoDataParser() = default;
34
35bool GeoDataParser::isValidRootElement()
36{
37 if (m_source == GeoData_UNKNOWN) {
38 if (GeoParser::isValidElement(QString::fromLatin1(kml::kmlTag_kml))) {
39 m_source = GeoData_KML;
40 } else {
41 Q_ASSERT(false);
42 return false;
43 }
44 }
45 switch ((GeoDataSourceType)m_source) {
46 // TODO: case GeoData_GeoRSS:
47 case GeoData_KML:
48 return isValidElement(QString::fromLatin1(kml::kmlTag_kml));
49 default:
50 Q_ASSERT(false);
51 return false;
52 }
53}
54
55bool GeoDataParser::isValidElement(const QString &tagName) const
56{
57 if (!GeoParser::isValidElement(tagName))
58 return false;
59
60 switch ((GeoDataSourceType)m_source) {
61 // TODO: case GeoData_GeoRSS:
62 case GeoData_KML: {
63 const QStringView namespaceUri = this->namespaceUri();
64 return (namespaceUri == QLatin1StringView(kml::kmlTag_nameSpace20) || namespaceUri == QLatin1StringView(kml::kmlTag_nameSpace21)
65 || namespaceUri == QLatin1StringView(kml::kmlTag_nameSpace22) || namespaceUri == QLatin1StringView(kml::kmlTag_nameSpaceOgc22)
66 || namespaceUri == QLatin1StringView(kml::kmlTag_nameSpaceGx22) || namespaceUri == QLatin1StringView(kml::kmlTag_nameSpaceMx));
67 }
68 default:
69 break;
70 }
71
72 // Should never be reached.
73 Q_ASSERT(false);
74 return false;
75}
76
77GeoDocument *GeoDataParser::createDocument() const
78{
79 return new GeoDataDocument;
80}
81
82// Global helper function for the tag handlers
83GeoDataDocument *geoDataDoc(GeoParser &parser)
84{
85 GeoDocument *document = parser.activeDocument();
86 Q_ASSERT(document->isGeoDataDocument());
87 return static_cast<GeoDataDocument *>(document);
88}
89
90}
Binds a QML item to a specific geodetic location in screen coordinates.
QString fromLatin1(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.