Skip to content
Permalink
Browse files

Merge pull request #6721 from slarosa/zoom_selected_cm

[needs-docs] add zoom to selection action to contextual menu of the layer
  • Loading branch information
slarosa committed Apr 6, 2018
2 parents 62ba263 + 5f7358a commit 747955ae472289d9feb5dd07f5049392271a5a6a
@@ -50,6 +50,13 @@ Action to check a group and all its parents
%End

QAction *actionZoomToLayer( QgsMapCanvas *canvas, QObject *parent = 0 ) /Factory/;

QAction *actionZoomToSelection( QgsMapCanvas *canvas, QObject *parent = 0 ) /Factory/;
%Docstring
Action to zoom to selected features of a vector layer

.. versionadded:: 3.2
%End
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = 0 ) /Factory/;

QAction *actionMakeTopLevel( QObject *parent = 0 ) /Factory/;
@@ -71,6 +78,14 @@ Action to enable/disable mutually exclusive flag of a group (only one child node
%End

void zoomToLayer( QgsMapCanvas *canvas );

void zoomToSelection( QgsMapCanvas *canvas );
%Docstring

.. seealso:: :py:func:`zoomToSelection`

.. versionadded:: 3.2
%End
void zoomToGroup( QgsMapCanvas *canvas );

public slots:
@@ -82,6 +97,13 @@ Action to enable/disable mutually exclusive flag of a group (only one child node
void renameGroupOrLayer();
void showFeatureCount();
void zoomToLayer();

void zoomToSelection();
%Docstring
Slot to zoom to selected features of a vector layer

.. versionadded:: 3.2
%End
void zoomToGroup();
void makeTopLevel();

@@ -135,6 +135,12 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
if ( layer && layer->isSpatial() )
{
menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) );
if ( vlayer )
{
QAction *actionZoomSelected = actions->actionZoomToSelection( mCanvas, menu );
actionZoomSelected->setEnabled( !vlayer->selectedFeatures().isEmpty() );
menu->addAction( actionZoomSelected );
}
menu->addAction( actions->actionShowInOverview( menu ) );
}

@@ -97,6 +97,15 @@ QAction *QgsLayerTreeViewDefaultActions::actionZoomToLayer( QgsMapCanvas *canvas
return a;
}

QAction *QgsLayerTreeViewDefaultActions::actionZoomToSelection( QgsMapCanvas *canvas, QObject *parent )
{
QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ),
tr( "&Zoom to Selection" ), parent );
a->setData( QVariant::fromValue( reinterpret_cast<void *>( canvas ) ) );
connect( a, &QAction::triggered, this, static_cast<void ( QgsLayerTreeViewDefaultActions::* )()>( &QgsLayerTreeViewDefaultActions::zoomToSelection ) );
return a;
}

QAction *QgsLayerTreeViewDefaultActions::actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent )
{
QAction *a = new QAction( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToLayer.svg" ) ),
@@ -259,6 +268,15 @@ void QgsLayerTreeViewDefaultActions::zoomToLayer( QgsMapCanvas *canvas )
zoomToLayers( canvas, layers );
}

void QgsLayerTreeViewDefaultActions::zoomToSelection( QgsMapCanvas *canvas )
{
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mView->currentLayer() );
if ( !layer )
return;

canvas->zoomToSelected( layer );
}

void QgsLayerTreeViewDefaultActions::zoomToGroup( QgsMapCanvas *canvas )
{
QgsLayerTreeGroup *groupNode = mView->currentGroupNode();
@@ -281,6 +299,14 @@ void QgsLayerTreeViewDefaultActions::zoomToLayer()
QApplication::restoreOverrideCursor();
}

void QgsLayerTreeViewDefaultActions::zoomToSelection()
{
QAction *s = qobject_cast<QAction *>( sender() );
QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
QgsTemporaryCursorOverride waitCursor( Qt::WaitCursor );
zoomToSelection( canvas );
}

void QgsLayerTreeViewDefaultActions::zoomToGroup()
{
QAction *s = qobject_cast<QAction *>( sender() );
@@ -58,8 +58,13 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
QAction *actionCheckAndAllParents( QObject *parent = nullptr );

QAction *actionZoomToLayer( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;

/**
* Action to zoom to selected features of a vector layer
* \since QGIS 3.2
*/
QAction *actionZoomToSelection( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
// TODO: zoom to selected

QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;

@@ -77,6 +82,12 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
QAction *actionMutuallyExclusiveGroup( QObject *parent = nullptr ) SIP_FACTORY;

void zoomToLayer( QgsMapCanvas *canvas );

/**
* \see zoomToSelection()
* \since QGIS 3.2
*/
void zoomToSelection( QgsMapCanvas *canvas );
void zoomToGroup( QgsMapCanvas *canvas );

public slots:
@@ -88,6 +99,12 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
void renameGroupOrLayer();
void showFeatureCount();
void zoomToLayer();

/**
* Slot to zoom to selected features of a vector layer
* \since QGIS 3.2
*/
void zoomToSelection();
void zoomToGroup();
void makeTopLevel();

0 comments on commit 747955a

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