Marble

GeoWriter.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2009 Andrew Manson <g.real.ate@gmail.com>
4//
5
6#ifndef MARBLE_GEOWRITER_H
7#define MARBLE_GEOWRITER_H
8
9#include "marble_export.h"
10
11#include <QVariant>
12#include <QXmlStreamWriter>
13
14namespace Marble
15{
16
17class GeoNode;
18
19/**
20 * @brief Standard Marble way of writing XML
21 * This class is intended to be a standardised way of writing XML for marble.
22 * It works with the GeoData classes and writes XML based on the type of output
23 * format that the writer is currently working with.
24 */
25class MARBLE_EXPORT GeoWriter : public QXmlStreamWriter
26{
27public:
28 GeoWriter();
29
30 /**
31 * @brief The main API call to use the XML writer.
32 * To use the XML writer you need to provide an IODevice to write the XML to
33 * and a QList of GeoDataFeatures which contains the data you wish to write.
34 * To define the type of XML document that is to be written you need to set
35 * the current Document Type for this GeoWriter. See @see setDocumentType()
36 */
37 bool write(QIODevice *device, const GeoNode *feature);
38
39 /**
40 * @brief Set the current document type.
41 * The current Document Type defines which set of handlers are to be used
42 * when writing the GeoDocument. This string should correspond with the
43 * string used to register the required Tag Writers in @see GeoTagWriter
44 */
45 void setDocumentType(const QString &documentType);
46
47 /**
48 * @brief Convenience method to write <key>value</key> with key prefixed format
49 * @p namespaceUri
50 */
51 void writeElement(const QString &namespaceUri, const QString &key, const QString &value);
52
53 /**
54 * @brief Convenience method to write <key>value</key>
55 *
56 **/
57 void writeElement(const QString &key, const QString &value);
58
59 /**
60 * @brief Convenience method to write <key>value</key> if value is
61 * not equal to defaultValue. Otherwise, nothing is written.
62 *
63 **/
64 void writeOptionalElement(const QString &key, const QString &value, const QString &defaultValue = QString());
65
66 /**
67 * @brief writeOptionalAttribute Convenience method to write k=v attributes
68 * if value is not equal to defaultValue
69 */
70 void writeOptionalAttribute(const QString &key, const QString &value, const QString &defaultValue = QString());
71
72 template<class T>
73 void writeOptionalElement(const QString &key, const T &value, const T &defaultValue = T())
74 {
75 if (value != defaultValue) {
76 writeElement(key, QVariant::fromValue(value).toString());
77 }
78 }
79
80private:
81 friend class GeoTagWriter;
82 friend class GeoDataDocumentWriter;
83 bool writeElement(const GeoNode *object);
84
85private:
86 QString m_documentType;
87};
88
89}
90
91#endif
Write GeoDataDocument content to I/O devices (e.g.
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
Base class intended to be subclassed by specific XML tag writers This class provides a base class tha...
Standard Marble way of writing XML This class is intended to be a standardised way of writing XML for...
Definition GeoWriter.h:26
Binds a QML item to a specific geodetic location in screen coordinates.
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.