[Marble-commits] KDE/kdeedu/marble/src/lib/geodata
Dennis Nienhüser
earthwings at gentoo.org
Wed Sep 8 00:04:40 CEST 2010
SVN commit 1172715 by nienhueser:
Adds a kml tag writer for GeoDataLineString, adds writing of Document/name and Document/address elements and two convenience methods to write elements with string values quickly to reduce the amount of code.
RB: 5283
M +14 -0 writer/GeoWriter.cpp
M +14 -0 writer/GeoWriter.h
M +1 -6 writers/kml/KmlDataTagWriter.cpp
M +2 -0 writers/kml/KmlDocumentTagWriter.cpp
M +1 -5 writers/kml/KmlFolderTagWriter.cpp
A writers/kml/KmlLineStringTagWriter.cpp [License: LGPL]
A writers/kml/KmlLineStringTagWriter.h [License: LGPL]
M +4 -15 writers/kml/KmlLookAtTagWriter.cpp
M +1 -5 writers/kml/KmlPlacemarkTagWriter.cpp
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoWriter.cpp #1172714:1172715
@@ -91,4 +91,18 @@
m_documentType = documentType;
}
+void GeoWriter::writeElement( const QString &key, const QString &value )
+{
+ writeStartElement( key );
+ writeCharacters( value );
+ writeEndElement();
}
+
+void GeoWriter::writeOptionalElement( const QString &key, const QString &value )
+{
+ if( !value.isEmpty() ) {
+ writeElement( key, value );
+ }
+}
+
+}
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoWriter.h #1172714:1172715
@@ -57,6 +57,20 @@
* string used to register the required Tag Writers in @see GeoTagWriter
*/
void setDocumentType( const QString& documentType );
+
+ /**
+ * @brief Convenience method to write <key>value</key>
+ *
+ **/
+ void writeElement( const QString &key, const QString &value );
+
+ /**
+ * @brief Convenience method to write <key>value</key> if value is
+ * not empty. Otherwise, nothing is written.
+ *
+ **/
+ void writeOptionalElement( const QString &key, const QString &value );
+
private:
friend class GeoTagWriter;
bool writeElement( const GeoDataObject& object );
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlDataTagWriter.cpp #1172714:1172715
@@ -31,14 +31,9 @@
writer.writeStartElement( kml::kmlTag_Data );
writer.writeAttribute( "name", data.displayName() );
-
- writer.writeStartElement( "value" );
- writer.writeCharacters( data.value().toString() );
+ writer.writeElement( "value", data.value().toString() );
writer.writeEndElement();
-
- writer.writeEndElement();
-
return true;
}
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlDocumentTagWriter.cpp #1172714:1172715
@@ -33,6 +33,8 @@
const GeoDataDocument &document = static_cast<const GeoDataDocument&>(node);
writer.writeStartElement( kml::kmlTag_Document );
+ writer.writeOptionalElement( "name", document.name() );
+ writer.writeOptionalElement( "address", document.address() );
QVector<GeoDataFeature*>::ConstIterator it = document.constBegin();
QVector<GeoDataFeature*>::ConstIterator const end = document.constEnd();
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlFolderTagWriter.cpp #1172714:1172715
@@ -34,11 +34,7 @@
writer.writeStartElement( kml::kmlTag_Folder );
//Writing folder name
- if( !folder.name().isEmpty() ) {
- writer.writeStartElement( "name" );
- writer.writeCharacters( folder.name() );
- writer.writeEndElement();
- }
+ writer.writeOptionalElement( "name", folder.name() );
//Write all containing features
QVector<GeoDataFeature*>::ConstIterator it = folder.constBegin();
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlLookAtTagWriter.cpp #1172714:1172715
@@ -31,24 +31,13 @@
writer.writeStartElement( kml::kmlTag_LookAt );
- writer.writeStartElement( "longitude" );
- writer.writeCharacters( QString::number( lookAt.longitude( GeoDataCoordinates::Degree ), 'f', 10 ) );
- writer.writeEndElement();
+ writer.writeElement( "longitude", QString::number( lookAt.longitude( GeoDataCoordinates::Degree ), 'f', 10 ) );
+ writer.writeElement( "latitude", QString::number( lookAt.latitude( GeoDataCoordinates::Degree ), 'f', 10 ) );
+ writer.writeElement( "altitude", QString::number( lookAt.altitude(), 'f', 10 ) );
+ writer.writeElement( "range", QString::number( lookAt.range(), 'f', 10 ) );
- writer.writeStartElement( "latitude" );
- writer.writeCharacters( QString::number( lookAt.latitude( GeoDataCoordinates::Degree ), 'f', 10 ) );
writer.writeEndElement();
- writer.writeStartElement( "altitude" );
- writer.writeCharacters( QString::number( lookAt.altitude(), 'f', 10 ) );
- writer.writeEndElement();
-
- writer.writeStartElement( "range" );
- writer.writeCharacters( QString::number( lookAt.range(), 'f', 10 ) );
- writer.writeEndElement();
-
- writer.writeEndElement();
-
return true;
}
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.cpp #1172714:1172715
@@ -34,11 +34,7 @@
const GeoDataPlacemark &placemark = static_cast<const GeoDataPlacemark&>(node);
writer.writeStartElement( kml::kmlTag_Placemark );
- if( !placemark.name().isEmpty() ) {
- writer.writeStartElement( "name" );
- writer.writeCharacters( placemark.name() );
- writer.writeEndElement();
- }
+ writer.writeOptionalElement( "name", placemark.name() );
if( !placemark.description().isEmpty() ) {
writer.writeStartElement( "description" );
More information about the Marble-commits
mailing list