File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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);
Original file line number Diff line number Diff line change 3030#include " qgisapp.h"
3131#include " qgssearchquerybuilder.h"
3232#include " qgslogger.h"
33+ #include " qgsmapcanvas.h"
3334
3435
3536class QgsAttributeTableTableDock : public QDockWidget
@@ -201,7 +202,7 @@ void QgsAttributeTableDialog::on_mCopySelectedRowsButton_clicked()
201202
202203void QgsAttributeTableDialog::on_mZoomMapToSelectedRowsButton_clicked ()
203204{
204- QgisApp::instance ()->zoomToSelected ();
205+ QgisApp::instance ()->mapCanvas ()-> zoomToSelected (mLayer );
205206}
206207
207208void QgsAttributeTableDialog::on_mInvertSelectionButton_clicked ()
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ class QgsMapLayer;
4949class QgsLegend ;
5050class QgsLegendView ;
5151class QgsRubberBand ;
52+ class QgsVectorLayer ;
5253
5354class QgsMapRenderer ;
5455class 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 );
You can’t perform that action at this time.
0 commit comments