mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Add isValid() method for QgsScaleBarRenderer::RendererContext
This commit is contained in:
parent
55d6db6230
commit
4eb6ce1053
@ -55,6 +55,13 @@ custom labeling.
|
||||
|
||||
Flags flags;
|
||||
|
||||
bool isValid() const;
|
||||
%Docstring
|
||||
Returns ``True`` if the context has valid settings.
|
||||
|
||||
.. versionadded:: 3.40
|
||||
%End
|
||||
|
||||
};
|
||||
|
||||
QgsScaleBarRenderer();
|
||||
|
@ -55,6 +55,13 @@ custom labeling.
|
||||
|
||||
Flags flags;
|
||||
|
||||
bool isValid() const;
|
||||
%Docstring
|
||||
Returns ``True`` if the context has valid settings.
|
||||
|
||||
.. versionadded:: 3.40
|
||||
%End
|
||||
|
||||
};
|
||||
|
||||
QgsScaleBarRenderer();
|
||||
|
@ -418,3 +418,8 @@ QList<double> QgsScaleBarRenderer::segmentWidths( const ScaleBarContext &scaleCo
|
||||
|
||||
return widths;
|
||||
}
|
||||
|
||||
bool QgsScaleBarRenderer::ScaleBarContext::isValid() const
|
||||
{
|
||||
return !std::isnan( segmentWidth );
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class CORE_EXPORT QgsScaleBarRenderer
|
||||
* Contains parameters regarding scalebar calculations.
|
||||
* \note The need to attribute the parameters vary depending on the targeted scalebar.
|
||||
*/
|
||||
struct ScaleBarContext
|
||||
struct CORE_EXPORT ScaleBarContext
|
||||
{
|
||||
|
||||
/**
|
||||
@ -88,6 +88,13 @@ class CORE_EXPORT QgsScaleBarRenderer
|
||||
//! Scalebar renderer flags
|
||||
Flags flags;
|
||||
|
||||
/**
|
||||
* Returns TRUE if the context has valid settings.
|
||||
*
|
||||
* \since QGIS 3.40
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
};
|
||||
|
||||
QgsScaleBarRenderer() = default;
|
||||
|
@ -302,6 +302,7 @@ ADD_PYTHON_TEST(PyQgsRenderedItemResults test_qgsrendereditemresults.py)
|
||||
ADD_PYTHON_TEST(PyQgsRenderer test_qgsrenderer.py)
|
||||
ADD_PYTHON_TEST(PyQgsReport test_qgsreport.py)
|
||||
ADD_PYTHON_TEST(PyQgsScaleBarRendererRegistry test_qgsscalebarrendererregistry.py)
|
||||
ADD_PYTHON_TEST(PyQgsScaleBarRenderers test_qgsscalebarrenderers.py)
|
||||
ADD_PYTHON_TEST(PyQgsScaleCalculator test_qgsscalecalculator.py)
|
||||
ADD_PYTHON_TEST(PyQgsSingleBandColorDataRenderer test_qgssinglebandcolordatarenderer.py)
|
||||
ADD_PYTHON_TEST(PyQgsSingleBandGrayRenderer test_qgssinglebandgrayrenderer.py)
|
||||
|
29
tests/src/python/test_qgsscalebarrenderers.py
Normal file
29
tests/src/python/test_qgsscalebarrenderers.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""QGIS Unit tests for scale bar renderers
|
||||
|
||||
.. note:: 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.
|
||||
"""
|
||||
|
||||
import math
|
||||
|
||||
from qgis.core import QgsScaleBarRenderer
|
||||
import unittest
|
||||
from qgis.testing import start_app, QgisTestCase
|
||||
|
||||
start_app()
|
||||
|
||||
|
||||
class TestQgsScaleBarRenderers(QgisTestCase):
|
||||
|
||||
def test_context(self):
|
||||
context = QgsScaleBarRenderer.ScaleBarContext()
|
||||
context.segmentWidth = 5
|
||||
self.assertTrue(context.isValid())
|
||||
context.segmentWidth = math.nan
|
||||
self.assertFalse(context.isValid())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user