Skip to content
Permalink
Browse files
added zoomToLayerExtent also to legend layer right click menu
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4957 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 3, 2006
1 parent 14df914 commit 40842d6cd8aa3baa659140a5778fe3f4b244427d
Showing with 73 additions and 0 deletions.
  1. +69 −0 src/legend/qgslegend.cpp
  2. +4 −0 src/legend/qgslegend.h
@@ -32,6 +32,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrasterlayerproperties.h"
#include <float.h>
#include <QCoreApplication>
#include <QPixmap>
#include <QMouseEvent>
@@ -403,6 +404,7 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
else if(li->type() == QgsLegendItem::LEGEND_LAYER)
{
theMenu.addAction(tr("&Properties"), this, SLOT(legendLayerShowProperties()));
theMenu.addAction(tr("&Zoom to layer extent"), this, SLOT(zoomToLayerExtent()));
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionAddAllToOverview.png"))), tr("&Add to overview"), this, SLOT(legendLayerAddToOverview()));
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionRemoveAllFromOverview.png"))), tr("&Remove from overview"), this, SLOT(legendLayerRemoveFromOverview()));
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("/mActionRemove.png"))), tr("&Remove"), this, SLOT(legendLayerRemove()));
@@ -1540,3 +1542,70 @@ void QgsLegend::showLegendLayerFileGroups()
}
while(theItem = nextItem(theItem));
}

void QgsLegend::zoomToLayerExtent()
{
//find current Layer
QgsLegendLayer* currentLayer=dynamic_cast<QgsLegendLayer*>(currentItem());
if(!currentLayer)
{
return;
}

std::list<QgsLegendLayerFile*> layerFiles = currentLayer->legendLayerFiles();
if(layerFiles.size() == 0)
{
return;
}

double xmin = DBL_MAX;
double ymin = DBL_MAX;
double xmax = -DBL_MAX;
double ymax = -DBL_MAX;

QgsRect transformedExtent;
QgsRect layerExtent;
QgsCoordinateTransform *ct;
QgsMapLayer* theLayer;

for(std::list<QgsLegendLayerFile*>::iterator it= layerFiles.begin(); it != layerFiles.end(); ++it)
{
theLayer = (*it)->layer();
if(theLayer)
{
layerExtent = theLayer->extent();
ct = theLayer->coordinateTransform();
if(ct)
{
//transform layer extent to canvas coordinate system
transformedExtent = ct->transform(layerExtent);
}
else
{
transformedExtent = layerExtent;
}

if(transformedExtent.xMin() < xmin)
{
xmin = transformedExtent.xMin();
}
if(transformedExtent.yMin() < ymin)
{
ymin = transformedExtent.yMin();
}
if(transformedExtent.xMax() > xmax)
{
xmax = transformedExtent.xMax();
}
if(transformedExtent.yMax() > ymax)
{
ymax = transformedExtent.yMax();
}
}
}

//zoom to bounding box
mMapCanvas->setExtent(QgsRect(xmin, ymin, xmax, ymax));
mMapCanvas->render();
mMapCanvas->refresh();
}
@@ -253,6 +253,10 @@ this item may be moved back to the original position with resetToInitialPosition
void makeToTopLevelItem();
/**Show/ Hide the legend layer file groups*/
void showLegendLayerFileGroups();
/**Zooms to extent of the current legend layer (considers there may be several
legend layer files*/
void zoomToLayerExtent();

private:

/**Pointer to QGisApp, needed for signal/slot reasons*/

0 comments on commit 40842d6

Please sign in to comment.