32 if (
QgsProject *project = qobject_cast< QgsProject * >( parent ) )
52 updateCoordinateCrs();
63 mBearingFormat.reset( format );
69 return mBearingFormat.get();
74 mGeographicCoordinateFormat.reset( format );
80 return mGeographicCoordinateFormat.get();
85 if ( mCoordinateType == type )
88 mCoordinateType = type;
89 updateCoordinateCrs();
96 if ( mCoordinateAxisOrder == order )
99 mCoordinateAxisOrder = order;
105 if ( mCoordinateCustomCrs ==
crs )
108 mCoordinateCustomCrs =
crs;
111 updateCoordinateCrs();
116void QgsProjectDisplaySettings::updateCoordinateCrs()
118 if (
QgsProject *project = qobject_cast< QgsProject * >( parent() ) )
122 switch ( mCoordinateType )
133 crs = mCoordinateCustomCrs;
137 if ( mCoordinateCrs !=
crs )
139 mCoordinateCrs =
crs;
148 const QDomElement bearingElement = element.firstChildElement( QStringLiteral(
"BearingFormat" ) );
153 QgsProject *project = qobject_cast< QgsProject * >( parent() );
156 const QDomElement geographicElement = element.firstChildElement( QStringLiteral(
"GeographicCoordinateFormat" ) );
157 if ( !geographicElement.isNull() )
165 const QString format = project->
readEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DegreeFormat" ), QString(), &ok );
168 mGeographicCoordinateFormat = std::make_unique< QgsGeographicCoordinateNumericFormat >();
169 mGeographicCoordinateFormat->setShowDirectionalSuffix(
true );
170 if ( format == QLatin1String(
"DM" ) )
172 else if ( format == QLatin1String(
"DMS" ) )
190 if ( element.hasAttribute( QStringLiteral(
"CoordinateType" ) ) )
196 const QString format = project->
readEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DegreeFormat" ), QString() );
197 if ( !format.isEmpty() )
199 if ( format != QLatin1String(
"MU" ) && !project->
crs().
isGeographic() )
210 QDomNodeList crsNodeList = element.elementsByTagName( QStringLiteral(
"CoordinateCustomCrs" ) );
211 if ( !crsNodeList.isEmpty() )
213 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
214 mCoordinateCustomCrs.
readXml( crsElem );
220 if ( element.hasAttribute( QStringLiteral(
"CoordinateAxisOrder" ) ) )
234 QDomElement element = doc.createElement( QStringLiteral(
"ProjectDisplaySettings" ) );
237 QDomElement bearingElement = doc.createElement( QStringLiteral(
"BearingFormat" ) );
238 mBearingFormat->writeXml( bearingElement, doc, context );
239 element.appendChild( bearingElement );
243 QDomElement geographicElement = doc.createElement( QStringLiteral(
"GeographicCoordinateFormat" ) );
244 mGeographicCoordinateFormat->writeXml( geographicElement, doc, context );
245 element.appendChild( geographicElement );
248 element.setAttribute( QStringLiteral(
"CoordinateType" ),
qgsEnumValueToKey( mCoordinateType ) );
249 if ( mCoordinateCustomCrs.
isValid() )
251 QDomElement crsElem = doc.createElement( QStringLiteral(
"CoordinateCustomCrs" ) );
252 mCoordinateCustomCrs.
writeXml( crsElem, doc );
253 element.appendChild( crsElem );
256 element.setAttribute( QStringLiteral(
"CoordinateAxisOrder" ),
qgsEnumValueToKey( mCoordinateAxisOrder ) );
CoordinateDisplayType
Relationship capabilities.
@ MapGeographic
Map Geographic CRS equivalent (stays unchanged if the map CRS is geographic)
CoordinateOrder
Order of coordinates.
@ Default
Respect the default axis ordering for the CRS, as defined in the CRS's parameters.
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
QgsCoordinateReferenceSystem toGeographicCrs() const
Returns the geographic CRS associated with this CRS object.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
static QgsGeographicCoordinateNumericFormat * geographicCoordinateFormat()
Returns the default geographic coordinate format, which controls how geographic coordinates are displ...
static QgsBearingNumericFormat * bearingFormat()
Returns the default bearing format, which controls how angular bearings are displayed.
const QgsGeographicCoordinateNumericFormat * geographicCoordinateFormat() const
Returns the project's geographic coordinate format, which controls how geographic coordinates associa...
void geographicCoordinateFormatChanged()
Emitted when the geographic coordinate format changes.
void setCoordinateAxisOrder(Qgis::CoordinateOrder order)
Sets the default coordinate axis order to use when displaying coordinates for the project.
void setCoordinateCustomCrs(const QgsCoordinateReferenceSystem &crs)
Sets the coordinate custom CRS used when the project coordinate type is set to Qgis....
void coordinateAxisOrderChanged()
Emitted when the default coordinate axis order changes.
void reset()
Resets the settings to a default state.
const QgsBearingNumericFormat * bearingFormat() const
Returns the project bearing's format, which controls how bearings associated with the project are dis...
void bearingFormatChanged()
Emitted when the bearing format changes.
void coordinateCrsChanged()
Emitted when the coordinate CRS changes.
void coordinateTypeChanged()
Emitted when the default coordinate format changes.
QgsProjectDisplaySettings(QObject *parent=nullptr)
Constructor for QgsProjectDisplaySettings with the specified parent object.
void coordinateCustomCrsChanged()
Emitted when the coordinate custom CRS changes.
void setCoordinateType(Qgis::CoordinateDisplayType type)
Sets the default coordinate type for the project.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the settings's state from a DOM element.
void setGeographicCoordinateFormat(QgsGeographicCoordinateNumericFormat *format)
Sets the project geographic coordinate format, which controls how geographic coordinates associated w...
~QgsProjectDisplaySettings() override
void setBearingFormat(QgsBearingNumericFormat *format)
Sets the project bearing format, which controls how bearings associated with the project are displaye...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Returns a DOM element representing the settings.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
void crsChanged()
Emitted when the CRS of the project has changed.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
QgsCoordinateReferenceSystem crs
The class is used as a container of context for various read/write operations on other objects.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
const QgsCoordinateReferenceSystem & crs