Add method to test if QgsMapUnitScale is null

This commit is contained in:
Nyall Dawson 2025-04-14 13:51:33 +10:00
parent 4a0ea094fb
commit 255d4b3ce2
5 changed files with 62 additions and 0 deletions

View File

@ -36,6 +36,14 @@ Constructor for QgsMapUnitScale
1000.0 for a 1:1000 map.
%End
bool isNull() const;
%Docstring
Returns ``True`` if the scale is null, i.e. it is a default constructed
QgsMapUnitScale.
.. versionadded:: 3.44
%End
double minScale;
double maxScale;

View File

@ -36,6 +36,14 @@ Constructor for QgsMapUnitScale
1000.0 for a 1:1000 map.
%End
bool isNull() const;
%Docstring
Returns ``True`` if the scale is null, i.e. it is a default constructed
QgsMapUnitScale.
.. versionadded:: 3.44
%End
double minScale;
double maxScale;

View File

@ -17,6 +17,16 @@
#include "qgsmapunitscale.h"
#include "qgsrendercontext.h"
bool QgsMapUnitScale::isNull() const
{
return qgsDoubleNear( minScale, 0 )
&& qgsDoubleNear( maxScale, 0 )
&& !minSizeMMEnabled
&& qgsDoubleNear( minSizeMM, 0 )
&& !maxSizeMMEnabled
&& qgsDoubleNear( maxSizeMM, 0 );
}
double QgsMapUnitScale::computeMapUnitsPerPixel( const QgsRenderContext &c ) const
{
double mup = c.mapToPixel().mapUnitsPerPixel();

View File

@ -48,6 +48,13 @@ class CORE_EXPORT QgsMapUnitScale
, maxScale( maxScale )
{}
/**
* Returns TRUE if the scale is null, i.e. it is a default constructed QgsMapUnitScale.
*
* \since QGIS 3.44
*/
bool isNull() const;
/**
* The minimum scale, or 0.0 if unset.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

View File

@ -74,6 +74,35 @@ class PyQgsMapUnitScale(unittest.TestCase):
self.assertEqual(c1, c2)
def testIsNull(self):
# test isNull
c1 = QgsMapUnitScale()
self.assertTrue(c1.isNull())
c1 = QgsMapUnitScale()
c1.minScale = 1000
self.assertFalse(c1.isNull())
c1 = QgsMapUnitScale()
c1.maxScale = 1000
self.assertFalse(c1.isNull())
c1 = QgsMapUnitScale()
c1.minSizeMMEnabled = True
self.assertFalse(c1.isNull())
c1 = QgsMapUnitScale()
c1.maxSizeMMEnabled = True
self.assertFalse(c1.isNull())
c1 = QgsMapUnitScale()
c1.minSizeMM = 3
self.assertFalse(c1.isNull())
c1 = QgsMapUnitScale()
c1.maxSizeMM = 3
self.assertFalse(c1.isNull())
def testMapUnitsPerPixel(self):
# test computeMapUnitsPerPixel