[Marble-commits] KDE/kdeedu/marble/src
Andrew Manson
g.real.ate at gmail.com
Mon Aug 10 18:48:51 CEST 2009
SVN commit 1009702 by mansona:
full implementation of OSM Annotation file reading and writing from and to KML
M +1 -1 lib/geodata/parser/GeoParser.cpp
M +87 -13 plugins/render/osmannotate/OsmAnnotatePlugin.cpp
M +5 -1 plugins/render/osmannotate/OsmAnnotatePlugin.h
M +4 -3 plugins/render/osmannotate/PlacemarkTextAnnotation.cpp
M +1 -1 plugins/render/osmannotate/PlacemarkTextAnnotation.h
M +4 -2 plugins/render/osmannotate/TextAnnotation.cpp
M +1 -1 plugins/render/osmannotate/TextAnnotation.h
--- trunk/KDE/kdeedu/marble/src/lib/geodata/parser/GeoParser.cpp #1009701:1009702
@@ -103,7 +103,7 @@
}
if ( error() )
- qDebug() << "[GeoParser::read] -> Error occurred:" << errorString();
+ qDebug() << "[GeoParser::read] -> Error occurred:" << errorString() << " at line: " << lineNumber();
return !error();
}
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/OsmAnnotatePlugin.cpp #1009701:1009702
@@ -19,13 +19,15 @@
#include <QtGui/QAction>
#include "AbstractProjection.h"
#include "AreaAnnotation.h"
-#include "MarbleDirs.h"
+#include "GeoDataDocument.h"
+#include "GeoDataParser.h"
#include "GeoPainter.h"
-#include "GeoDataParser.h"
#include "GeoWriter.h"
+#include "MarbleDirs.h"
#include "MarbleWidget.h"
#include "osm/OsmBoundsGraphicsItem.h"
#include "PlacemarkTextAnnotation.h"
+#include "TextAnnotation.h"
namespace Marble
{
@@ -231,11 +233,17 @@
}
}
-void OsmAnnotatePlugin::saveOsmFile()
+void OsmAnnotatePlugin::saveAnnotationFile()
{
- QList<GeoDataFeature> features;
- GeoDataPlacemark test;
- features.append( test );
+ GeoDataDocument document;
+
+ QList<TextAnnotation*> allAnnotations = annotations();
+
+ TextAnnotation* annotation;
+ foreach( annotation, allAnnotations ) {
+ document.append( annotation->toGeoData() );
+ }
+
QString filename;
filename = QFileDialog::getSaveFileName( 0, tr("Save Annotation File"),
QString(),
@@ -252,12 +260,57 @@
// Open file in right mode
file.open( QIODevice::ReadWrite );
- if ( !writer.write( &file, features ) ) {
+ if ( !writer.write( &file, document ) ) {
qWarning( "Could not write the file." );
}
}
}
+void OsmAnnotatePlugin::loadAnnotationFile()
+{
+ //load the file here
+ QString filename;
+ filename = QFileDialog::getOpenFileName(0, tr("Open Annotation File"),
+ QString(),
+ tr("All Supported Files (*.kml);;Kml Annotation file (*.kml)"));
+
+ if ( ! filename.isNull() ) {
+
+ GeoDataParser parser( GeoData_KML );
+
+ QFile file( filename );
+ if ( !file.exists() ) {
+ qWarning( "File does not exist!" );
+ return;
+ }
+
+ // Open file in right mode
+ file.open( QIODevice::ReadOnly );
+
+ if ( !parser.read( &file ) ) {
+ qWarning( "Could not parse file!" );
+ //do not quit on a failed read!
+ //return
+ }
+ GeoDataDocument* document = dynamic_cast<GeoDataDocument*>(parser.releaseDocument() );
+ Q_ASSERT( document );
+
+ file.close();
+
+ QVector<GeoDataFeature>::ConstIterator it = document->constBegin();
+ for( ; it < document->constEnd(); ++it ) {
+ PlacemarkTextAnnotation* annotation = new PlacemarkTextAnnotation();
+ annotation->setName( (*it).name() );
+ annotation->setDescription( (*it).description() );
+ annotation->setCoordinate( GeoDataPlacemark((*it)).coordinate() );
+ model.append( annotation );
+ }
+
+ delete document;
+ emit repaintNeeded(QRegion());
+ }
+}
+
bool OsmAnnotatePlugin::eventFilter(QObject* watched, QEvent* event)
{
MarbleWidget* marbleWidget = (MarbleWidget*) watched;
@@ -375,7 +428,8 @@
QAction* m_beginSeparator;
QAction* m_endSeparator;
QAction* m_loadOsmFile;
- QAction* m_saveOsmFile;
+ QAction* m_saveAnnotationFile;
+ QAction* m_loadAnnotationFile;
QAction* m_enableInputAction;
m_addPlacemark = new QAction(this);
@@ -397,11 +451,16 @@
connect( m_loadOsmFile, SIGNAL(triggered()),
this, SLOT(loadOsmFile()) );
- m_saveOsmFile = new QAction( this );
- m_saveOsmFile->setText( tr("Save Osm File") );
- connect( m_saveOsmFile, SIGNAL(triggered()),
- this, SLOT(saveOsmFile()) );
+ m_saveAnnotationFile = new QAction( this );
+ m_saveAnnotationFile->setText( tr("Save Annotation File") );
+ connect( m_saveAnnotationFile, SIGNAL(triggered()),
+ this, SLOT(saveAnnotationFile()) );
+ m_loadAnnotationFile = new QAction( this );
+ m_loadAnnotationFile->setText( tr("Load Annotation File" ) );
+ connect( m_loadAnnotationFile, SIGNAL(triggered()),
+ this, SLOT(loadAnnotationFile()) );
+
m_beginSeparator = new QAction( this );
m_beginSeparator->setSeparator( true );
m_endSeparator = new QAction ( this );
@@ -421,7 +480,8 @@
group->addAction( m_addPlacemark );
group->addAction( m_drawPolygon );
group->addAction( m_loadOsmFile );
- group->addAction( m_saveOsmFile );
+ group->addAction( m_saveAnnotationFile );
+ group->addAction( m_loadAnnotationFile );
group->addAction( m_endSeparator );
actions->append( initial );
@@ -440,8 +500,22 @@
emit actionGroupsChanged();
}
+QList<TextAnnotation*> OsmAnnotatePlugin::annotations() const
+{
+ QList<TextAnnotation*> tmpAnnotations;
+ TmpGraphicsItem* item;
+ foreach( item, model ) {
+ TextAnnotation* annotation = dynamic_cast<TextAnnotation*>(item);
+ if( annotation ) {
+ tmpAnnotations.append( annotation );
+ }
+ }
+
+ return tmpAnnotations;
}
+}
+
Q_EXPORT_PLUGIN2( OsmAnnotatePlugin, Marble::OsmAnnotatePlugin )
#include "OsmAnnotatePlugin.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/OsmAnnotatePlugin.h #1009701:1009702
@@ -28,6 +28,7 @@
class MarbleWidget;
class GeoDataDocument;
+ class TextAnnotation;
/**
* @short The class that specifies the Marble layer interface of a plugin.
@@ -80,7 +81,8 @@
public slots:
void loadOsmFile();
- void saveOsmFile();
+ void saveAnnotationFile();
+ void loadAnnotationFile();
void setAddingPlacemark( bool );
void setDrawingPolygon( bool );
@@ -100,6 +102,8 @@
QList<TmpGraphicsItem*> model;
QList<GeoGraphicsItem*>* m_itemModel;
+ QList<TextAnnotation*> annotations() const;
+
//used while creating new polygons
GeoDataLineString* m_tmp_lineString;
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/PlacemarkTextAnnotation.cpp #1009701:1009702
@@ -152,16 +152,17 @@
m_textEditor->setDescription( description );
}
-GeoDataGeometry PlacemarkTextAnnotation::geometry() const
+GeoDataPoint PlacemarkTextAnnotation::geometry() const
{
- return GeoDataPoint( coordinate() );
+ GeoDataPoint point( coordinate() );
+ return point;
}
void PlacemarkTextAnnotation::setGeometry( const GeoDataGeometry &geometry )
{
//FIXME: undefined reference
// if( geometry.nodeType() == GeoDataTypes::GeoDataPointType ) {
- setCoordinate( GeoDataCoordinates( static_cast<GeoDataPoint>(geometry) ) );
+ static_cast<GeoDataPoint>(geometry);
// }
}
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/PlacemarkTextAnnotation.h #1009701:1009702
@@ -37,7 +37,7 @@
virtual void setName( const QString &name );
virtual QString description() const;
virtual void setDescription( const QString &description );
- virtual GeoDataGeometry geometry() const;
+ virtual GeoDataPoint geometry() const;
virtual void setGeometry( const GeoDataGeometry &geometry );
private:
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/TextAnnotation.cpp #1009701:1009702
@@ -12,7 +12,9 @@
#include "GeoDataPlacemark.h"
+#include <QtCore/QDebug>
+
namespace Marble{
TextAnnotation::TextAnnotation()
@@ -33,8 +35,8 @@
placemark.setDescriptionCDATA( true );
//FIXME: make this work for all geometries and not just points
-// placemark.setGeometry( geometry() );
- placemark.setGeometry( GeoDataPoint( geometry() ) );
+// FIXME change the geometry() to return a GeoDataGeometry and this won't work
+ placemark.setGeometry( geometry() );
return placemark;
}
--- trunk/KDE/kdeedu/marble/src/plugins/render/osmannotate/TextAnnotation.h #1009701:1009702
@@ -29,7 +29,7 @@
virtual void setName( const QString& name ) = 0;
virtual QString description() const = 0;
virtual void setDescription( const QString& description ) = 0;
- virtual GeoDataGeometry geometry() const = 0;
+ virtual GeoDataPoint geometry() const = 0;
virtual void setGeometry( const GeoDataGeometry &geometry ) = 0;
GeoDataPlacemark toGeoData() const;
More information about the Marble-commits
mailing list