21 #include <QDomElement>
36 const bool fullExtentChanged = !mPresetFullExtent.
isNull();
38 if ( fullExtentChanged )
41 if ( mUseProjectScales || !mMapScales.empty() )
43 mUseProjectScales =
false;
51 return mDefaultViewExtent;
56 mDefaultViewExtent = extent;
61 return mPresetFullExtent;
66 if ( extent == mPresetFullExtent )
69 mPresetFullExtent = extent;
76 return mPresetFullExtent;
78 if ( !mPresetFullExtent.
isNull() )
86 const QList< QgsMapLayer * > layers = mProject->
mapLayers(
true ).values();
88 QList< QgsMapLayer * > nonBaseMapLayers;
89 std::copy_if( layers.begin(), layers.end(),
90 std::back_inserter( nonBaseMapLayers ),
91 [](
const QgsMapLayer * layer ) { return !( layer->properties() & Qgis::MapLayerProperty::IsBasemapLayer ); } );
94 if ( !nonBaseMapLayers.empty( ) )
104 QVector< double > sorted = scales;
105 std::sort( sorted.begin(), sorted.end(), std::greater<double>() );
125 mUseProjectScales = enabled;
131 return mUseProjectScales;
136 return mDefaultRotation;
141 mDefaultRotation = rotation;
146 const bool useProjectScale = element.attribute( QStringLiteral(
"UseProjectScales" ), QStringLiteral(
"0" ) ).toInt();
148 QDomNodeList scalesNodes = element.elementsByTagName( QStringLiteral(
"Scales" ) );
149 QVector< double > newScales;
150 if ( !scalesNodes.isEmpty() )
152 const QDomElement scalesElement = scalesNodes.at( 0 ).toElement();
153 scalesNodes = scalesElement.elementsByTagName( QStringLiteral(
"Scale" ) );
154 for (
int i = 0; i < scalesNodes.count(); i++ )
156 const QDomElement scaleElement = scalesNodes.at( i ).toElement();
157 newScales.append( scaleElement.attribute( QStringLiteral(
"Value" ) ).toDouble() );
160 if ( useProjectScale != mUseProjectScales || newScales != mMapScales )
162 mMapScales = newScales;
163 mUseProjectScales = useProjectScale;
167 const QDomElement defaultViewElement = element.firstChildElement( QStringLiteral(
"DefaultViewExtent" ) );
168 if ( !defaultViewElement.isNull() )
170 const double xMin = defaultViewElement.attribute( QStringLiteral(
"xmin" ) ).toDouble();
171 const double yMin = defaultViewElement.attribute( QStringLiteral(
"ymin" ) ).toDouble();
172 const double xMax = defaultViewElement.attribute( QStringLiteral(
"xmax" ) ).toDouble();
173 const double yMax = defaultViewElement.attribute( QStringLiteral(
"ymax" ) ).toDouble();
183 const QDomElement presetViewElement = element.firstChildElement( QStringLiteral(
"PresetFullExtent" ) );
184 if ( !presetViewElement.isNull() )
186 const double xMin = presetViewElement.attribute( QStringLiteral(
"xmin" ) ).toDouble();
187 const double yMin = presetViewElement.attribute( QStringLiteral(
"ymin" ) ).toDouble();
188 const double xMax = presetViewElement.attribute( QStringLiteral(
"xmax" ) ).toDouble();
189 const double yMax = presetViewElement.attribute( QStringLiteral(
"ymax" ) ).toDouble();
199 mDefaultRotation = element.attribute( QStringLiteral(
"rotation" ), QStringLiteral(
"0" ) ).toDouble();
206 QDomElement element = doc.createElement( QStringLiteral(
"ProjectViewSettings" ) );
207 element.setAttribute( QStringLiteral(
"UseProjectScales" ), mUseProjectScales ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
209 element.setAttribute( QStringLiteral(
"rotation" ),
qgsDoubleToString( mDefaultRotation ) );
211 QDomElement scales = doc.createElement( QStringLiteral(
"Scales" ) );
212 for (
const double scale : mMapScales )
214 QDomElement scaleElement = doc.createElement( QStringLiteral(
"Scale" ) );
215 scaleElement.setAttribute( QStringLiteral(
"Value" ),
qgsDoubleToString( scale ) );
216 scales.appendChild( scaleElement );
218 element.appendChild( scales );
220 if ( !mDefaultViewExtent.
isNull() )
222 QDomElement defaultViewElement = doc.createElement( QStringLiteral(
"DefaultViewExtent" ) );
227 mDefaultViewExtent.
crs().
writeXml( defaultViewElement, doc );
228 element.appendChild( defaultViewElement );
231 if ( !mPresetFullExtent.
isNull() )
233 QDomElement presetViewElement = doc.createElement( QStringLiteral(
"PresetFullExtent" ) );
238 mPresetFullExtent.
crs().
writeXml( presetViewElement, doc );
239 element.appendChild( presetViewElement );