Marble

GeoWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2009 Andrew Manson <g.real.ate@gmail.com>
4//
5
6#include "GeoWriter.h"
7
8#include "GeoDocument.h"
9#include "GeoTagWriter.h"
10#include "KmlElementDictionary.h"
11#include "DgmlElementDictionary.h"
12
13#include "MarbleDebug.h"
14
15namespace Marble
16{
17
18GeoWriter::GeoWriter()
19{
20 //FIXME: work out a standard way to do this.
21 m_documentType = kml::kmlTag_nameSpaceOgc22;
22}
23
24bool GeoWriter::write(QIODevice* device, const GeoNode *feature)
25{
27 setAutoFormatting( true );
29
30 //FIXME: write the starting tags. Possibly register a tag handler to do this
31 // with a null string as the object name?
32
33 GeoTagWriter::QualifiedName name( "", m_documentType );
34 const GeoTagWriter* writer = GeoTagWriter::recognizes(name);
35 if( writer ) {
36 //FIXME is this too much of a hack?
37 writer->write(/* node = */ nullptr, *this); // node is never used in write()
38 } else {
39 mDebug() << "There is no GeoWriter registered for: " << name;
40 return false;
41 }
42
43 if( ! writeElement( feature ) ) {
44 return false;
45 }
46
47 //close the document
49 return true;
50}
51
52bool GeoWriter::writeElement(const GeoNode *object)
53{
54 // Add checks to see that everything is ok here
55
56 GeoTagWriter::QualifiedName name( object->nodeType(), m_documentType );
57 const GeoTagWriter* writer = GeoTagWriter::recognizes( name );
58
59 if( writer ) {
60 if( ! writer->write( object, *this ) ) {
61 mDebug() << "An error has been reported by the GeoWriter for: "
62 << name;
63 return false;
64 }
65 } else {
66 mDebug() << "There is no GeoWriter registered for: " << name;
67 return true;
68 }
69 return true;
70}
71
72
73void GeoWriter::setDocumentType( const QString &documentType )
74{
75 m_documentType = documentType;
76}
77
78void GeoWriter::writeElement( const QString &namespaceUri, const QString &key, const QString &value )
79{
80 writeStartElement( namespaceUri, key );
81 writeCharacters( value );
83}
84
85void GeoWriter::writeElement( const QString &key, const QString &value )
86{
87 writeStartElement( key );
88 writeCharacters( value );
90}
91
92void GeoWriter::writeOptionalElement( const QString &key, const QString &value, const QString &defaultValue )
93{
94 if( value != defaultValue ) {
95 writeElement( key, value );
96 }
97}
98
99void GeoWriter::writeOptionalAttribute( const QString &key, const QString &value, const QString &defaultValue )
100{
101 if( value != defaultValue ) {
102 writeAttribute( key, value );
103 }
104}
105
106}
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
virtual const char * nodeType() const =0
Provides type information for downcasting a GeoNode.
Base class intended to be subclassed by specific XML tag writers This class provides a base class tha...
QPair< QString, QString > QualifiedName
Object Name and Namespace Pair This type is intended to be used in a similar way to.
void setDocumentType(const QString &documentType)
Set the current document type.
Definition GeoWriter.cpp:73
bool write(QIODevice *device, const GeoNode *feature)
The main API call to use the XML writer.
Definition GeoWriter.cpp:24
void writeOptionalElement(const QString &key, const QString &value, const QString &defaultValue=QString())
Convenience method to write <key>value</key> if value is not equal to defaultValue.
Definition GeoWriter.cpp:92
void writeOptionalAttribute(const QString &key, const QString &value, const QString &defaultValue=QString())
writeOptionalAttribute Convenience method to write k=v attributes if value is not equal to defaultVal...
Definition GeoWriter.cpp:99
void writeElement(const QString &namespaceUri, const QString &key, const QString &value)
Convenience method to write <key>value</key> with key prefixed format namespaceUri.
Definition GeoWriter.cpp:78
QString name(StandardShortcut id)
Binds a QML item to a specific geodetic location in screen coordinates.
QIODevice * device() const const
void setAutoFormatting(bool enable)
void setDevice(QIODevice *device)
void writeAttribute(QAnyStringView namespaceUri, QAnyStringView name, QAnyStringView value)
void writeCharacters(QAnyStringView text)
void writeEndElement()
void writeStartDocument()
void writeStartElement(QAnyStringView namespaceUri, QAnyStringView name)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.