diff --git a/images/images.qrc b/images/images.qrc index ff99e25d2f4c..539880d08070 100644 --- a/images/images.qrc +++ b/images/images.qrc @@ -111,6 +111,7 @@ themes/default/mActionOpenTable.png themes/default/mActionOptions.png themes/default/mActionPan.png + themes/default/mActionPanToSelected.png themes/default/mAction.png themes/default/mActionProjectProperties.png themes/default/mActionPropertyItem.png @@ -295,6 +296,7 @@ themes/gis/mActionNodeTool.png themes/gis/mActionOpenTable.png themes/gis/mActionPan.png + themes/gis/mActionPanToSelected.png themes/gis/mActionRaiseItems.png themes/gis/mActionRedo.png themes/gis/mActionRemoveLayer.png diff --git a/images/themes/default/mActionPanToSelected.png b/images/themes/default/mActionPanToSelected.png new file mode 100644 index 000000000000..18addbc5f886 Binary files /dev/null and b/images/themes/default/mActionPanToSelected.png differ diff --git a/images/themes/gis/mActionPanToSelected.png b/images/themes/gis/mActionPanToSelected.png new file mode 100644 index 000000000000..18addbc5f886 Binary files /dev/null and b/images/themes/gis/mActionPanToSelected.png differ diff --git a/python/gui/qgisinterface.sip b/python/gui/qgisinterface.sip index e179aec7bce9..0e74993dac4e 100644 --- a/python/gui/qgisinterface.sip +++ b/python/gui/qgisinterface.sip @@ -289,6 +289,7 @@ class QgisInterface : QObject //! View menu actions virtual QAction *actionPan() = 0; + virtual QAction *actionPanToSelected() = 0; virtual QAction *actionZoomIn() = 0; virtual QAction *actionZoomOut() = 0; virtual QAction *actionSelect() = 0; diff --git a/python/gui/qgsmapcanvas.sip b/python/gui/qgsmapcanvas.sip index 9b254d787009..6fe976b3bc9c 100644 --- a/python/gui/qgsmapcanvas.sip +++ b/python/gui/qgsmapcanvas.sip @@ -12,16 +12,16 @@ class QgsMapCanvasLayer public: QgsMapCanvasLayer(QgsMapLayer* layer, bool visible = TRUE, bool isInOverview = FALSE); - + void setVisible(bool visible); void setInOverview(bool isInOverview); - + bool isVisible() const; bool isInOverview() const; - + QgsMapLayer* layer(); //const QgsMapLayer* layer() const; - + }; @@ -53,17 +53,17 @@ class QgsMapCanvas : QGraphicsView ~QgsMapCanvas(); void setLayerSet(QList& layers); - + void setCurrentLayer(QgsMapLayer* layer); - + void updateOverview(); - + void enableOverviewMode(QgsMapOverviewCanvas* overview); - + QgsMapCanvasMap* map(); - + QgsMapRenderer* mapRenderer(); - + //! Accessor for the canvas pixmap // @deprecated use canvasPaintDevice() QPixmap& canvasPixmap() /Deprecated/; @@ -99,24 +99,28 @@ class QgsMapCanvas : QGraphicsView // ! Clears the list of extents and sets current extent as first item void clearExtentHistory(); - + /** 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); + /** Pan to the selected features of current (vector) layer keeping same extent. + @note added in 2.0 */ + void panToSelected( QgsVectorLayer* layer = NULL ); + /** \brief Sets the map tool currently being used on the canvas */ void setMapTool(QgsMapTool* mapTool); - - /** \brief Unset the current mapset tool or last non zoom tool if - * it the same as passed map tool pointer. The tool is not - * referenced/used any more, but the instance is not deleted + + /** \brief Unset the current mapset tool or last non zoom tool if + * it the same as passed map tool pointer. The tool is not + * referenced/used any more, but the instance is not deleted * by this method. */ void unsetMapTool(QgsMapTool* mapTool); /**Returns the currently active tool*/ QgsMapTool* mapTool(); - + /** Write property of QColor bgColor. */ virtual void setCanvasColor(const QColor & _newVal); @@ -128,7 +132,7 @@ class QgsMapCanvas : QGraphicsView //! return the map layer at position index in the layer stack QgsMapLayer *layer(int index); - + //! return number of layers on the map int layerCount() const; @@ -162,10 +166,10 @@ class QgsMapCanvas : QGraphicsView //! true if canvas currently drawing bool isDrawing(); - + //! returns current layer (set by legend widget) QgsMapLayer* currentLayer(); - + //! set wheel action and zoom factor (should be greater than 1) void setWheelAction(WheelAction action, double factor = 2); @@ -178,7 +182,7 @@ class QgsMapCanvas : QGraphicsView //! Zoom to a specific scale // added in 1.5 void zoomScale( double scale ); - + //! Zoom with the factor supplied. Factor > 1 zooms in void zoomByFactor( double scaleFactor ); @@ -187,7 +191,7 @@ class QgsMapCanvas : QGraphicsView //! used to determine if anti-aliasing is enabled or not void enableAntiAliasing(bool theFlag); - + //! Select which Qt class to render with void useImageToRender(bool theFlag); @@ -197,10 +201,10 @@ class QgsMapCanvas : QGraphicsView void panActionEnd(QPoint releasePoint); //! Called when mouse is moving and pan is activated void panAction(QMouseEvent * event); - + //! returns last position of mouse cursor QPoint mouseLastXY(); - + public slots: /**Sets dirty=true and calls render()*/ @@ -222,19 +226,19 @@ class QgsMapCanvas : QGraphicsView /** The map units may have changed, so cope with that */ void mapUnitsChanged(); - + /** updates pixmap on render progress */ void updateMap(); - + //! show whatever error is exposed by the QgsMapLayer. void showError(QgsMapLayer * mapLayer); - + //! called to read map canvas settings from project void readProject(const QDomDocument &); - + //! called to write map canvas settings to project void writeProject(QDomDocument &); - + signals: /** Let the owner know how far we are with render operations */ void setProgress(int,int); @@ -271,7 +275,7 @@ class QgsMapCanvas : QGraphicsView //! Emit key release event void keyReleased(QKeyEvent * e); - + //! Emit map tool changed event void mapToolSet(QgsMapTool *tool); @@ -315,7 +319,6 @@ class QgsMapCanvas : QGraphicsView //! called on resize or changed extent to notify canvas items to change their rectangle void updateCanvasItemPositions(); - }; // class QgsMapCanvas diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 6b135fcbbc2f..5868052e48e0 100755 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -808,6 +808,7 @@ void QgisApp::createActions() // View Menu Items connect( mActionPan, SIGNAL( triggered() ), this, SLOT( pan() ) ); + connect( mActionPanToSelected, SIGNAL( triggered() ), this, SLOT( panToSelected() ) ); connect( mActionZoomIn, SIGNAL( triggered() ), this, SLOT( zoomIn() ) ); connect( mActionZoomOut, SIGNAL( triggered() ), this, SLOT( zoomOut() ) ); connect( mActionSelect, SIGNAL( triggered() ), this, SLOT( select() ) ); @@ -3266,6 +3267,11 @@ void QgisApp::zoomToSelected() mMapCanvas->zoomToSelected(); } +void QgisApp::panToSelected() +{ + mMapCanvas->panToSelected(); +} + void QgisApp::pan() { mMapCanvas->setMapTool( mMapTools.mPan ); diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index b71aa3137a37..2c134606eba1 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -239,6 +239,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow QAction *actionSnappingOptions() { return mActionSnappingOptions; } QAction *actionPan() { return mActionPan; } + QAction *actionPanToSelected() { return mActionPanToSelected; } QAction *actionZoomIn() { return mActionZoomIn; } QAction *actionZoomOut() { return mActionZoomOut; } QAction *actionSelect() { return mActionSelect; } @@ -374,6 +375,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow void zoomToNext(); //! Zoom to selected features void zoomToSelected(); + //! Pan map to selected features + //! @note added in 2.0 + void panToSelected(); //! open the properties dialog for the currently selected layer void layerProperties(); diff --git a/src/app/qgisappinterface.cpp b/src/app/qgisappinterface.cpp index f36ff8774f15..3d0b770b32da 100644 --- a/src/app/qgisappinterface.cpp +++ b/src/app/qgisappinterface.cpp @@ -113,7 +113,6 @@ QgsRasterLayer* QgisAppInterface::addRasterLayer( const QString& url, const QStr return qgis->addRasterLayer( url, baseName, providerKey, layers, styles, format, crs ); } - bool QgisAppInterface::addProject( QString theProjectName ) { return qgis->addProject( theProjectName ); @@ -413,6 +412,7 @@ QAction *QgisAppInterface::actionEditSeparator2() { return 0; } //! View menu actions QAction *QgisAppInterface::actionPan() { return qgis->actionPan(); } +QAction *QgisAppInterface::actionPanToSelected() { return qgis->actionPanToSelected(); } QAction *QgisAppInterface::actionZoomIn() { return qgis->actionZoomIn(); } QAction *QgisAppInterface::actionZoomOut() { return qgis->actionZoomOut(); } QAction *QgisAppInterface::actionSelect() { return qgis->actionSelect(); } diff --git a/src/app/qgisappinterface.h b/src/app/qgisappinterface.h index 95e86b76a305..0fe8dddcb10c 100644 --- a/src/app/qgisappinterface.h +++ b/src/app/qgisappinterface.h @@ -261,6 +261,7 @@ class QgisAppInterface : public QgisInterface //! View menu actions virtual QAction *actionPan(); + virtual QAction *actionPanToSelected(); virtual QAction *actionZoomIn(); virtual QAction *actionZoomOut(); virtual QAction *actionSelect(); diff --git a/src/gui/qgisinterface.h b/src/gui/qgisinterface.h index 8328fd2c3d4c..2bcfd4492835 100644 --- a/src/gui/qgisinterface.h +++ b/src/gui/qgisinterface.h @@ -402,6 +402,7 @@ class GUI_EXPORT QgisInterface : public QObject //! View menu actions virtual QAction *actionPan() = 0; + virtual QAction *actionPanToSelected() = 0; virtual QAction *actionZoomIn() = 0; virtual QAction *actionZoomOut() = 0; virtual QAction *actionSelect() = 0; diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 418264ef4f14..894afc7aa7ed 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -720,6 +720,34 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer* layer ) refresh(); } // zoomToSelected +void QgsMapCanvas::panToSelected( QgsVectorLayer* layer ) +{ + if ( mDrawing ) + { + return; + } + + if ( layer == NULL ) + { + // use current layer by default + layer = qobject_cast( mCurrentLayer ); + } + + if ( layer == NULL ) + { + return; + } + + if ( layer->selectedFeatureCount() == 0 ) + { + return; + } + + QgsRectangle rect = mMapRenderer->layerExtentToOutputExtent( layer, layer->boundingBoxOfSelected() ); + setExtent( QgsRectangle( rect.center(), rect.center() ) ); + refresh(); +} // panToSelected + void QgsMapCanvas::keyPressEvent( QKeyEvent * e ) { diff --git a/src/gui/qgsmapcanvas.h b/src/gui/qgsmapcanvas.h index f1ec1f3c0ad8..aa8a3896a55c 100644 --- a/src/gui/qgsmapcanvas.h +++ b/src/gui/qgsmapcanvas.h @@ -156,6 +156,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView Added in version 1.2: optionally specify different than current layer */ void zoomToSelected( QgsVectorLayer* layer = NULL ); + /** Pan to the selected features of current (vector) layer keeping same extent. + @note added in 2.0 */ + void panToSelected( QgsVectorLayer* layer = NULL ); + /** \brief Sets the map tool currently being used on the canvas */ void setMapTool( QgsMapTool* mapTool ); diff --git a/src/ui/qgisapp.ui b/src/ui/qgisapp.ui index 6693784c85ef..21980ee972d8 100644 --- a/src/ui/qgisapp.ui +++ b/src/ui/qgisapp.ui @@ -17,7 +17,7 @@ 0 0 1052 - 25 + 28 @@ -107,6 +107,7 @@ + @@ -307,6 +308,7 @@ false + @@ -1590,6 +1592,18 @@ Run feature action + + + + :/images/themes/default/mActionPanToSelected.png:/images/themes/default/mActionPanToSelected.png + + + Pan Map to Selection + + + Pan Map to Selection + +