summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-08-06 21:04:51 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-08-06 21:04:51 (GMT)
commit0448670d4325ab96cc24ae24b5b3fea1d90328e4 (patch)
tree6003eedb4514212dc59f9c700d8392319cf95dcc
parent99c25c19efbb3080a3d8b2dff4010eafc8ae310e (diff)
Use GeoDataDocumentWriter instead of GeoWriter.
-rw-r--r--src/lib/marble/BookmarkManager.cpp10
-rw-r--r--src/lib/marble/BookmarkManagerDialog.cpp8
-rw-r--r--src/lib/marble/FileManager.cpp13
-rw-r--r--src/lib/marble/PositionTracking.cpp11
-rw-r--r--src/lib/marble/TourWidget.cpp29
-rw-r--r--src/lib/marble/geodata/writer/GeoDataDocumentWriter.cpp2
-rw-r--r--src/lib/marble/geodata/writer/GeoDataDocumentWriter.h2
-rw-r--r--tools/kml2cache/kml2cache.cpp1
-rw-r--r--tools/kml2kml/kml2kml.cpp11
-rw-r--r--tools/osm-addresses/OsmParser.cpp15
-rw-r--r--tools/osm-simplify/main.cpp52
11 files changed, 42 insertions, 112 deletions
diff --git a/src/lib/marble/BookmarkManager.cpp b/src/lib/marble/BookmarkManager.cpp
index 44b9d82..e87685c 100644
--- a/src/lib/marble/BookmarkManager.cpp
+++ b/src/lib/marble/BookmarkManager.cpp
@@ -17,7 +17,7 @@
#include "GeoDataFolder.h"
#include "GeoDataPlacemark.h"
#include "GeoDataTreeModel.h"
-#include "GeoWriter.h"
+#include "GeoDataDocumentWriter.h"
#include "KmlElementDictionary.h"
#include "MarbleDebug.h"
#include "MarbleDirs.h"
@@ -249,11 +249,7 @@ bool BookmarkManager::updateBookmarkFile()
QString absoluteLocalFilePath = MarbleDirs::localPath() + '/' + d->m_bookmarkFileRelativePath ;
if ( ! d->m_bookmarkFileRelativePath.isNull() ) {
- GeoWriter writer;
- writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 );
-
QFile file( absoluteLocalFilePath );
-
if ( !file.exists() ) {
// Extracting directory of file : for bookmarks it will be MarbleDirs::localPath()+/bookmarks/
QFileInfo fileInfo( absoluteLocalFilePath );
@@ -264,9 +260,7 @@ bool BookmarkManager::updateBookmarkFile()
directory.mkpath( directoryPath );
}
- file.open( QIODevice::WriteOnly );
-
- if ( !writer.write( &file, d->m_bookmarkDocument ) ) {
+ if (!GeoDataDocumentWriter::write(absoluteLocalFilePath, *d->m_bookmarkDocument)) {
mDebug() << "Could not write the bookmarks file" << absoluteLocalFilePath;
file.close();
return false;
diff --git a/src/lib/marble/BookmarkManagerDialog.cpp b/src/lib/marble/BookmarkManagerDialog.cpp
index bf105ed..7b9e5c3 100644
--- a/src/lib/marble/BookmarkManagerDialog.cpp
+++ b/src/lib/marble/BookmarkManagerDialog.cpp
@@ -24,7 +24,7 @@
#include "GeoDataStyle.h"
#include "GeoDataTreeModel.h"
#include "GeoDataTypes.h"
-#include "GeoWriter.h"
+#include "GeoDataDocumentWriter.h"
#include "MarbleDirs.h"
#include "MarbleDebug.h"
#include "MarbleModel.h"
@@ -406,11 +406,7 @@ void BookmarkManagerDialog::exportBookmarks()
QDir::homePath(), tr( "KML files (*.kml)" ) );
if ( !fileName.isEmpty() ) {
- QFile file( fileName );
- GeoWriter writer;
- writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 );
-
- if ( !file.open( QIODevice::ReadWrite ) || !writer.write( &file, bookmarkDocument() ) ) {
+ if (!GeoDataDocumentWriter::write(fileName, *bookmarkDocument())) {
mDebug() << "Could not write the bookmarks file" << fileName;
QString const text = tr( "Unable to save bookmarks. Please check that the file is writable." );
QMessageBox::warning(this, tr("Bookmark Export"), text);
diff --git a/src/lib/marble/FileManager.cpp b/src/lib/marble/FileManager.cpp
index b9fe122..cd26c26 100644
--- a/src/lib/marble/FileManager.cpp
+++ b/src/lib/marble/FileManager.cpp
@@ -23,7 +23,7 @@
#include "GeoDataDocument.h"
#include "GeoDataLatLonAltBox.h"
#include "GeoDataStyle.h"
-#include "GeoWriter.h"
+#include "GeoDataDocumentWriter.h"
#include <KmlElementDictionary.h>
@@ -143,16 +143,9 @@ void FileManagerPrivate::closeFile( const QString& key )
void FileManager::saveFile( const QString &fileName, const GeoDataDocument *document )
{
- GeoWriter writer;
- writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 );
-
- QFile file( fileName );
- if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) {
- return;
+ if (document) {
+ GeoDataDocumentWriter::write(fileName, *document, kml::kmlTag_nameSpaceOgc22);
}
-
- writer.write( &file, document );
- file.close();
}
void FileManager::closeFile( const GeoDataDocument *document )
diff --git a/src/lib/marble/PositionTracking.cpp b/src/lib/marble/PositionTracking.cpp
index abc2cba..289ddd7 100644
--- a/src/lib/marble/PositionTracking.cpp
+++ b/src/lib/marble/PositionTracking.cpp
@@ -21,7 +21,7 @@
#include "GeoDataTrack.h"
#include "GeoDataTreeModel.h"
#include "GeoDataTypes.h"
-#include "GeoWriter.h"
+#include "GeoDataDocumentWriter.h"
#include "KmlElementDictionary.h"
#include "FileManager.h"
#include "MarbleMath.h"
@@ -259,10 +259,6 @@ bool PositionTracking::saveTrack( const QString& fileName )
return false;
}
- GeoWriter writer;
- //FIXME: a better way to do this?
- writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 );
-
GeoDataDocument *document = new GeoDataDocument;
QFileInfo fileInfo( fileName );
QString name = fileInfo.baseName();
@@ -277,10 +273,7 @@ bool PositionTracking::saveTrack( const QString& fileName )
track->setName( "Track " + name );
document->append( track );
- QFile file( fileName );
- file.open( QIODevice::WriteOnly );
- bool const result = writer.write( &file, document );
- file.close();
+ bool const result = GeoDataDocumentWriter::write(fileName, *document);
delete document;
return result;
}
diff --git a/src/lib/marble/TourWidget.cpp b/src/lib/marble/TourWidget.cpp
index 321906a..f40e7fc 100644
--- a/src/lib/marble/TourWidget.cpp
+++ b/src/lib/marble/TourWidget.cpp
@@ -27,7 +27,7 @@
#include "GeoDataTourControl.h"
#include "GeoDataSoundCue.h"
#include "GeoDataAnimatedUpdate.h"
-#include "GeoWriter.h"
+#include "GeoDataDocumentWriter.h"
#include "KmlElementDictionary.h"
#include "MarbleModel.h"
#include "MarblePlacemarkModel.h"
@@ -835,24 +835,17 @@ void TourWidgetPrivate::saveTourAs()
bool TourWidgetPrivate::saveTourAs(const QString &filename)
{
- if ( !filename.isEmpty() )
- {
- QFile file( filename );
- if ( file.open( QIODevice::WriteOnly ) ) {
- GeoWriter writer;
- writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 );
- if ( writer.write( &file, m_document ) ) {
- file.close();
- m_tourUi.m_actionSaveTour->setEnabled( false );
- m_isChanged = false;
- GeoDataDocument* document = m_document;
- if ( !document->fileName().isNull() ) {
- m_widget->model()->removeGeoData( document->fileName() );
- }
- m_widget->model()->addGeoDataFile( filename );
- m_document->setFileName( filename );
- return true;
+ if ( !filename.isEmpty() ) {
+ if (GeoDataDocumentWriter::write(filename, *m_document)) {
+ m_tourUi.m_actionSaveTour->setEnabled( false );
+ m_isChanged = false;
+ GeoDataDocument* document = m_document;
+ if ( !document->fileName().isNull() ) {
+ m_widget->model()->removeGeoData( document->fileName() );
}
+ m_widget->model()->addGeoDataFile( filename );
+ m_document->setFileName( filename );
+ return true;
}
}
return false;
diff --git a/src/lib/marble/geodata/writer/GeoDataDocumentWriter.cpp b/src/lib/marble/geodata/writer/GeoDataDocumentWriter.cpp
index 30bfd75..0537d12 100644
--- a/src/lib/marble/geodata/writer/GeoDataDocumentWriter.cpp
+++ b/src/lib/marble/geodata/writer/GeoDataDocumentWriter.cpp
@@ -42,7 +42,7 @@ bool GeoDataDocumentWriter::write(QIODevice *device, const GeoDataDocument &docu
}
}
-bool GeoDataDocumentWriter::write(QString &filename, const GeoDataDocument &document, const QString &documentIdentifier)
+bool GeoDataDocumentWriter::write(const QString &filename, const GeoDataDocument &document, const QString &documentIdentifier)
{
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
diff --git a/src/lib/marble/geodata/writer/GeoDataDocumentWriter.h b/src/lib/marble/geodata/writer/GeoDataDocumentWriter.h
index e7bedf8..d2dc96e 100644
--- a/src/lib/marble/geodata/writer/GeoDataDocumentWriter.h
+++ b/src/lib/marble/geodata/writer/GeoDataDocumentWriter.h
@@ -46,7 +46,7 @@ public:
* Use an empty string (default) to determine it automatically
* @return True if writing is successful, false otherwise
*/
- static bool write(QString &filename, const GeoDataDocument &document, const QString &documentIdentifier = QString());
+ static bool write(const QString &filename, const GeoDataDocument &document, const QString &documentIdentifier = QString());
/**
* Registers a plugin as a backend for writing a certain file extension. Usually called by the MARBLE_ADD_WRITER macro.
diff --git a/tools/kml2cache/kml2cache.cpp b/tools/kml2cache/kml2cache.cpp
index 1bd55fd..0710ac3 100644
--- a/tools/kml2cache/kml2cache.cpp
+++ b/tools/kml2cache/kml2cache.cpp
@@ -18,7 +18,6 @@
#include <GeoDataFolder.h>
#include <GeoDataPlacemark.h>
#include <GeoDataExtendedData.h>
-#include <GeoWriter.h>
#include <QApplication>
#include <QDebug>
diff --git a/tools/kml2kml/kml2kml.cpp b/tools/kml2kml/kml2kml.cpp
index 86209b1..2a1c320 100644
--- a/tools/kml2kml/kml2kml.cpp
+++ b/tools/kml2kml/kml2kml.cpp
@@ -14,7 +14,7 @@
#include <MarbleWidget.h>
#include <ParsingRunnerManager.h>
#include <PluginManager.h>
-#include <GeoWriter.h>
+#include <GeoDataDocumentWriter.h>
#include <QApplication>
#include <QFile>
@@ -48,12 +48,5 @@ int main(int argc, char** argv)
return 2;
}
-
- QFile output(outputFilename);
- if (!output.open(QIODevice::WriteOnly)) {
- qDebug() << "Unable to write to " << output.fileName();
- return 3;
- }
-
- GeoWriter().write(&output, dynamic_cast<GeoDataFeature*>(document));
+ GeoDataDocumentWriter::write(outputFilename, *document);
}
diff --git a/tools/osm-addresses/OsmParser.cpp b/tools/osm-addresses/OsmParser.cpp
index 10ef246..ddeced0 100644
--- a/tools/osm-addresses/OsmParser.cpp
+++ b/tools/osm-addresses/OsmParser.cpp
@@ -22,7 +22,7 @@
#include "GeoDataStyleMap.h"
#include "GeoDataLineStyle.h"
#include "GeoDataFeature.h"
-#include "geodata/writer/GeoWriter.h"
+#include "geodata/writer/GeoDataDocumentWriter.h"
#include "geodata/data/GeoDataExtendedData.h"
#include <geodata/handlers/kml/KmlElementDictionary.h>
@@ -745,18 +745,9 @@ void OsmParser::writeKml( const QString &area, const QString &version, const QSt
document->addStyleMap( styleMap );
// }
- GeoWriter writer;
- writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 );
-
- QFile file( filename );
- if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) {
- qCritical() << "Cannot write to " << file.fileName();
- }
-
- if ( !writer.write( &file, document ) ) {
- qCritical() << "Can not write to " << file.fileName();
+ if (!GeoDataDocumentWriter::write(filename, *document)) {
+ qCritical() << "Can not write to " << filename;
}
- file.close();
}
Coordinate::Coordinate(float lon_, float lat_) : lon(lon_), lat(lat_)
diff --git a/tools/osm-simplify/main.cpp b/tools/osm-simplify/main.cpp
index e365f2f..b74452c 100644
--- a/tools/osm-simplify/main.cpp
+++ b/tools/osm-simplify/main.cpp
@@ -8,7 +8,7 @@
// Copyright 2016 David Kolozsvari <freedawson@gmail.com>
//
-#include "GeoWriter.h"
+#include "GeoDataDocumentWriter.h"
#include "MarbleModel.h"
#include "ParsingRunnerManager.h"
@@ -228,14 +228,11 @@ int main(int argc, char *argv[])
for(unsigned int y = 0; y < N; ++y) {
GeoDataDocument* tile = processor.cutToTiles(zoomLevel, x, y);
- GeoWriter writer;
- writer.setDocumentType("0.6");
-
- QFile outputFile;
+ QString outputFile;
if(parser.isSet("output")) {
- outputFile.setFileName( QString("%1/%2/%3/%4.osm").arg(outputName).arg(zoomLevel).arg(x).arg(y) );
+ outputFile = QString("%1/%2/%3/%4.osm").arg(outputName).arg(zoomLevel).arg(x).arg(y);
} else {
- outputFile.setFileName( QString("%1/%2/%3.osm").arg(zoomLevel).arg(x).arg(y) );
+ outputFile = QString("%1/%2/%3.osm").arg(zoomLevel).arg(x).arg(y);
}
QDir dir;
@@ -260,8 +257,7 @@ int main(int argc, char *argv[])
}
}
- outputFile.open( QIODevice::WriteOnly );
- if ( !writer.write( &outputFile, tile ) ) {
+ if (!GeoDataDocumentWriter::write(outputFile, *tile)) {
qDebug() << "Could not write the file " << outputName;
return 4;
}
@@ -287,14 +283,11 @@ int main(int argc, char *argv[])
GeoDataDocument* tile = mergeDocuments(tile1, tile2);
- GeoWriter writer;
- writer.setDocumentType("0.6");
-
- QFile outputFile;
+ QString outputFile;
if(parser.isSet("output")) {
- outputFile.setFileName( QString("%1/%2/%3/%4.osm").arg(outputName).arg(zoomLevel).arg(x).arg(y) );
+ outputFile = QString("%1/%2/%3/%4.osm").arg(outputName).arg(zoomLevel).arg(x).arg(y);
} else {
- outputFile.setFileName( QString("%1/%2/%3.osm").arg(zoomLevel).arg(x).arg(y) );
+ outputFile = QString("%1/%2/%3.osm").arg(zoomLevel).arg(x).arg(y);
}
QDir dir;
@@ -319,8 +312,7 @@ int main(int argc, char *argv[])
}
}
- outputFile.open( QIODevice::WriteOnly );
- if ( !writer.write( &outputFile, tile ) ) {
+ if (!GeoDataDocumentWriter::write(outputFile, *tile)) {
qDebug() << "Could not write the file " << outputName;
return 4;
}
@@ -343,14 +335,11 @@ int main(int argc, char *argv[])
for(unsigned int y = 0; y < N; ++y) {
GeoDataDocument* tile = processor.cutToTiles(zoomLevel, x, y);
- GeoWriter writer;
- writer.setDocumentType("0.6");
-
- QFile outputFile;
+ QString outputFile;
if(parser.isSet("output")) {
- outputFile.setFileName( QString("%1/%2/%3/%4.osm").arg(outputName).arg(zoomLevel).arg(x).arg(y) );
+ outputFile = QString("%1/%2/%3/%4.osm").arg(outputName).arg(zoomLevel).arg(x).arg(y);
} else {
- outputFile.setFileName( QString("%1/%2/%3.osm").arg(zoomLevel).arg(x).arg(y) );
+ outputFile = QString("%1/%2/%3.osm").arg(zoomLevel).arg(x).arg(y);
}
QDir dir;
@@ -375,8 +364,7 @@ int main(int argc, char *argv[])
}
}
- outputFile.open( QIODevice::WriteOnly );
- if ( !writer.write( &outputFile, tile ) ) {
+ if (!GeoDataDocumentWriter::write(outputFile, *tile)) {
qDebug() << "Could not write the file " << outputName;
return 4;
}
@@ -395,12 +383,7 @@ int main(int argc, char *argv[])
else{
NodeReducer reducer(map, zoomLevel);
reducer.process();
- QFile outputFile(outputName);
- GeoWriter writer;
- writer.setDocumentType("0.6");
-
- outputFile.open( QIODevice::WriteOnly );
- if ( !writer.write( &outputFile, map ) ) {
+ if (!GeoDataDocumentWriter::write(outputName, *map)) {
qDebug() << "Could not write the file " << outputName;
return 4;
}
@@ -418,13 +401,8 @@ int main(int argc, char *argv[])
concatenator.process();
qDebug()<<"Concatenation done, writing results to the file";
-
- QFile outputFile(outputName);
- GeoWriter writer;
- writer.setDocumentType("0.6");
- outputFile.open( QIODevice::WriteOnly );
- if ( !writer.write( &outputFile, map ) ) {
+ if (!GeoDataDocumentWriter::write(outputName, *map)) {
qDebug() << "Could not write the file " << outputName;
return 4;
}else{