Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
scales import/export
- Loading branch information
Showing
7 changed files
with
266 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*************************************************************************** | ||
qgsscaleutils.cpp | ||
--------------------- | ||
begin : July 2012 | ||
copyright : (C) 2012 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QFile> | ||
#include <QDomDocument> | ||
#include <QTextStream> | ||
|
||
#include "qgsscaleutils.h" | ||
|
||
bool QgsScaleUtils::saveScaleList( const QString &fileName, const QStringList &scales, QString &errorMessage ) | ||
{ | ||
QDomDocument doc; | ||
QDomElement root = doc.createElement( "qgsScales" ); | ||
root.setAttribute( "version", "1.0" ); | ||
doc.appendChild( root ); | ||
|
||
for ( int i = 0; i < scales.count(); ++i ) | ||
{ | ||
QDomElement el = doc.createElement( "scale" ); | ||
el.setAttribute( "value", scales.at( i ) ); | ||
root.appendChild( el ); | ||
} | ||
|
||
QFile file( fileName ); | ||
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) | ||
{ | ||
errorMessage = QString( "Cannot write file %1:\n%2." ).arg( fileName ).arg( file.errorString() ); | ||
return false; | ||
} | ||
|
||
QTextStream out( &file ); | ||
doc.save( out, 4 ); | ||
return true; | ||
} | ||
|
||
bool QgsScaleUtils::loadScaleList( const QString &fileName, QStringList &scales, QString &errorMessage ) | ||
{ | ||
QFile file( fileName ); | ||
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) | ||
{ | ||
errorMessage = QString( "Cannot read file %1:\n%2." ).arg( fileName ).arg( file.errorString() ); | ||
return false; | ||
} | ||
|
||
QDomDocument doc; | ||
QString errorStr; | ||
int errorLine; | ||
int errorColumn; | ||
|
||
if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) ) | ||
{ | ||
errorMessage = QString( "Parse error at line %1, column %2:\n%3" ) | ||
.arg( errorLine ) | ||
.arg( errorColumn ) | ||
.arg( errorStr ); | ||
return false; | ||
} | ||
|
||
QDomElement root = doc.documentElement(); | ||
if ( root.tagName() != "qgsScales" ) | ||
{ | ||
errorMessage = "The file is not an scales exchange file."; | ||
return false; | ||
} | ||
|
||
QDomElement child = root.firstChildElement(); | ||
while ( !child.isNull() ) | ||
{ | ||
scales.append( child.attribute( "value" ) ); | ||
child = child.nextSiblingElement(); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*************************************************************************** | ||
qgscaleutils.h | ||
---------------------- | ||
begin : July 2012 | ||
copyright : (C) 2012 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QString> | ||
#include <QStringList> | ||
|
||
#ifndef QGSSCALEUTILS_H | ||
#define QGSSCALEUTILS_H | ||
|
||
class CORE_EXPORT QgsScaleUtils | ||
{ | ||
public: | ||
/** save scales to the given file | ||
* @param fileName the name of the output file | ||
* @param scales the list of scales to save | ||
* @param errorMessage it will contain the error message if something | ||
* went wrong | ||
* @return true on success and false if failed | ||
*/ | ||
static bool saveScaleList( const QString &fileName, const QStringList &scales, QString &errorMessage ); | ||
|
||
/** load scales from the given file | ||
* @param fileName the name of the file to process | ||
* @param scales it will contain loaded scales | ||
* @param errorMessage it will contain the error message if something | ||
* went wrong | ||
* @return true on success and false if failed | ||
*/ | ||
static bool loadScaleList( const QString &fileName, QStringList &scales, QString &errorMessage ); | ||
}; | ||
|
||
#endif |