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 "GeoDataOverlay.h"
9#include "GeoDataTimeStamp.h"
10#include "GeoDataTimeSpan.h"
11#include "GeoDataDocument.h"
12#include "GeoDataStyle.h"
13#include "GeoDataStyleMap.h"
14#include "GeoDataExtendedData.h"
15#include "GeoDataLookAt.h"
16#include "GeoDataPlacemark.h"
17#include "GeoDataCamera.h"
18#include "GeoWriter.h"
19#include "GeoDataRegion.h"
20#include "GeoDataLatLonAltBox.h"
21#include "KmlElementDictionary.h"
22#include "KmlObjectTagWriter.h"
23#include "KmlOsmPlacemarkDataTagWriter.h"
24#include "OsmPlacemarkData.h"
25
26#include <QDateTime>
27
28namespace Marble
29{
30
31KmlFeatureTagWriter::KmlFeatureTagWriter(const QString &elementName)
32 : m_elementName( elementName )
33{
34 // nothing to do
35}
36
37bool KmlFeatureTagWriter::write( const Marble::GeoNode *node, GeoWriter &writer ) const
38{
39 const GeoDataFeature *feature = static_cast<const GeoDataFeature*>(node);
40
41 if (const GeoDataDocument *document = geodata_cast<GeoDataDocument>(feature)) {
42 // when a document has only one feature and no styling
43 // the document tag is excused
44 if( (document->id().isEmpty())
45 && (document->name().isEmpty())
46 && (document->targetId().isEmpty())
47 && (document->styles().count() == 0)
48 && (document->styleMaps().count() == 0)
49 && (document->extendedData().isEmpty())
50 && (document->featureList().count() == 1) ) {
51 writeElement( document->featureList()[0], writer );
52 return true;
53 }
54 }
55
56 writer.writeStartElement( m_elementName );
57
58 KmlObjectTagWriter::writeIdentifiers( writer, feature );
59
60 writer.writeOptionalElement( kml::kmlTag_name, feature->name() );
61 writer.writeOptionalElement( kml::kmlTag_visibility, QString::number( feature->isVisible() ), "1" );
62 writer.writeOptionalElement( "address", feature->address() );
63
64 if( !feature->description().isEmpty() ) {
65 writer.writeStartElement( "description" );
66 if( feature->descriptionIsCDATA() ) {
67 writer.writeCDATA( feature->description() );
68 } else {
69 writer.writeCharacters( feature->description() );
70 }
71 writer.writeEndElement();
72 }
73
74 GeoDataLookAt const * lookAt = dynamic_cast<const GeoDataLookAt*>( feature->abstractView() );
75 if ( lookAt ) {
76 writeElement( lookAt, writer );
77 }
78 GeoDataCamera const * camera = dynamic_cast<const GeoDataCamera*>( feature->abstractView() );
79 if ( camera ) {
80 writeElement( camera, writer );
81 }
82
83 if( feature->timeStamp().when().isValid() ) {
84 writeElement( &feature->timeStamp(), writer );
85 }
86
87 if( feature->timeSpan().isValid() ) {
88 writeElement( &feature->timeSpan(), writer );
89 }
90
91 if ( !feature->region().latLonAltBox().isNull() ) {
92 writeElement( &feature->region(), writer );
93 }
94
95 bool const result = writeMid( node, writer );
96
97 if (geodata_cast<GeoDataPlacemark>(feature)) {
98 KmlOsmPlacemarkDataTagWriter::write(feature, writer);
99 }
100
101 if( !feature->extendedData().isEmpty() ) {
102 writeElement( &feature->extendedData(), writer );
103 }
104
105 writer.writeEndElement();
106 return result;
107}
108
109}
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 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 Jun 7 2024 12:03:13 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.