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 #include "GeoWriter.h" 0007 0008 #include "GeoDocument.h" 0009 #include "GeoTagWriter.h" 0010 #include "KmlElementDictionary.h" 0011 #include "DgmlElementDictionary.h" 0012 0013 #include "digikam_debug.h" 0014 0015 namespace Marble 0016 { 0017 0018 GeoWriter::GeoWriter() 0019 { 0020 //FIXME: work out a standard way to do this. 0021 m_documentType = QString::fromUtf8(kml::kmlTag_nameSpaceOgc22); 0022 } 0023 0024 bool GeoWriter::write(QIODevice* device, const GeoNode *feature) 0025 { 0026 setDevice( device ); 0027 setAutoFormatting( true ); 0028 writeStartDocument(); 0029 0030 //FIXME: write the starting tags. Possibly register a tag handler to do this 0031 // with a null string as the object name? 0032 0033 GeoTagWriter::QualifiedName name( QString(), m_documentType ); 0034 const GeoTagWriter* writer = GeoTagWriter::recognizes(name); 0035 if( writer ) { 0036 //FIXME is this too much of a hack? 0037 writer->write(/* node = */ nullptr, *this); // node is never used in write() 0038 } else { 0039 qCDebug(DIGIKAM_MARBLE_LOG) << "There is no GeoWriter registered for: " << name; 0040 return false; 0041 } 0042 0043 if( ! writeElement( feature ) ) { 0044 return false; 0045 } 0046 0047 //close the document 0048 writeEndElement(); 0049 return true; 0050 } 0051 0052 bool GeoWriter::writeElement(const GeoNode *object) 0053 { 0054 // Add checks to see that everything is ok here 0055 0056 GeoTagWriter::QualifiedName name( QString::fromUtf8(object->nodeType()), m_documentType ); 0057 const GeoTagWriter* writer = GeoTagWriter::recognizes( name ); 0058 0059 if( writer ) { 0060 if( ! writer->write( object, *this ) ) { 0061 qCDebug(DIGIKAM_MARBLE_LOG) << "An error has been reported by the GeoWriter for: " 0062 << name; 0063 return false; 0064 } 0065 } else { 0066 qCDebug(DIGIKAM_MARBLE_LOG) << "There is no GeoWriter registered for: " << name; 0067 return true; 0068 } 0069 return true; 0070 } 0071 0072 0073 void GeoWriter::setDocumentType( const QString &documentType ) 0074 { 0075 m_documentType = documentType; 0076 } 0077 0078 void GeoWriter::writeElement( const QString &namespaceUri, const QString &key, const QString &value ) 0079 { 0080 writeStartElement( namespaceUri, key ); 0081 writeCharacters( value ); 0082 writeEndElement(); 0083 } 0084 0085 void GeoWriter::writeElement( const QString &key, const QString &value ) 0086 { 0087 writeStartElement( key ); 0088 writeCharacters( value ); 0089 writeEndElement(); 0090 } 0091 0092 void GeoWriter::writeOptionalElement( const QString &key, const QString &value, const QString &defaultValue ) 0093 { 0094 if( value != defaultValue ) { 0095 writeElement( key, value ); 0096 } 0097 } 0098 0099 void GeoWriter::writeOptionalAttribute( const QString &key, const QString &value, const QString &defaultValue ) 0100 { 0101 if( value != defaultValue ) { 0102 writeAttribute( key, value ); 0103 } 0104 } 0105 0106 }