Skip to content

Commit 43202ab

Browse files
author
wonder
committed
Fixed #1706.
git-svn-id: http://svn.osgeo.org/qgis/trunk@10896 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 18dd732 commit 43202ab

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

python/gui/qgsmapcanvas.sip

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ class QgsMapCanvas : QGraphicsView
9393
//! Zoom to the next extent (view)
9494
void zoomToNextExtent();
9595

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

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

src/app/attributetable/qgsattributetabledialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgisapp.h"
3131
#include "qgssearchquerybuilder.h"
3232
#include "qgslogger.h"
33+
#include "qgsmapcanvas.h"
3334

3435

3536
class QgsAttributeTableTableDock : public QDockWidget
@@ -201,7 +202,7 @@ void QgsAttributeTableDialog::on_mCopySelectedRowsButton_clicked()
201202

202203
void QgsAttributeTableDialog::on_mZoomMapToSelectedRowsButton_clicked()
203204
{
204-
QgisApp::instance()->zoomToSelected();
205+
QgisApp::instance()->mapCanvas()->zoomToSelected(mLayer);
205206
}
206207

207208
void QgsAttributeTableDialog::on_mInvertSelectionButton_clicked()

src/gui/qgsmapcanvas.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,18 +613,22 @@ void QgsMapCanvas::mapUnitsChanged()
613613
refresh();
614614
}
615615

616-
void QgsMapCanvas::zoomToSelected()
616+
void QgsMapCanvas::zoomToSelected(QgsVectorLayer* layer)
617617
{
618618
if ( mDrawing )
619619
{
620620
return;
621621
}
622622

623-
QgsVectorLayer *lyr = dynamic_cast < QgsVectorLayer * >( mCurrentLayer );
623+
if (layer == NULL)
624+
{
625+
// use current layer by default
626+
layer = dynamic_cast < QgsVectorLayer * >( mCurrentLayer );
627+
}
624628

625-
if ( lyr )
629+
if ( layer )
626630
{
627-
QgsRectangle rect = mMapRenderer->layerExtentToOutputExtent( lyr, lyr->boundingBoxOfSelected() );
631+
QgsRectangle rect = mMapRenderer->layerExtentToOutputExtent( layer, layer->boundingBoxOfSelected() );
628632

629633
// no selected features, only one selected point feature
630634
//or two point features with the same x- or y-coordinates

src/gui/qgsmapcanvas.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class QgsMapLayer;
4949
class QgsLegend;
5050
class QgsLegendView;
5151
class QgsRubberBand;
52+
class QgsVectorLayer;
5253

5354
class QgsMapRenderer;
5455
class QgsMapCanvasMap;
@@ -146,8 +147,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
146147
//! Zoom to the Next extent (view)
147148
void zoomToNextExtent();
148149

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

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

0 commit comments

Comments
 (0)