Commit 0448670d authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Use GeoDataDocumentWriter instead of GeoWriter.

parent 99c25c19
......@@ -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;
......
......@@ -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);
......
......@@ -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 )
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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)) {
......
......@@ -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.
......
......@@ -18,7 +18,6 @@
#include <GeoDataFolder.h>
#include <GeoDataPlacemark.h>
#include <GeoDataExtendedData.h>
#include <GeoWriter.h>
#include <QApplication>
#include <QDebug>
......
......@@ -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);
}
......@@ -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_)
......
......@@ -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{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment