Marble

GeoWriter.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2009 Andrew Manson <[email protected]>
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 
15 namespace Marble
16 {
17 
18 GeoWriter::GeoWriter()
19 {
20  //FIXME: work out a standard way to do this.
21  m_documentType = kml::kmlTag_nameSpaceOgc22;
22 }
23 
24 bool GeoWriter::write(QIODevice* device, const GeoNode *feature)
25 {
26  setDevice( device );
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 
52 bool 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 
73 void GeoWriter::setDocumentType( const QString &documentType )
74 {
75  m_documentType = documentType;
76 }
77 
78 void GeoWriter::writeElement( const QString &namespaceUri, const QString &key, const QString &value )
79 {
80  writeStartElement( namespaceUri, key );
81  writeCharacters( value );
83 }
84 
85 void GeoWriter::writeElement( const QString &key, const QString &value )
86 {
87  writeStartElement( key );
88  writeCharacters( value );
90 }
91 
92 void GeoWriter::writeOptionalElement( const QString &key, const QString &value, const QString &defaultValue )
93 {
94  if( value != defaultValue ) {
95  writeElement( key, value );
96  }
97 }
98 
99 void GeoWriter::writeOptionalAttribute( const QString &key, const QString &value, const QString &defaultValue )
100 {
101  if( value != defaultValue ) {
102  writeAttribute( key, value );
103  }
104 }
105 
106 }
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
virtual const char * nodeType() const =0
Provides type information for downcasting a GeoNode.
void writeEndElement()
void writeStartDocument()
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 setDocumentType(const QString &documentType)
Set the current document type.
Definition: GeoWriter.cpp:73
Base class intended to be subclassed by specific XML tag writers This class provides a base class tha...
Definition: GeoTagWriter.h:27
A shared base class for all classes that are mapped to a specific tag (ie.
Definition: GeoDocument.h:34
QIODevice * device() const const
bool write(QIODevice *device, const GeoNode *feature)
The main API call to use the XML writer.
Definition: GeoWriter.cpp:24
Binds a QML item to a specific geodetic location in screen coordinates.
void setDevice(QIODevice *device)
const char * name(StandardAction id)
void setAutoFormatting(bool enable)
void writeAttribute(const QString &qualifiedName, const QString &value)
void writeCharacters(const QString &text)
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 writeStartElement(const QString &qualifiedName)
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.