Add method to set a list of clipping regions for QgsMapSettings

This commit is contained in:
Nyall Dawson 2020-06-30 16:32:36 +10:00
parent 9a97892107
commit bbd5d80e71
4 changed files with 36 additions and 0 deletions

View File

@ -675,6 +675,19 @@ Adds a new clipping ``region`` to the map settings.
.. seealso:: :py:func:`clippingRegions`
.. seealso:: :py:func:`setClippingRegions`
.. versionadded:: 3.16
%End
void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
%Docstring
Sets the list of clipping ``regions`` to apply to the map.
.. seealso:: :py:func:`addClippingRegion`
.. seealso:: :py:func:`clippingRegions`
.. versionadded:: 3.16
%End
@ -684,6 +697,8 @@ Returns the list of clipping regions to apply to the map.
.. seealso:: :py:func:`addClippingRegion`
.. seealso:: :py:func:`setClippingRegions`
.. versionadded:: 3.16
%End

View File

@ -687,6 +687,11 @@ void QgsMapSettings::addClippingRegion( const QgsMapClippingRegion &region )
mClippingRegions.append( region );
}
void QgsMapSettings::setClippingRegions( const QList<QgsMapClippingRegion> &regions )
{
mClippingRegions = regions;
}
QList<QgsMapClippingRegion> QgsMapSettings::clippingRegions() const
{
return mClippingRegions;

View File

@ -583,15 +583,27 @@ class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
* Adds a new clipping \a region to the map settings.
*
* \see clippingRegions()
* \see setClippingRegions()
*
* \since QGIS 3.16
*/
void addClippingRegion( const QgsMapClippingRegion &region );
/**
* Sets the list of clipping \a regions to apply to the map.
*
* \see addClippingRegion()
* \see clippingRegions()
*
* \since QGIS 3.16
*/
void setClippingRegions( const QList< QgsMapClippingRegion > &regions );
/**
* Returns the list of clipping regions to apply to the map.
*
* \see addClippingRegion()
* \see setClippingRegions()
*
* \since QGIS 3.16
*/

View File

@ -614,6 +614,10 @@ void TestQgsMapSettings::testClippingRegions()
QCOMPARE( settings3.clippingRegions().size(), 2 );
QCOMPARE( settings3.clippingRegions().at( 0 ).geometry().asWkt(), QStringLiteral( "Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))" ) );
QCOMPARE( settings3.clippingRegions().at( 1 ).geometry().asWkt(), QStringLiteral( "Polygon ((10 0, 11 0, 11 1, 10 1, 10 0))" ) ) ;
settings.setClippingRegions( QList< QgsMapClippingRegion >() << region2 );
QCOMPARE( settings.clippingRegions().size(), 1 );
QCOMPARE( settings.clippingRegions().at( 0 ).geometry().asWkt(), QStringLiteral( "Polygon ((10 0, 11 0, 11 1, 10 1, 10 0))" ) ) ;
}
QGSTEST_MAIN( TestQgsMapSettings )