Skip to content
Permalink
Browse files
Use QgsMapLayerUtils::combinedExtent
  • Loading branch information
nyalldawson committed Nov 25, 2021
1 parent 780db4e commit 937dd80733a9a06368a45d765618560ba5231dbb
Showing with 5 additions and 44 deletions.
  1. +1 −1 python/core/auto_generated/qgsgrouplayer.sip.in
  2. +3 −42 src/core/qgsgrouplayer.cpp
  3. +1 −1 src/core/qgsgrouplayer.h
@@ -87,7 +87,7 @@ the parent :py:class:`QgsProject` wherever appropriate.
.. seealso:: :py:func:`childLayers`
%End

QList< QgsMapLayer * > childLayers();
QList< QgsMapLayer * > childLayers() const;
%Docstring
Returns the child layers contained by the group.

@@ -27,6 +27,7 @@
#include "qgsmessagelog.h"
#include "qgspainteffectregistry.h"
#include "qgsapplication.h"
#include "qgsmaplayerutils.h"

QgsGroupLayer::QgsGroupLayer( const QString &name, const LayerOptions &options )
: QgsMapLayer( QgsMapLayerType::GroupLayer, name )
@@ -66,47 +67,7 @@ QgsMapLayerRenderer *QgsGroupLayer::createMapRenderer( QgsRenderContext &context

QgsRectangle QgsGroupLayer::extent() const
{
QgsRectangle rect;
rect.setMinimal();

const QList< QgsMapLayer * > currentLayers = _qgis_listRefToRaw( mChildren );
for ( const QgsMapLayer *layer : currentLayers )
{
if ( !layer->isSpatial() )
continue;

QgsRectangle layerExtent = layer->extent();
if ( const QgsVectorLayer *vLayer = qobject_cast<const QgsVectorLayer *>( layer ) )
{
if ( layerExtent.isEmpty() )
{
const_cast< QgsVectorLayer * >( vLayer )->updateExtents();
layerExtent = vLayer->extent();
}
}

if ( layerExtent.isNull() )
continue;

//transform extent
try
{
QgsCoordinateTransform ct = QgsCoordinateTransform( layer->crs(), crs(), mTransformContext );
if ( ct.isValid() )
{
ct.setBallparkTransformsAreAppropriate( true );
layerExtent = ct.transformBoundingBox( layerExtent );
}
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
}

rect.combineExtentWith( layerExtent );
}

return rect;
return QgsMapLayerUtils::combinedExtent( childLayers(), crs(), mTransformContext );
}

void QgsGroupLayer::setTransformContext( const QgsCoordinateTransformContext &context )
@@ -325,7 +286,7 @@ void QgsGroupLayer::setChildLayers( const QList< QgsMapLayer * > &layers )
triggerRepaint();
}

QList< QgsMapLayer * > QgsGroupLayer::childLayers()
QList< QgsMapLayer * > QgsGroupLayer::childLayers() const
{
return _qgis_listRefToRaw( mChildren );
}
@@ -109,7 +109,7 @@ class CORE_EXPORT QgsGroupLayer : public QgsMapLayer
*
* \see setChildLayers()
*/
QList< QgsMapLayer * > childLayers();
QList< QgsMapLayer * > childLayers() const;

/**
* Returns the current paint effect for the group layer.

0 comments on commit 937dd80

Please sign in to comment.