Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed #1706.
git-svn-id: http://svn.osgeo.org/qgis/trunk@10896 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 9, 2009
1 parent 18dd732 commit 43202ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -93,8 +93,9 @@ class QgsMapCanvas : QGraphicsView
//! Zoom to the next extent (view)
void zoomToNextExtent();

/**Zooms to the extend of the selected features*/
void zoomToSelected();
/** Zoom to the extent of the selected features of current (vector) layer.
Added in version 1.2: optionally specify different than current layer */
void zoomToSelected(QgsVectorLayer* layer = NULL);

/** \brief Sets the map tool currently being used on the canvas */
void setMapTool(QgsMapTool* mapTool);
Expand Down
3 changes: 2 additions & 1 deletion src/app/attributetable/qgsattributetabledialog.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgisapp.h"
#include "qgssearchquerybuilder.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"


class QgsAttributeTableTableDock : public QDockWidget
Expand Down Expand Up @@ -201,7 +202,7 @@ void QgsAttributeTableDialog::on_mCopySelectedRowsButton_clicked()

void QgsAttributeTableDialog::on_mZoomMapToSelectedRowsButton_clicked()
{
QgisApp::instance()->zoomToSelected();
QgisApp::instance()->mapCanvas()->zoomToSelected(mLayer);
}

void QgsAttributeTableDialog::on_mInvertSelectionButton_clicked()
Expand Down
12 changes: 8 additions & 4 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -613,18 +613,22 @@ void QgsMapCanvas::mapUnitsChanged()
refresh();
}

void QgsMapCanvas::zoomToSelected()
void QgsMapCanvas::zoomToSelected(QgsVectorLayer* layer)
{
if ( mDrawing )
{
return;
}

QgsVectorLayer *lyr = dynamic_cast < QgsVectorLayer * >( mCurrentLayer );
if (layer == NULL)
{
// use current layer by default
layer = dynamic_cast < QgsVectorLayer * >( mCurrentLayer );
}

if ( lyr )
if ( layer )
{
QgsRectangle rect = mMapRenderer->layerExtentToOutputExtent( lyr, lyr->boundingBoxOfSelected() );
QgsRectangle rect = mMapRenderer->layerExtentToOutputExtent( layer, layer->boundingBoxOfSelected() );

// no selected features, only one selected point feature
//or two point features with the same x- or y-coordinates
Expand Down
6 changes: 4 additions & 2 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -49,6 +49,7 @@ class QgsMapLayer;
class QgsLegend;
class QgsLegendView;
class QgsRubberBand;
class QgsVectorLayer;

class QgsMapRenderer;
class QgsMapCanvasMap;
Expand Down Expand Up @@ -146,8 +147,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Zoom to the Next extent (view)
void zoomToNextExtent();

/**Zooms to the extend of the selected features*/
void zoomToSelected();
/** Zoom to the extent of the selected features of current (vector) layer.
Added in version 1.2: optionally specify different than current layer */
void zoomToSelected(QgsVectorLayer* layer = NULL);

/** \brief Sets the map tool currently being used on the canvas */
void setMapTool( QgsMapTool* mapTool );
Expand Down

0 comments on commit 43202ab

Please sign in to comment.