Skip to content

Commit

Permalink
New class QgsProjectDisplaySettings
Browse files Browse the repository at this point in the history
This class (attached to a QgsProject object) provides a place to
store and retrieve settings related to project display behavior,
e.g. the numeric formats used for bearings and coordinates
  • Loading branch information
nyalldawson committed Jan 9, 2020
1 parent 0ba2bcc commit 410da5e
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/core/auto_generated/qgsproject.sip.in
Expand Up @@ -575,6 +575,15 @@ relating to how a QgsProject should be viewed and behave inside a map canvas
.. versionadded:: 3.10.1
%End


QgsProjectDisplaySettings *displaySettings();
%Docstring
Returns the project's display settings, which settings and properties relating
to how a QgsProject should display values such as map coordinates and bearings.

.. versionadded:: 3.12
%End

QgsLayerTree *layerTreeRoot() const;
%Docstring
Returns pointer to the root (invisible) node of the project's layer tree
Expand Down
90 changes: 90 additions & 0 deletions python/core/auto_generated/qgsprojectdisplaysettings.sip.in
@@ -0,0 +1,90 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsprojectdisplaysettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsProjectDisplaySettings : QObject
{
%Docstring
Contains settings and properties relating to how a QgsProject should display
values such as map coordinates and bearings.

.. versionadded:: 3.12
%End

%TypeHeaderCode
#include "qgsprojectdisplaysettings.h"
%End
public:

QgsProjectDisplaySettings( QObject *parent = 0 );
%Docstring
Constructor for QgsProjectDisplaySettings with the specified ``parent`` object.
%End

~QgsProjectDisplaySettings();

void reset();
%Docstring
Resets the settings to a default state.
%End

void setBearingFormat( QgsBearingNumericFormat *format /Transfer/ );
%Docstring
Sets the project bearing ``format``, which controls how bearings associated with the project are displayed.

Ownership of ``format`` is transferred to the settings.

.. seealso:: :py:func:`bearingFormat`

.. seealso:: :py:func:`bearingFormatChanged`
%End

const QgsBearingNumericFormat *bearingFormat() const;
%Docstring
Returns the project bearing's format, which controls how bearings associated with the project are displayed.

.. seealso:: :py:func:`setBearingFormat`

.. seealso:: :py:func:`bearingFormatChanged`
%End

bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
%Docstring
Reads the settings's state from a DOM element.

.. seealso:: :py:func:`writeXml`
%End

QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
%Docstring
Returns a DOM element representing the settings.

.. seealso:: :py:func:`readXml`
%End

signals:

void bearingFormatChanged();
%Docstring
Emitted when the bearing format changes.

.. seealso:: :py:func:`setBearingFormat`

.. seealso:: :py:func:`bearingFormat`
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsprojectdisplaysettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -144,6 +144,7 @@
%Include auto_generated/qgspostgresstringutils.sip
%Include auto_generated/qgsproject.sip
%Include auto_generated/qgsprojectbadlayerhandler.sip
%Include auto_generated/qgsprojectdisplaysettings.sip
%Include auto_generated/qgsprojectfiletransform.sip
%Include auto_generated/qgsprojectproperty.sip
%Include auto_generated/qgsprojectstorage.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -332,6 +332,7 @@ SET(QGIS_CORE_SRCS
qgsprojectbadlayerhandler.cpp
qgsprojectfiletransform.cpp
qgssnappingconfig.cpp
qgsprojectdisplaysettings.cpp
qgsprojectproperty.cpp
qgsprojectstorage.cpp
qgsprojectstorageregistry.cpp
Expand Down Expand Up @@ -832,6 +833,7 @@ SET(QGIS_CORE_HDRS
qgspostgresstringutils.h
qgsproject.h
qgsprojectbadlayerhandler.h
qgsprojectdisplaysettings.h
qgsprojectfiletransform.h
qgsprojectproperty.h
qgsprojectstorage.h
Expand Down
20 changes: 20 additions & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -58,6 +58,7 @@
#include "qgsexpressioncontextutils.h"
#include "qgsstyleentityvisitor.h"
#include "qgsprojectviewsettings.h"
#include "qgsprojectdisplaysettings.h"

#include <algorithm>
#include <QApplication>
Expand Down Expand Up @@ -363,6 +364,7 @@ QgsProject::QgsProject( QObject *parent )
, mLayoutManager( new QgsLayoutManager( this ) )
, mBookmarkManager( QgsBookmarkManager::createProjectBasedManager( this ) )
, mViewSettings( new QgsProjectViewSettings( this ) )
, mDisplaySettings( new QgsProjectDisplaySettings( this ) )
, mRootGroup( new QgsLayerTree )
, mLabelingEngineSettings( new QgsLabelingEngineSettings )
, mArchive( new QgsProjectArchive() )
Expand Down Expand Up @@ -748,6 +750,7 @@ void QgsProject::clear()
mLayoutManager->clear();
mBookmarkManager->clear();
mViewSettings->reset();
mDisplaySettings->reset();
mSnappingConfig.reset();
emit snappingConfigChanged( mSnappingConfig );
emit topologicalEditingChanged();
Expand Down Expand Up @@ -1504,6 +1507,10 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags
if ( !viewSettingsElement.isNull() )
mViewSettings->readXml( viewSettingsElement, context );

QDomElement displaySettingsElement = doc->documentElement().firstChildElement( QStringLiteral( "ProjectDisplaySettings" ) );
if ( !displaySettingsElement.isNull() )
mDisplaySettings->readXml( displaySettingsElement, context );

emit customVariablesChanged();
emit crsChanged();
emit ellipsoidChanged( ellipsoid() );
Expand Down Expand Up @@ -2104,6 +2111,9 @@ bool QgsProject::writeProjectFile( const QString &filename )
QDomElement viewSettingsElem = mViewSettings->writeXml( *doc, context );
qgisNode.appendChild( viewSettingsElem );

QDomElement displaySettingsElem = mDisplaySettings->writeXml( *doc, context );
qgisNode.appendChild( displaySettingsElem );

// now wrap it up and ship it to the project file
doc->normalize(); // XXX I'm not entirely sure what this does

Expand Down Expand Up @@ -2809,6 +2819,16 @@ QgsProjectViewSettings *QgsProject::viewSettings()
return mViewSettings;
}

const QgsProjectDisplaySettings *QgsProject::displaySettings() const
{
return mDisplaySettings;
}

QgsProjectDisplaySettings *QgsProject::displaySettings()
{
return mDisplaySettings;
}

QgsLayerTree *QgsProject::layerTreeRoot() const
{
return mRootGroup;
Expand Down
18 changes: 18 additions & 0 deletions src/core/qgsproject.h
Expand Up @@ -73,6 +73,7 @@ class QgsAuxiliaryStorage;
class QgsMapLayer;
class QgsBookmarkManager;
class QgsProjectViewSettings;
class QgsProjectDisplaySettings;

/**
* \ingroup core
Expand Down Expand Up @@ -580,6 +581,21 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
QgsProjectViewSettings *viewSettings();

/**
* Returns the project's display settings, which settings and properties relating
* to how a QgsProject should display values such as map coordinates and bearings.
* \note not available in Python bindings
* \since QGIS 3.12
*/
const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;

/**
* Returns the project's display settings, which settings and properties relating
* to how a QgsProject should display values such as map coordinates and bearings.
* \since QGIS 3.12
*/
QgsProjectDisplaySettings *displaySettings();

/**
* Returns pointer to the root (invisible) node of the project's layer tree
* \since QGIS 2.4
Expand Down Expand Up @@ -1744,6 +1760,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera

QgsProjectViewSettings *mViewSettings = nullptr;

QgsProjectDisplaySettings *mDisplaySettings = nullptr;

QgsLayerTree *mRootGroup = nullptr;

QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
Expand Down
69 changes: 69 additions & 0 deletions src/core/qgsprojectdisplaysettings.cpp
@@ -0,0 +1,69 @@
/***************************************************************************
qgsprojectdisplaysettings.cpp
-----------------------------
begin : January 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsprojectdisplaysettings.h"
#include "qgis.h"
#include "qgsbearingnumericformat.h"
#include "qgsnumericformatregistry.h"
#include "qgsapplication.h"

#include <QDomElement>

QgsProjectDisplaySettings::QgsProjectDisplaySettings( QObject *parent )
: QObject( parent )
, mBearingFormat( qgis::make_unique< QgsBearingNumericFormat >() )
{

}

QgsProjectDisplaySettings::~QgsProjectDisplaySettings() = default;

void QgsProjectDisplaySettings::reset()
{
mBearingFormat = qgis::make_unique< QgsBearingNumericFormat >();

emit bearingFormatChanged();
}

void QgsProjectDisplaySettings::setBearingFormat( QgsBearingNumericFormat *format )
{
mBearingFormat.reset( format );
emit bearingFormatChanged();
}

const QgsBearingNumericFormat *QgsProjectDisplaySettings::bearingFormat() const
{
return mBearingFormat.get();
}

bool QgsProjectDisplaySettings::readXml( const QDomElement &element, const QgsReadWriteContext &context )
{
QDomElement bearingElement = element.firstChildElement( QStringLiteral( "BearingFormat" ) );
mBearingFormat.reset( static_cast< QgsBearingNumericFormat * >( QgsApplication::numericFormatRegistry()->createFromXml( bearingElement, context ) ) );
emit bearingFormatChanged();

return true;
}

QDomElement QgsProjectDisplaySettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
{
QDomElement element = doc.createElement( QStringLiteral( "ProjectDisplaySettings" ) );

QDomElement bearingElement = doc.createElement( QStringLiteral( "BearingFormat" ) );
mBearingFormat->writeXml( bearingElement, doc, context );
element.appendChild( bearingElement );

return element;
}

0 comments on commit 410da5e

Please sign in to comment.