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();
111 crs.
readXml( defaultViewElement );
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 );
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the settings's state from a DOM element.
QgsReferencedRectangle defaultViewExtent() const
Returns the default view extent, which should be used as the initial map extent when this project is ...
bool useProjectScales() const
Returns true if project mapScales() are enabled.
const QgsCoordinateReferenceSystem & crs
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Returns a DOM element representing the settings.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set...
void setMapScales(const QVector< double > &scales)
Sets the list of custom project map scales.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QVector< double > mapScales() const
Returns the list of custom project map scales.
void setUseProjectScales(bool enabled)
Sets whether project mapScales() are enabled.
A QgsRectangle with associated coordinate reference system.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsProjectViewSettings(QObject *parent=nullptr)
Constructor for QgsProjectViewSettings with the specified parent object.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
This class represents a coordinate reference system (CRS).
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void mapScalesChanged()
Emitted when the list of custom project map scales changes.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void setDefaultViewExtent(const QgsReferencedRectangle &extent)
Sets the default view extent, which should be used as the initial map extent when this project is ope...
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
void reset()
Resets the settings to a default state.