20#include <QDomDocument>
27 QDomElement root = doc.createElement( u
"qgsScales"_s );
28 root.setAttribute( u
"version"_s, u
"1.0"_s );
29 doc.appendChild( root );
31 for (
int i = 0; i < scales.count(); ++i )
33 QDomElement el = doc.createElement( u
"scale"_s );
34 el.setAttribute( u
"value"_s, scales.at( i ) );
35 root.appendChild( el );
38 QFile file( fileName );
39 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
41 errorMessage = u
"Cannot write file %1:\n%2."_s.arg( fileName, file.errorString() );
45 QTextStream out( &file );
52 QFile file( fileName );
53 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
55 errorMessage = u
"Cannot read file %1:\n%2."_s.arg( fileName, file.errorString() );
64 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
66 errorMessage = u
"Parse error at line %1, column %2:\n%3"_s
73 const QDomElement root = doc.documentElement();
74 if ( root.tagName() !=
"qgsScales"_L1 )
76 errorMessage = u
"The file is not an scales exchange file."_s;
80 QDomElement child = root.firstChildElement();
81 while ( !child.isNull() )
83 scales.append( child.attribute( u
"value"_s ) );
84 child = child.nextSiblingElement();
92 return scale > minScale ||
qgsDoubleNear( scale, minScale, 1E-8 );
97 return scale < maxScale && !
qgsDoubleNear( scale, maxScale, 1E-8 );
static bool equalToOrGreaterThanMinimumScale(const double scale, const double minScale)
Returns whether the scale is equal to or greater than the minScale, taking non-round numbers into acc...
static bool lessThanMaximumScale(const double scale, const double maxScale)
Returns whether the scale is less than the maxScale, taking non-round numbers into account.
static bool loadScaleList(const QString &fileName, QStringList &scales, QString &errorMessage)
Load scales from the given file.
static bool saveScaleList(const QString &fileName, const QStringList &scales, QString &errorMessage)
Save scales to the given file.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).