Skip to content
Permalink
Browse files

QgsProjectDisplaySettings should inherit bearing format from local de…

…fault settings

when reset

This ensures that newly created projects will correctly use the profile's default
bearing format
  • Loading branch information
nyalldawson committed Jan 8, 2020
1 parent 1f7140b commit 338dcae6a3ee27fa214240a61a9bca1c47223626
Showing with 43 additions and 8 deletions.
  1. +3 −1 src/core/qgsprojectdisplaysettings.cpp
  2. +40 −7 tests/src/python/test_qgsprojectdisplaysettings.py
@@ -18,6 +18,7 @@
#include "qgsbearingnumericformat.h"
#include "qgsnumericformatregistry.h"
#include "qgsapplication.h"
#include "qgslocaldefaultsettings.h"

#include <QDomElement>

@@ -32,7 +33,8 @@ QgsProjectDisplaySettings::~QgsProjectDisplaySettings() = default;

void QgsProjectDisplaySettings::reset()
{
mBearingFormat = qgis::make_unique< QgsBearingNumericFormat >();
// inherit local default settings
mBearingFormat.reset( QgsLocalDefaultSettings::bearingFormat() );

emit bearingFormatChanged();
}
@@ -12,15 +12,16 @@

import qgis # NOQA

from qgis.core import (QgsProject,
QgsProjectDisplaySettings,
from qgis.core import (QgsProjectDisplaySettings,
QgsReadWriteContext,
QgsBearingNumericFormat)
QgsBearingNumericFormat,
QgsSettings,
QgsLocalDefaultSettings)

from qgis.PyQt.QtCore import QTemporaryDir
from qgis.PyQt.QtCore import QCoreApplication

from qgis.PyQt.QtTest import QSignalSpy
from qgis.PyQt.QtXml import QDomDocument, QDomElement
from qgis.PyQt.QtXml import QDomDocument
from qgis.testing import start_app, unittest
from utilities import (unitTestDataPath)

@@ -30,6 +31,16 @@

class TestQgsProjectDisplaySettings(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests"""

QCoreApplication.setOrganizationName("QGIS_Test")
QCoreApplication.setOrganizationDomain("TestPyQgsWFSProvider.com")
QCoreApplication.setApplicationName("TestPyQgsWFSProvider")
QgsSettings().clear()
start_app()

def testBearingFormat(self):
p = QgsProjectDisplaySettings()

@@ -51,9 +62,31 @@ def testBearingFormat(self):
self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 3)
self.assertEqual(p.bearingFormat().directionFormat(), QgsBearingNumericFormat.UseRangeNegative180ToPositive180)

def testReset(self):
"""
Test that resetting inherits local default settings
"""
format = QgsBearingNumericFormat()
format.setNumberDecimalPlaces(3)
format.setDirectionFormat(QgsBearingNumericFormat.UseRangeNegative180ToPositive180)
p = QgsProjectDisplaySettings()
p.setBearingFormat(format)
self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 3)
self.assertEqual(p.bearingFormat().directionFormat(), QgsBearingNumericFormat.UseRangeNegative180ToPositive180)

# setup a local default bearing format
s = QgsLocalDefaultSettings()
format = QgsBearingNumericFormat()
format.setNumberDecimalPlaces(9)
format.setDirectionFormat(QgsBearingNumericFormat.UseRange0To360)
s.setBearingFormat(format)

spy = QSignalSpy(p.bearingFormatChanged)
p.reset()
self.assertEqual(len(spy), 3)
self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 6)
self.assertEqual(len(spy), 1)
# project should default to local default format
self.assertEqual(p.bearingFormat().numberDecimalPlaces(), 9)
self.assertEqual(p.bearingFormat().directionFormat(), QgsBearingNumericFormat.UseRange0To360)

def testReadWrite(self):
p = QgsProjectDisplaySettings()

0 comments on commit 338dcae

Please sign in to comment.
You can’t perform that action at this time.