QGIS API Documentation  3.21.0-Master (5b68dc587e)
qgsprojectdisplaysettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprojectdisplaysettings.cpp
3  -----------------------------
4  begin : January 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 #include "qgis.h"
20 #include "qgsapplication.h"
22 
23 #include <QDomElement>
24 
26  : QObject( parent )
27  , mBearingFormat( std::make_unique< QgsBearingNumericFormat >() )
28 {
29 
30 }
31 
33 
35 {
36  // inherit local default settings
37  mBearingFormat.reset( QgsLocalDefaultSettings::bearingFormat() );
38 
39  emit bearingFormatChanged();
40 }
41 
43 {
44  mBearingFormat.reset( format );
45  emit bearingFormatChanged();
46 }
47 
49 {
50  return mBearingFormat.get();
51 }
52 
53 bool QgsProjectDisplaySettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
54 {
55  const QDomElement bearingElement = element.firstChildElement( QStringLiteral( "BearingFormat" ) );
56  mBearingFormat.reset( static_cast< QgsBearingNumericFormat * >( QgsApplication::numericFormatRegistry()->createFromXml( bearingElement, context ) ) );
57  emit bearingFormatChanged();
58 
59  return true;
60 }
61 
62 QDomElement QgsProjectDisplaySettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
63 {
64  QDomElement element = doc.createElement( QStringLiteral( "ProjectDisplaySettings" ) );
65 
66  QDomElement bearingElement = doc.createElement( QStringLiteral( "BearingFormat" ) );
67  mBearingFormat->writeXml( bearingElement, doc, context );
68  element.appendChild( bearingElement );
69 
70  return element;
71 }
static QgsNumericFormatRegistry * numericFormatRegistry()
Gets the registry of available numeric formats.
A numeric formatter which returns a text representation of a direction/bearing.
static QgsBearingNumericFormat * bearingFormat()
Returns the default bearing format, which controls how angular bearings are displayed.
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.
QgsProjectDisplaySettings(QObject *parent=nullptr)
Constructor for QgsProjectDisplaySettings with the specified parent object.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the settings's state from a DOM element.
~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.
The class is used as a container of context for various read/write operations on other objects.