28#include "moc_qgsprojectdisplaysettings.cpp"
35 if (
QgsProject *project = qobject_cast< QgsProject * >( parent ) )
55 updateCoordinateCrs();
66 mBearingFormat.reset( format );
72 return mBearingFormat.get();
77 mGeographicCoordinateFormat.reset( format );
83 return mGeographicCoordinateFormat.get();
88 if ( mCoordinateType == type )
91 mCoordinateType = type;
92 updateCoordinateCrs();
99 if ( mCoordinateAxisOrder == order )
102 mCoordinateAxisOrder = order;
108 if ( mCoordinateCustomCrs == crs )
111 mCoordinateCustomCrs = crs;
114 updateCoordinateCrs();
119void QgsProjectDisplaySettings::updateCoordinateCrs()
121 if (
QgsProject *project = qobject_cast< QgsProject * >( parent() ) )
125 switch ( mCoordinateType )
136 crs = mCoordinateCustomCrs;
140 if ( mCoordinateCrs != crs )
142 mCoordinateCrs = crs;
151 const QDomElement bearingElement = element.firstChildElement( QStringLiteral(
"BearingFormat" ) );
156 QgsProject *project = qobject_cast< QgsProject * >( parent() );
159 const QDomElement geographicElement = element.firstChildElement( QStringLiteral(
"GeographicCoordinateFormat" ) );
160 if ( !geographicElement.isNull() )
168 const QString format = project->
readEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DegreeFormat" ), QString(), &ok );
171 mGeographicCoordinateFormat = std::make_unique< QgsGeographicCoordinateNumericFormat >();
172 mGeographicCoordinateFormat->setShowDirectionalSuffix(
true );
173 if ( format == QLatin1String(
"DM" ) )
175 else if ( format == QLatin1String(
"DMS" ) )
193 if ( element.hasAttribute( QStringLiteral(
"CoordinateType" ) ) )
199 const QString format = project->
readEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DegreeFormat" ), QString() );
200 if ( !format.isEmpty() )
202 if ( format != QLatin1String(
"MU" ) && !project->
crs().
isGeographic() )
213 QDomNodeList crsNodeList = element.elementsByTagName( QStringLiteral(
"CoordinateCustomCrs" ) );
214 if ( !crsNodeList.isEmpty() )
216 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
217 mCoordinateCustomCrs.readXml( crsElem );
223 if ( element.hasAttribute( QStringLiteral(
"CoordinateAxisOrder" ) ) )
237 QDomElement element = doc.createElement( QStringLiteral(
"ProjectDisplaySettings" ) );
240 QDomElement bearingElement = doc.createElement( QStringLiteral(
"BearingFormat" ) );
241 mBearingFormat->writeXml( bearingElement, doc, context );
242 element.appendChild( bearingElement );
246 QDomElement geographicElement = doc.createElement( QStringLiteral(
"GeographicCoordinateFormat" ) );
247 mGeographicCoordinateFormat->writeXml( geographicElement, doc, context );
248 element.appendChild( geographicElement );
251 element.setAttribute( QStringLiteral(
"CoordinateType" ),
qgsEnumValueToKey( mCoordinateType ) );
252 if ( mCoordinateCustomCrs.isValid() )
254 QDomElement crsElem = doc.createElement( QStringLiteral(
"CoordinateCustomCrs" ) );
255 mCoordinateCustomCrs.writeXml( crsElem, doc );
256 element.appendChild( crsElem );
259 element.setAttribute( QStringLiteral(
"CoordinateAxisOrder" ),
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.