Skip to content
Permalink
Browse files

[FEATURE] new navigation tool Pan Map to Selection (fix #4031)

  • Loading branch information
alexbruy committed Jan 24, 2012
1 parent 138d4a2 commit 42edad5ebcda03d270d90cd85706b0ec1e30f957
@@ -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>
@@ -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>
Binary file not shown.
Binary file not shown.
@@ -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;
@@ -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<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/;
@@ -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


@@ -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 );
@@ -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();
@@ -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(); }
@@ -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();
@@ -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;
@@ -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 )
{

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

@@ -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">
@@ -107,6 +107,7 @@
<addaction name="mActionDecorationScaleBar"/>
</widget>
<addaction name="mActionPan"/>
<addaction name="mActionPanToSelected"/>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="separator"/>
@@ -307,6 +308,7 @@
<bool>false</bool>
</attribute>
<addaction name="mActionPan"/>
<addaction name="mActionPanToSelected"/>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionZoomActualSize"/>
@@ -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"/>

0 comments on commit 42edad5

Please sign in to comment.
You can’t perform that action at this time.