File indexing completed on 2025-01-05 03:59:12
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2009 Andrew Manson <g.real.ate@gmail.com> 0004 // 0005 0006 #ifndef MARBLE_GEOWRITER_H 0007 #define MARBLE_GEOWRITER_H 0008 0009 #include "digikam_export.h" 0010 0011 #include <QXmlStreamWriter> 0012 #include <QVariant> 0013 0014 namespace Marble 0015 { 0016 0017 class GeoNode; 0018 0019 /** 0020 * @brief Standard Marble way of writing XML 0021 * This class is intended to be a standardised way of writing XML for marble. 0022 * It works with the GeoData classes and writes XML based on the type of output 0023 * format that the writer is currently working with. 0024 */ 0025 class DIGIKAM_EXPORT GeoWriter : public QXmlStreamWriter 0026 { 0027 public: 0028 GeoWriter(); 0029 0030 /** 0031 * @brief The main API call to use the XML writer. 0032 * To use the XML writer you need to provide an IODevice to write the XML to 0033 * and a QList of GeoDataFeatures which contains the data you wish to write. 0034 * To define the type of XML document that is to be written you need to set 0035 * the current Document Type for this GeoWriter. See @see setDocumentType() 0036 */ 0037 bool write( QIODevice* device, const GeoNode *feature); 0038 0039 /** 0040 * @brief Set the current document type. 0041 * The current Document Type defines which set of handlers are to be used 0042 * when writing the GeoDocument. This string should correspond with the 0043 * string used to register the required Tag Writers in @see GeoTagWriter 0044 */ 0045 void setDocumentType( const QString& documentType ); 0046 0047 /** 0048 * @brief Convenience method to write \<key\>value\</key\> with key prefixed format 0049 * @p namespaceUri 0050 */ 0051 void writeElement( const QString &namespaceUri, const QString &key, const QString &value ); 0052 0053 /** 0054 * @brief Convenience method to write \<key\>value\</key\> 0055 * 0056 **/ 0057 void writeElement( const QString &key, const QString &value ); 0058 0059 /** 0060 * @brief Convenience method to write \<key\>value\</key\> if value is 0061 * not equal to defaultValue. Otherwise, nothing is written. 0062 * 0063 **/ 0064 void writeOptionalElement(const QString &key, const QString &value , const QString &defaultValue = QString() ); 0065 0066 /** 0067 * @brief writeOptionalAttribute Convenience method to write k=v attributes 0068 * if value is not equal to defaultValue 0069 */ 0070 void writeOptionalAttribute( const QString &key, const QString &value, const QString &defaultValue = QString() ); 0071 0072 template<class T> 0073 void writeOptionalElement( const QString &key, const T &value , const T &defaultValue = T() ) 0074 { 0075 if ( value != defaultValue ) { 0076 writeElement( key, QVariant::fromValue( value ).toString() ); 0077 } 0078 } 0079 0080 private: 0081 friend class GeoTagWriter; 0082 friend class GeoDataDocumentWriter; 0083 bool writeElement( const GeoNode* object ); 0084 0085 private: 0086 QString m_documentType; 0087 }; 0088 0089 } 0090 0091 #endif