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
12#include "MarbleDebug.h"
13
14namespace Marble
15{
16
17GeoWriter::GeoWriter()
18{
19 // FIXME: work out a standard way to do this.
20 m_documentType = QString::fromLatin1(kml::kmlTag_nameSpaceOgc22);
21}
22
23bool GeoWriter::write(QIODevice *device, const GeoNode *feature)
24{
28
29 // FIXME: write the starting tags. Possibly register a tag handler to do this
30 // with a null string as the object name?
31
32 GeoTagWriter::QualifiedName name({}, m_documentType);
33 const GeoTagWriter *writer = GeoTagWriter::recognizes(name);
34 if (writer) {
35 // FIXME is this too much of a hack?
36 writer->write(/* node = */ nullptr, *this); // node is never used in write()
37 } else {
38 mDebug() << "There is no GeoWriter registered for: " << name;
39 return false;
40 }
41
42 if (!writeElement(feature)) {
43 return false;
44 }
45
46 // close the document
48 return true;
49}
50
51bool GeoWriter::writeElement(const GeoNode *object)
52{
53 // Add checks to see that everything is ok here
54
55 GeoTagWriter::QualifiedName name(QString::fromLatin1(object->nodeType()), m_documentType);
56 const GeoTagWriter *writer = GeoTagWriter::recognizes(name);
57
58 if (writer) {
59 if (!writer->write(object, *this)) {
60 mDebug() << "An error has been reported by the GeoWriter for: " << name;
61 return false;
62 }
63 } else {
64 mDebug() << "There is no GeoWriter registered for: " << name;
65 return true;
66 }
67 return true;
68}
69
70void GeoWriter::setDocumentType(const QString &documentType)
71{
72 m_documentType = documentType;
73}
74
75void GeoWriter::writeElement(const QString &namespaceUri, const QString &key, const QString &value)
76{
77 writeStartElement(namespaceUri, key);
78 writeCharacters(value);
80}
81
82void GeoWriter::writeElement(const QString &key, const QString &value)
83{
85 writeCharacters(value);
87}
88
89void GeoWriter::writeOptionalElement(const QString &key, const QString &value, const QString &defaultValue)
90{
91 if (value != defaultValue) {
92 writeElement(key, value);
93 }
94}
95
96void GeoWriter::writeOptionalAttribute(const QString &key, const QString &value, const QString &defaultValue)
97{
98 if (value != defaultValue) {
99 writeAttribute(key, value);
100 }
101}
102
103}
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:70
bool write(QIODevice *device, const GeoNode *feature)
The main API call to use the XML writer.
Definition GeoWriter.cpp:23
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:89
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:96
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:75
QString name(GameStandardAction id)
Binds a QML item to a specific geodetic location in screen coordinates.
QString fromLatin1(QByteArrayView str)
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 Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.