Skip to content

Commit

Permalink
[FEATURE] new navigation tool Pan Map to Selection (fix #4031)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jan 24, 2012
1 parent 138d4a2 commit 42edad5
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 32 deletions.
2 changes: 2 additions & 0 deletions images/images.qrc
Expand Up @@ -111,6 +111,7 @@
<file>themes/default/mActionOpenTable.png</file>
<file>themes/default/mActionOptions.png</file>
<file>themes/default/mActionPan.png</file>
<file>themes/default/mActionPanToSelected.png</file>
<file>themes/default/mAction.png</file>
<file>themes/default/mActionProjectProperties.png</file>
<file>themes/default/mActionPropertyItem.png</file>
Expand Down Expand Up @@ -295,6 +296,7 @@
<file>themes/gis/mActionNodeTool.png</file>
<file>themes/gis/mActionOpenTable.png</file>
<file>themes/gis/mActionPan.png</file>
<file>themes/gis/mActionPanToSelected.png</file>
<file>themes/gis/mActionRaiseItems.png</file>
<file>themes/gis/mActionRedo.png</file>
<file>themes/gis/mActionRemoveLayer.png</file>
Expand Down
Binary file added images/themes/default/mActionPanToSelected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/gis/mActionPanToSelected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions python/gui/qgisinterface.sip
Expand Up @@ -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;
Expand Down
63 changes: 33 additions & 30 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -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;

};


Expand Down Expand Up @@ -53,17 +53,17 @@ class QgsMapCanvas : QGraphicsView
~QgsMapCanvas();

void setLayerSet(QList<QgsMapCanvasLayer>& 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/;
Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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 );

Expand All @@ -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);

Expand All @@ -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()*/
Expand All @@ -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);
Expand Down Expand Up @@ -271,7 +275,7 @@ class QgsMapCanvas : QGraphicsView

//! Emit key release event
void keyReleased(QKeyEvent * e);

//! Emit map tool changed event
void mapToolSet(QgsMapTool *tool);

Expand Down Expand Up @@ -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


6 changes: 6 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -3266,6 +3267,11 @@ void QgisApp::zoomToSelected()
mMapCanvas->zoomToSelected();
}

void QgisApp::panToSelected()
{
mMapCanvas->panToSelected();
}

void QgisApp::pan()
{
mMapCanvas->setMapTool( mMapTools.mPan );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisappinterface.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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(); }
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisappinterface.h
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgisinterface.h
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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<QgsVectorLayer *>( 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 )
{

Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -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 );

Expand Down
16 changes: 15 additions & 1 deletion src/ui/qgisapp.ui
Expand Up @@ -17,7 +17,7 @@
<x>0</x>
<y>0</y>
<width>1052</width>
<height>25</height>
<height>28</height>
</rect>
</property>
<widget class="QMenu" name="mEditMenu">
Expand Down Expand Up @@ -107,6 +107,7 @@
<addaction name="mActionDecorationScaleBar"/>
</widget>
<addaction name="mActionPan"/>
<addaction name="mActionPanToSelected"/>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -307,6 +308,7 @@
<bool>false</bool>
</attribute>
<addaction name="mActionPan"/>
<addaction name="mActionPanToSelected"/>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionZoomActualSize"/>
Expand Down Expand Up @@ -1590,6 +1592,18 @@
<string>Run feature action</string>
</property>
</action>
<action name="mActionPanToSelected">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionPanToSelected.png</normaloff>:/images/themes/default/mActionPanToSelected.png</iconset>
</property>
<property name="text">
<string>Pan Map to Selection</string>
</property>
<property name="toolTip">
<string>Pan Map to Selection</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 42edad5

Please sign in to comment.