20#include <QDomDocument>
25using namespace Qt::StringLiterals;
30 QDomElement root = doc.createElement( u
"qgsScales"_s );
31 root.setAttribute( u
"version"_s, u
"1.0"_s );
32 doc.appendChild( root );
34 for (
int i = 0; i < scales.count(); ++i )
36 QDomElement el = doc.createElement( u
"scale"_s );
37 el.setAttribute( u
"value"_s, scales.at( i ) );
38 root.appendChild( el );
41 QFile file( fileName );
42 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
44 errorMessage = u
"Cannot write file %1:\n%2."_s.arg( fileName, file.errorString() );
48 QTextStream out( &file );
55 QFile file( fileName );
56 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
58 errorMessage = u
"Cannot read file %1:\n%2."_s.arg( fileName, file.errorString() );
67 if ( !doc.setContent( &file,
true, &errorStr, &errorLine, &errorColumn ) )
69 errorMessage = u
"Parse error at line %1, column %2:\n%3"_s
76 const QDomElement root = doc.documentElement();
77 if ( root.tagName() !=
"qgsScales"_L1 )
79 errorMessage = u
"The file is not an scales exchange file."_s;
83 QDomElement child = root.firstChildElement();
84 while ( !child.isNull() )
86 scales.append( child.attribute( u
"value"_s ) );
87 child = child.nextSiblingElement();
95 return scale > minScale ||
qgsDoubleNear( scale, minScale, 1E-8 );
100 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).