Marble

KmlFeatureTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2013 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#include "KmlFeatureTagWriter.h"
7
8#include "GeoDataCamera.h"
9#include "GeoDataDocument.h"
10#include "GeoDataExtendedData.h"
11#include "GeoDataLatLonAltBox.h"
12#include "GeoDataLookAt.h"
13#include "GeoDataPlacemark.h"
14#include "GeoDataRegion.h"
15#include "GeoDataStyle.h"
16#include "GeoDataStyleMap.h"
17#include "GeoDataTimeSpan.h"
18#include "GeoDataTimeStamp.h"
19#include "GeoWriter.h"
20#include "KmlElementDictionary.h"
21#include "KmlObjectTagWriter.h"
22#include "KmlOsmPlacemarkDataTagWriter.h"
23#include "OsmPlacemarkData.h"
24
25#include <QDateTime>
26
27namespace Marble
28{
29
30KmlFeatureTagWriter::KmlFeatureTagWriter(const QString &elementName)
31 : m_elementName(elementName)
32{
33 // nothing to do
34}
35
36bool KmlFeatureTagWriter::write(const Marble::GeoNode *node, GeoWriter &writer) const
37{
38 const auto feature = static_cast<const GeoDataFeature *>(node);
39
40 if (const auto document = geodata_cast<GeoDataDocument>(feature)) {
41 // when a document has only one feature and no styling
42 // the document tag is excused
43 if ((document->id().isEmpty()) && (document->name().isEmpty()) && (document->targetId().isEmpty()) && (document->styles().isEmpty())
44 && (document->styleMaps().isEmpty()) && (document->extendedData().isEmpty()) && (document->featureList().count() == 1)) {
45 writeElement(document->featureList().constFirst(), writer);
46 return true;
47 }
48 }
49
50 writer.writeStartElement(m_elementName);
51
52 KmlObjectTagWriter::writeIdentifiers(writer, feature);
53
54 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_name), feature->name());
55 writer.writeOptionalElement(QString::fromLatin1(kml::kmlTag_visibility), QString::number(feature->isVisible()), QStringLiteral("1"));
56 writer.writeOptionalElement(QStringLiteral("address"), feature->address());
57
58 if (!feature->description().isEmpty()) {
59 writer.writeStartElement("description");
60 if (feature->descriptionIsCDATA()) {
61 writer.writeCDATA(feature->description());
62 } else {
63 writer.writeCharacters(feature->description());
64 }
65 writer.writeEndElement();
66 }
67
68 auto const *lookAt = dynamic_cast<const GeoDataLookAt *>(feature->abstractView());
69 if (lookAt) {
70 writeElement(lookAt, writer);
71 }
72 auto const *camera = dynamic_cast<const GeoDataCamera *>(feature->abstractView());
73 if (camera) {
74 writeElement(camera, writer);
75 }
76
77 if (feature->timeStamp().when().isValid()) {
78 writeElement(&feature->timeStamp(), writer);
79 }
80
81 if (feature->timeSpan().isValid()) {
82 writeElement(&feature->timeSpan(), writer);
83 }
84
85 if (!feature->region().latLonAltBox().isNull()) {
86 writeElement(&feature->region(), writer);
87 }
88
89 bool const result = writeMid(node, writer);
90
91 if (geodata_cast<GeoDataPlacemark>(feature)) {
92 KmlOsmPlacemarkDataTagWriter::write(feature, writer);
93 }
94
95 if (!feature->extendedData().isEmpty()) {
96 writeElement(&feature->extendedData(), writer);
97 }
98
99 writer.writeEndElement();
100 return result;
101}
102
103}
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
Q_SCRIPTABLE QString camera()
Binds a QML item to a specific geodetic location in screen coordinates.
QString fromLatin1(QByteArrayView str)
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.