mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
Use QgsMapLayerUtils::combinedExtent
This commit is contained in:
parent
780db4eb0a
commit
937dd80733
@ -87,7 +87,7 @@ the parent :py:class:`QgsProject` wherever appropriate.
|
|||||||
.. seealso:: :py:func:`childLayers`
|
.. seealso:: :py:func:`childLayers`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QList< QgsMapLayer * > childLayers();
|
QList< QgsMapLayer * > childLayers() const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns the child layers contained by the group.
|
Returns the child layers contained by the group.
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "qgsmessagelog.h"
|
#include "qgsmessagelog.h"
|
||||||
#include "qgspainteffectregistry.h"
|
#include "qgspainteffectregistry.h"
|
||||||
#include "qgsapplication.h"
|
#include "qgsapplication.h"
|
||||||
|
#include "qgsmaplayerutils.h"
|
||||||
|
|
||||||
QgsGroupLayer::QgsGroupLayer( const QString &name, const LayerOptions &options )
|
QgsGroupLayer::QgsGroupLayer( const QString &name, const LayerOptions &options )
|
||||||
: QgsMapLayer( QgsMapLayerType::GroupLayer, name )
|
: QgsMapLayer( QgsMapLayerType::GroupLayer, name )
|
||||||
@ -66,47 +67,7 @@ QgsMapLayerRenderer *QgsGroupLayer::createMapRenderer( QgsRenderContext &context
|
|||||||
|
|
||||||
QgsRectangle QgsGroupLayer::extent() const
|
QgsRectangle QgsGroupLayer::extent() const
|
||||||
{
|
{
|
||||||
QgsRectangle rect;
|
return QgsMapLayerUtils::combinedExtent( childLayers(), crs(), mTransformContext );
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsGroupLayer::setTransformContext( const QgsCoordinateTransformContext &context )
|
void QgsGroupLayer::setTransformContext( const QgsCoordinateTransformContext &context )
|
||||||
@ -325,7 +286,7 @@ void QgsGroupLayer::setChildLayers( const QList< QgsMapLayer * > &layers )
|
|||||||
triggerRepaint();
|
triggerRepaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList< QgsMapLayer * > QgsGroupLayer::childLayers()
|
QList< QgsMapLayer * > QgsGroupLayer::childLayers() const
|
||||||
{
|
{
|
||||||
return _qgis_listRefToRaw( mChildren );
|
return _qgis_listRefToRaw( mChildren );
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ class CORE_EXPORT QgsGroupLayer : public QgsMapLayer
|
|||||||
*
|
*
|
||||||
* \see setChildLayers()
|
* \see setChildLayers()
|
||||||
*/
|
*/
|
||||||
QList< QgsMapLayer * > childLayers();
|
QList< QgsMapLayer * > childLayers() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current paint effect for the group layer.
|
* Returns the current paint effect for the group layer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user