mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
[needs-docs] add zoom to selection action to contextual menu of the layer
This commit is contained in:
parent
1a74b0a021
commit
bf41a90af8
@ -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/;
|
||||
@ -63,6 +70,7 @@ Action to enable/disable mutually exclusive flag of a group (only one child node
|
||||
%End
|
||||
|
||||
void zoomToLayer( QgsMapCanvas *canvas );
|
||||
void zoomToSelection( QgsMapCanvas *canvas );
|
||||
void zoomToGroup( QgsMapCanvas *canvas );
|
||||
|
||||
public slots:
|
||||
@ -74,6 +82,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();
|
||||
void groupSelected();
|
||||
|
@ -129,6 +129,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" ) ),
|
||||
@ -252,6 +261,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();
|
||||
@ -274,6 +292,15 @@ void QgsLayerTreeViewDefaultActions::zoomToLayer()
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void QgsLayerTreeViewDefaultActions::zoomToSelection()
|
||||
{
|
||||
QAction *s = qobject_cast<QAction *>( sender() );
|
||||
QgsMapCanvas *canvas = reinterpret_cast<QgsMapCanvas *>( s->data().value<void *>() );
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
zoomToSelection( canvas );
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
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;
|
||||
QAction *actionGroupSelected( QObject *parent = nullptr ) SIP_FACTORY;
|
||||
@ -71,6 +76,7 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
|
||||
QAction *actionMutuallyExclusiveGroup( QObject *parent = nullptr ) SIP_FACTORY;
|
||||
|
||||
void zoomToLayer( QgsMapCanvas *canvas );
|
||||
void zoomToSelection( QgsMapCanvas *canvas );
|
||||
void zoomToGroup( QgsMapCanvas *canvas );
|
||||
|
||||
public slots:
|
||||
@ -82,6 +88,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();
|
||||
void groupSelected();
|
||||
|
Loading…
x
Reference in New Issue
Block a user