18 #include <QDomElement>
29 if ( mUseProjectScales || !mMapScales.empty() )
31 mUseProjectScales =
false;
39 return mDefaultViewExtent;
44 mDefaultViewExtent = extent;
50 QVector< double > sorted = scales;
51 std::sort( sorted.begin(), sorted.end(), std::greater<double>() );
71 mUseProjectScales = enabled;
77 return mUseProjectScales;
82 bool useProjectScale = element.attribute( QStringLiteral(
"UseProjectScales" ), QStringLiteral(
"0" ) ).toInt();
84 QDomNodeList scalesNodes = element.elementsByTagName( QStringLiteral(
"Scales" ) );
85 QVector< double > newScales;
86 if ( !scalesNodes.isEmpty() )
88 QDomElement scalesElement = scalesNodes.at( 0 ).toElement();
89 scalesNodes = scalesElement.elementsByTagName( QStringLiteral(
"Scale" ) );
90 for (
int i = 0; i < scalesNodes.count(); i++ )
92 QDomElement scaleElement = scalesNodes.at( i ).toElement();
93 newScales.append( scaleElement.attribute( QStringLiteral(
"Value" ) ).toDouble() );
96 if ( useProjectScale != mUseProjectScales || newScales != mMapScales )
98 mMapScales = newScales;
99 mUseProjectScales = useProjectScale;
103 QDomElement defaultViewElement = element.firstChildElement( QStringLiteral(
"DefaultViewExtent" ) );
104 if ( !defaultViewElement.isNull() )
106 double xMin = defaultViewElement.attribute( QStringLiteral(
"xmin" ) ).toDouble();
107 double yMin = defaultViewElement.attribute( QStringLiteral(
"ymin" ) ).toDouble();
108 double xMax = defaultViewElement.attribute( QStringLiteral(
"xmax" ) ).toDouble();
109 double yMax = defaultViewElement.attribute( QStringLiteral(
"ymax" ) ).toDouble();
124 QDomElement element = doc.createElement( QStringLiteral(
"ProjectViewSettings" ) );
125 element.setAttribute( QStringLiteral(
"UseProjectScales" ), mUseProjectScales ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
127 QDomElement scales = doc.createElement( QStringLiteral(
"Scales" ) );
128 for (
double scale : mMapScales )
130 QDomElement scaleElement = doc.createElement( QStringLiteral(
"Scale" ) );
131 scaleElement.setAttribute( QStringLiteral(
"Value" ),
qgsDoubleToString( scale ) );
132 scales.appendChild( scaleElement );
134 element.appendChild( scales );
136 if ( !mDefaultViewExtent.
isNull() )
138 QDomElement defaultViewElement = doc.createElement( QStringLiteral(
"DefaultViewExtent" ) );
143 mDefaultViewExtent.
crs().
writeXml( defaultViewElement, doc );
144 element.appendChild( defaultViewElement );