29#include "moc_qgsprojectdisplaysettings.cpp"
31using namespace Qt::StringLiterals;
38 if (
QgsProject *project = qobject_cast< QgsProject * >( parent ) )
58 updateCoordinateCrs();
69 mBearingFormat.reset( format );
75 return mBearingFormat.get();
80 mGeographicCoordinateFormat.reset( format );
86 return mGeographicCoordinateFormat.get();
91 if ( mCoordinateType == type )
94 mCoordinateType = type;
95 updateCoordinateCrs();
102 if ( mCoordinateAxisOrder == order )
105 mCoordinateAxisOrder = order;
111 if ( mCoordinateCustomCrs == crs )
114 mCoordinateCustomCrs = crs;
117 updateCoordinateCrs();
122void QgsProjectDisplaySettings::updateCoordinateCrs()
124 if (
QgsProject *project = qobject_cast< QgsProject * >( parent() ) )
128 switch ( mCoordinateType )
139 crs = mCoordinateCustomCrs;
143 if ( mCoordinateCrs != crs )
145 mCoordinateCrs = crs;
154 const QDomElement bearingElement = element.firstChildElement( u
"BearingFormat"_s );
159 QgsProject *project = qobject_cast< QgsProject * >( parent() );
162 const QDomElement geographicElement = element.firstChildElement( u
"GeographicCoordinateFormat"_s );
163 if ( !geographicElement.isNull() )
171 const QString format = project->
readEntry( u
"PositionPrecision"_s, u
"/DegreeFormat"_s, QString(), &ok );
174 mGeographicCoordinateFormat = std::make_unique< QgsGeographicCoordinateNumericFormat >();
175 mGeographicCoordinateFormat->setShowDirectionalSuffix(
true );
176 if ( format ==
"DM"_L1 )
178 else if ( format ==
"DMS"_L1 )
196 if ( element.hasAttribute( u
"CoordinateType"_s ) )
202 const QString format = project->
readEntry( u
"PositionPrecision"_s, u
"/DegreeFormat"_s, QString() );
203 if ( !format.isEmpty() )
216 QDomNodeList crsNodeList = element.elementsByTagName( u
"CoordinateCustomCrs"_s );
217 if ( !crsNodeList.isEmpty() )
219 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
220 mCoordinateCustomCrs.readXml( crsElem );
226 if ( element.hasAttribute( u
"CoordinateAxisOrder"_s ) )
240 QDomElement element = doc.createElement( u
"ProjectDisplaySettings"_s );
243 QDomElement bearingElement = doc.createElement( u
"BearingFormat"_s );
244 mBearingFormat->writeXml( bearingElement, doc, context );
245 element.appendChild( bearingElement );
249 QDomElement geographicElement = doc.createElement( u
"GeographicCoordinateFormat"_s );
250 mGeographicCoordinateFormat->writeXml( geographicElement, doc, context );
251 element.appendChild( geographicElement );
254 element.setAttribute( u
"CoordinateType"_s,
qgsEnumValueToKey( mCoordinateType ) );
255 if ( mCoordinateCustomCrs.isValid() )
257 QDomElement crsElem = doc.createElement( u
"CoordinateCustomCrs"_s );
258 mCoordinateCustomCrs.writeXml( crsElem, doc );
259 element.appendChild( crsElem );
262 element.setAttribute( u
"CoordinateAxisOrder"_s,
qgsEnumValueToKey( mCoordinateAxisOrder ) );
CoordinateDisplayType
Formats for displaying coordinates.
@ 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.
Represents a coordinate reference system (CRS).
QgsCoordinateReferenceSystem toGeographicCrs() const
Returns the geographic CRS associated with this CRS object.
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
A container for the context for various read/write operations on 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.