[Marble-commits] KDE/kdeedu/marble
Andrew Manson
g.real.ate at gmail.com
Wed Aug 5 12:37:29 CEST 2009
SVN commit 1007229 by mansona:
Commiting the work in progress of the XML writer. The tag recognition system
is mostly done ( very strongly based on the TagHandler stuff ).
Also moving the OSM file and KML file examples as discussed.
D data/examples (directory)
A examples/kml (directory)
A examples/kml/Marble writing.kml src/plugins/render/geodata/Marble writing.kml#1006747
A examples/kml/Rabet.kml src/plugins/render/geodata/Rabet.kml#1006747
A examples/kml/czech.kml src/plugins/render/geodata/czech.kml#1006747
A examples/kml/germany.kml src/plugins/render/geodata/germany.kml#1006747
A examples/kml/poland.kml src/plugins/render/geodata/poland.kml#1006747
A examples/osm (directory)
AM examples/osm/map.osm data/examples/map.osm#1006747
M +11 -3 src/lib/geodata/parser/GeoParser.h
M +11 -0 src/lib/geodata/writer/GeoTagWriter.cpp
M +7 -1 src/lib/geodata/writer/GeoTagWriter.h
M +34 -0 src/lib/geodata/writer/GeoWriter.cpp
M +26 -0 src/lib/geodata/writer/GeoWriter.h
M +10 -5 src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.cpp
M +1 -1 src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.h
D src/plugins/render/geodata/Marble writing.kml
D src/plugins/render/geodata/Rabet.kml
D src/plugins/render/geodata/czech.kml
D src/plugins/render/geodata/germany.kml
D src/plugins/render/geodata/poland.kml
M +23 -7 src/plugins/render/osmannotate/OsmAnnotatePlugin.cpp
** trunk/KDE/kdeedu/marble/examples/osm/map.osm #property svn:mergeinfo
+
--- trunk/KDE/kdeedu/marble/src/lib/geodata/parser/GeoParser.h #1007228:1007229
@@ -43,11 +43,19 @@
explicit GeoParser( GeoDataGenericSourceType sourceType );
virtual ~GeoParser();
- // Main API.
+ /**
+ * @brief Main API for reading the XML document.
+ * This is the only mentod that is necessary to call to start the GeoParser.
+ * To retrieve the resulting data see @see releaseDocument() and
+ * @see releaseModel()
+ */
bool read( QIODevice* );
- // If parsing was successful, retrieve the resulting document
- // and set the contained m_document pointer to 0.
+ /**
+ * @brief retrieve the parsed document and reset the parser
+ * If parsing was successful, retrieve the resulting document
+ * and set the contained m_document pointer to 0.
+ */
GeoDocument* releaseDocument();
GeoDocument* activeDocument() { return m_document; }
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoTagWriter.cpp #1007228:1007229
@@ -44,4 +44,15 @@
return s_tagWriterHash;
}
+const GeoTagWriter* GeoTagWriter::recognizes( const QualifiedName &qname )
+{
+ TagHash* hash = tagWriterHash();
+
+ if( !hash->contains( qname ) ) {
+ return 0;
+ }
+
+ return hash->value( qname );
}
+
+}
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoTagWriter.h #1007228:1007229
@@ -30,7 +30,7 @@
class GeoTagWriter
{
public:
- virtual bool write( GeoNode &node, GeoWriter& writer ) = 0;
+ virtual bool write( GeoNode &node, GeoWriter& writer ) const = 0;
/**
* @brief Object Name and Namespace Pair
@@ -55,10 +55,16 @@
friend struct GeoTagWriterRegistrar;
static void registerWriter(const QualifiedName&, const GeoTagWriter*);
+private:
//Collect the Tag Writers and provide a singleton like accessor
typedef QHash<QualifiedName, const GeoTagWriter*> TagHash;
static TagHash* tagWriterHash();
static TagHash* s_tagWriterHash;
+
+private:
+ // Only our writer is allowed to access tag handlers.
+ friend class GeoWriter;
+ static const GeoTagWriter* recognizes(const QualifiedName&);
};
// Helper structure
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoWriter.cpp #1007228:1007229
@@ -10,6 +10,40 @@
#include "GeoWriter.h"
+#include "GeoTagWriter.h"
+#include "KmlElementDictionary.h"
+
+namespace Marble
+{
+
GeoWriter::GeoWriter()
{
+ //FIXME: work out a standard way to do this.
+ m_documentType = kml::kmlTag_nameSpace22;
}
+
+bool GeoWriter::write(QIODevice* device, const QList<GeoDataFeature> &features)
+{
+ setDevice( device );
+ //FIXME: write the starting tags. Possibly register a tag handler to do this
+ // with a null string as the object name?
+
+ QListIterator<GeoDataFeature> it(features);
+
+ while ( it.hasNext() ) {
+ GeoDataFeature f = it.next();
+ GeoTagWriter::QualifiedName name( f.nodeType(), m_documentType );
+ const GeoTagWriter* writer = GeoTagWriter::recognizes( name );
+
+ if( writer ) {
+ writer->write( f, (*this) );
+ }
+ }
+}
+
+void GeoWriter::setDocumentType( const QString &documentType )
+{
+ m_documentType = documentType;
+}
+
+}
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoWriter.h #1007228:1007229
@@ -11,8 +11,12 @@
#ifndef GEOWRITER_H
#define GEOWRITER_H
+#include "GeoDataFeature.h"
+
#include <QtXml/QXmlStreamWriter>
+namespace Marble{
+
/**
* @brief Standard Marble way of writing XML
* This class is intended to be a standardised way of writing XML for marble.
@@ -23,6 +27,28 @@
{
public:
GeoWriter();
+
+ /**
+ * @brief The main API call to use the XML writer.
+ * To use the XML writer you need to provide an IODevice to write the XML to
+ * and a QList of GeoDataFeatures which contains the data you wish to write.
+ * To define the type of XML document that is to be written you need to set
+ * the current Document Type for this GeoWriter. See @see setDocumentType()
+ */
+ bool write( QIODevice* device,
+ const QList<GeoDataFeature>& features);
+
+ /**
+ * @brief Set the current document type.
+ * The current Document Type defines which set of hadlers are to be used
+ * when writing the GeoDocument. This string should corrispond with the
+ * string used to register the required Tag Writers in @see GeoTagWriter
+ */
+ void setDocumentType( const QString& documentType );
+private:
+ QString m_documentType;
};
+}
+
#endif // GEOWRITER_H
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.cpp #1007228:1007229
@@ -10,6 +10,9 @@
#include "KmlPlacemarkTagWriter.h"
#include "KmlElementDictionary.h"
+//FIXME:should the GeoDataTypes enum be in the GeoDocument?
+#include "GeoDocument.h"
+#include "GeoWriter.h"
namespace Marble{
@@ -17,15 +20,17 @@
//don't use the tag dictionary for tag names, because with the writer we are using
// the object type strings instead
//FIXME: USE object strings provided by idis
-static GeoTagWriterRegistrar s_writerPlacemark( GeoTagWriter::QualifiedName("ObjectType",
- kml::kmlTag_nameSpace20),
+static GeoTagWriterRegistrar s_writerPlacemark( GeoTagWriter::QualifiedName(GeoDataTypes::GeoDataPlacemarkType,
+ kml::kmlTag_nameSpace22),
new KmlPlacemarkTagWriter() );
-bool KmlPlacemarkTagWriter::write( GeoNode &node, GeoWriter& writer )
+bool KmlPlacemarkTagWriter::write( GeoNode &node, GeoWriter& writer ) const
{
- //write some stuff to the GeoWriter... which is just an XMLStream writer!
- return false;
+ writer.writeStartElement( kml::kmlTag_Placemark );
+ //Write the actual important stuff!
+ writer.writeEndElement();
+ return true;
}
}
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.h #1007228:1007229
@@ -18,7 +18,7 @@
class KmlPlacemarkTagWriter : public GeoTagWriter
{
public:
- virtual bool write( GeoNode &node, GeoWriter& writer );
+ virtual bool write( GeoNode &node, GeoWriter& writer ) const;
};
}
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/OsmAnnotatePlugin.cpp #1007228:1007229
@@ -22,6 +22,7 @@
#include "MarbleDirs.h"
#include "GeoPainter.h"
#include "GeoDataParser.h"
+#include "GeoWriter.h"
#include "MarbleWidget.h"
#include "osm/OsmBoundsGraphicsItem.h"
#include "PlacemarkTextAnnotation.h"
@@ -232,13 +233,28 @@
void OsmAnnotatePlugin::saveOsmFile()
{
- TmpGraphicsItem* item;
- QListIterator<TmpGraphicsItem*> it(model);
- while( it.hasNext() ) {
- item = it.next();
- qDebug() << "Saving item!";
-// implement the XML writer here
-// qDebug() << item;
+ QList<GeoDataFeature> features;
+ GeoDataPlacemark test;
+ features.append( test );
+ QString filename;
+ filename = QFileDialog::getSaveFileName( 0, tr("Save Annotation File"),
+ QString(),
+ tr("All Supported Files (*.kml);;KML file (*.kml)"));
+
+ if ( ! filename.isNull() ) {
+
+ GeoWriter writer;
+ //FIXME: a better way to do this?
+ writer.setDocumentType( "http://earth.google.com/kml/2.2" );
+
+ QFile file( filename );
+
+ // Open file in right mode
+ file.open( QIODevice::ReadWrite );
+
+ if ( !writer.write( &file, features ) ) {
+ qWarning( "Could not write the file." );
+ }
}
}
More information about the Marble-commits
mailing list