diff --git a/python/PyQt6/core/auto_generated/qgsmapunitscale.sip.in b/python/PyQt6/core/auto_generated/qgsmapunitscale.sip.in index afdf55f016f..fe03967ac6b 100644 --- a/python/PyQt6/core/auto_generated/qgsmapunitscale.sip.in +++ b/python/PyQt6/core/auto_generated/qgsmapunitscale.sip.in @@ -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; diff --git a/python/core/auto_generated/qgsmapunitscale.sip.in b/python/core/auto_generated/qgsmapunitscale.sip.in index afdf55f016f..fe03967ac6b 100644 --- a/python/core/auto_generated/qgsmapunitscale.sip.in +++ b/python/core/auto_generated/qgsmapunitscale.sip.in @@ -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; diff --git a/src/core/qgsmapunitscale.cpp b/src/core/qgsmapunitscale.cpp index 70aaf6866ec..c9155f614e7 100644 --- a/src/core/qgsmapunitscale.cpp +++ b/src/core/qgsmapunitscale.cpp @@ -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(); diff --git a/src/core/qgsmapunitscale.h b/src/core/qgsmapunitscale.h index e8859254c52..39a5893f7b3 100644 --- a/src/core/qgsmapunitscale.h +++ b/src/core/qgsmapunitscale.h @@ -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. diff --git a/tests/src/python/test_qgsmapunitscale.py b/tests/src/python/test_qgsmapunitscale.py index 9932ca010fc..f15424a3c6f 100644 --- a/tests/src/python/test_qgsmapunitscale.py +++ b/tests/src/python/test_qgsmapunitscale.py @@ -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