Skip to content
Permalink
Browse files
[FEATURE] zoom to group of layers. Contributed by Alex Bruy - thanks! (
…#2783)

git-svn-id: http://svn.osgeo.org/qgis/trunk@15220 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Feb 20, 2011
1 parent 1407ba5 commit 5c1302f9ffc28a4af79ed7ac92fbf2e93409ea56
Showing with 52 additions and 11 deletions.
  1. +52 −11 src/app/legend/qgslegend.cpp
@@ -549,6 +549,9 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
}
else if ( li->type() == QgsLegendItem::LEGEND_GROUP )
{
theMenu.addAction( QgisApp::getThemeIcon( "/mActionZoomToLayer.png" ),
tr( "Zoom to group" ), this, SLOT( legendLayerZoom() ) );

theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ),
tr( "&Remove" ), this, SLOT( legendGroupRemove() ) );
}
@@ -1656,21 +1659,59 @@ void QgsLegend::legendLayerZoom()
return;
}

//find current Layer
QgsLegendLayer* currentLayer = dynamic_cast<QgsLegendLayer *>( currentItem() );
if ( !currentLayer )
return;
QgsRectangle extent;

QgsMapLayer* theLayer = currentLayer->layer();
QgsRectangle extent = theLayer->extent();
QgsLegendItem* li = dynamic_cast<QgsLegendItem *>( currentItem() );

//transform extent if otf-projection is on
if ( mMapCanvas->hasCrsTransformEnabled() )
if ( li->type() == QgsLegendItem::LEGEND_LAYER )
{
QgsMapRenderer* renderer = mMapCanvas->mapRenderer();
if ( renderer )
QgsLegendLayer* currentLayer = dynamic_cast<QgsLegendLayer *>( currentItem() );
if ( !currentLayer )
return;

QgsMapLayer* theLayer = currentLayer->layer();
extent = theLayer->extent();

//transform extent if otf-projection is on
if ( mMapCanvas->hasCrsTransformEnabled() )
{
extent = renderer->layerExtentToOutputExtent( theLayer, extent );
QgsMapRenderer* renderer = mMapCanvas->mapRenderer();
if ( renderer )
{
extent = renderer->layerExtentToOutputExtent( theLayer, extent );
}
}
}
else if ( li->type() == QgsLegendItem::LEGEND_GROUP )
{
QgsLegendGroup* currentGroup = dynamic_cast<QgsLegendGroup *>( currentItem() );

QgsRectangle layerExtent;

QList<QgsLegendLayer*> layers = currentGroup->legendLayers();
for ( int i = 0; i < layers.size(); ++i )
{
QgsMapLayer* theLayer = layers.at( i )->layer();
layerExtent = theLayer->extent();

//transform extent if otf-projection is on
if ( mMapCanvas->hasCrsTransformEnabled() )
{
QgsMapRenderer* renderer = mMapCanvas->mapRenderer();
if ( renderer )
{
layerExtent = renderer->layerExtentToOutputExtent( theLayer, layerExtent );
}
}

if ( i == 0 )
{
extent = layerExtent;
}
else
{
extent.combineExtentWith( &layerExtent );
}
}
}

0 comments on commit 5c1302f

Please sign in to comment.