Skip to content
Permalink
Browse files

Cleanups

  • Loading branch information
nyalldawson committed Jan 5, 2021
1 parent b2af412 commit cf3bee384e059e61f32d49f2911a032c2d4d1dbe
@@ -288,11 +288,13 @@ Centers canvas extent to feature ids
Pan to the selected features of current (vector) layer keeping same extent.
%End

void panToAllSelected( const QList<QgsMapLayer *> *layers );
void panToSelected( const QList<QgsMapLayer *> &layers );
%Docstring
Pan to the combined extent of the selected features of all provided (vector) layers.

:param layers: A list of layers

.. versionadded:: 3.18
%End

void flashFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids,
@@ -962,11 +964,13 @@ Zoom to the extent of the selected features of provided (vector) layer.
:param layer: optionally specify different than current layer
%End

void zoomToAllSelected( const QList<QgsMapLayer *> *layers );
void zoomToSelected( const QList<QgsMapLayer *> &layers );
%Docstring
Zoom to the combined extent of the selected features of all provided (vector) layers.

:param layers: A list of layers

.. versionadded:: 3.18
%End

void setZoomResolutions( const QList<double> &resolutions );
@@ -8191,10 +8191,10 @@ void QgisApp::zoomOut()

void QgisApp::zoomToSelected()
{
QList<QgsMapLayer *> layers = mLayerTreeView->selectedLayers();
const QList<QgsMapLayer *> layers = mLayerTreeView->selectedLayers();

if ( layers.size() > 1 && !layers.isEmpty() )
mMapCanvas->zoomToAllSelected( &layers );
if ( layers.size() > 1 )
mMapCanvas->zoomToSelected( layers );

else
mMapCanvas->zoomToSelected();
@@ -8203,11 +8203,10 @@ void QgisApp::zoomToSelected()

void QgisApp::panToSelected()
{
QList<QgsMapLayer *> layers = mLayerTreeView->selectedLayers();

if ( layers.size() > 1 && !layers.isEmpty() )
mMapCanvas->panToAllSelected( &layers );
const QList<QgsMapLayer *> layers = mLayerTreeView->selectedLayers();

if ( layers.size() > 1 )
mMapCanvas->panToSelected( layers );
else
mMapCanvas->panToSelected();
}
@@ -156,23 +156,19 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addAction( zoomToLayers );
if ( vlayer )
{
QList<QgsMapLayer *> selectedLayers = mView->selectedLayers();
bool hasSelectedFeature;
for ( int i = 0; i < selectedLayers.size(); ++i )
const QList<QgsMapLayer *> selectedLayers = mView->selectedLayers();
bool hasSelectedFeature = false;
for ( const QgsMapLayer *layer : selectedLayers )
{
QgsMapLayer *layer = selectedLayers.at( i );

if ( layer->type() == QgsMapLayerType( 0 ) )
if ( const QgsVectorLayer *vLayer = qobject_cast<const QgsVectorLayer *>( layer ) )
{
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layer );

if ( !vLayer->selectedFeatureIds().isEmpty() )
if ( vLayer->selectedFeatureCount() > 0 )
{
hasSelectedFeature = true;
break;
}
else
hasSelectedFeature = false;
}

}
@@ -525,9 +525,9 @@ void QgsMapCanvasDockWidget::showLabels( bool show )
void QgsMapCanvasDockWidget::autoZoomToSelection( bool autoZoom )
{
if ( autoZoom )
connect( mMapCanvas, &QgsMapCanvas::selectionChanged, mMapCanvas, &QgsMapCanvas::zoomToSelected );
connect( mMapCanvas, &QgsMapCanvas::selectionChanged, mMapCanvas, qgis::overload<QgsVectorLayer *>::of( &QgsMapCanvas::zoomToSelected ) );
else
disconnect( mMapCanvas, &QgsMapCanvas::selectionChanged, mMapCanvas, &QgsMapCanvas::zoomToSelected );
disconnect( mMapCanvas, &QgsMapCanvas::selectionChanged, mMapCanvas, qgis::overload<QgsVectorLayer *>::of( &QgsMapCanvas::zoomToSelected ) );
}

QgsMapSettingsAction::QgsMapSettingsAction( QWidget *parent )
@@ -312,16 +312,12 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas )

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

if ( mView->currentLayer()->type() == QgsMapLayerType( 0 ) )
layer = qobject_cast<QgsVectorLayer *>( mView->currentLayer() );

QList<QgsMapLayer *> layers = mView->selectedLayers();

if ( layers.size() > 1 && !layers.isEmpty() )
canvas->zoomToAllSelected( &layers );
const QList<QgsMapLayer *> layers = mView->selectedLayers();

if ( layers.size() > 1 )
canvas->zoomToSelected( layers );
else if ( layers.size() <= 1 && layer )
canvas->zoomToSelected( layer );

@@ -1349,19 +1349,16 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer *layer )
zoomToFeatureExtent( rect );
}

void QgsMapCanvas::zoomToAllSelected( const QList<QgsMapLayer *> *layers )
void QgsMapCanvas::zoomToSelected( const QList<QgsMapLayer *> &layers )
{
QgsVectorLayer *layer;

QgsRectangle rect;
rect.setMinimal();
QgsRectangle selectionExtent;
selectionExtent.setMinimal();

for ( int i = 0; i < layers->size(); ++i )
for ( QgsMapLayer *mapLayer : layers )
{
if ( layers->at( i )->type() == QgsMapLayerType( 0 ) )
layer = qobject_cast<QgsVectorLayer *>( layers->at( i ) );
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer );

if ( !layer || !layer->isSpatial() || layer->selectedFeatureCount() == 0 )
continue;
@@ -1539,19 +1536,16 @@ void QgsMapCanvas::panToSelected( QgsVectorLayer *layer )
refresh();
}

void QgsMapCanvas::panToAllSelected( const QList<QgsMapLayer *> *layers )
void QgsMapCanvas::panToSelected( const QList<QgsMapLayer *> &layers )
{
QgsVectorLayer *layer;

QgsRectangle rect;
rect.setMinimal();
QgsRectangle selectionExtent;
selectionExtent.setMinimal();

for ( int i = 0; i < layers->size(); ++i )
for ( QgsMapLayer *mapLayer : layers )
{
if ( layers->at( i )->type() == QgsMapLayerType( 0 ) )
layer = qobject_cast<QgsVectorLayer *>( layers->at( i ) );
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer );

if ( !layer || !layer->isSpatial() || layer->selectedFeatureCount() == 0 )
continue;
@@ -314,8 +314,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
/**
* Pan to the combined extent of the selected features of all provided (vector) layers.
* \param layers A list of layers
* \since QGIS 3.18
*/
void panToAllSelected( const QList<QgsMapLayer *> *layers );
void panToSelected( const QList<QgsMapLayer *> &layers );

/**
* Causes a set of features with matching \a ids from a vector \a layer to flash
@@ -875,8 +876,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
/**
* Zoom to the combined extent of the selected features of all provided (vector) layers.
* \param layers A list of layers
* \since QGIS 3.18
*/
void zoomToAllSelected( const QList<QgsMapLayer *> *layers );
void zoomToSelected( const QList<QgsMapLayer *> &layers );

/**
* Set a list of resolutions (map units per pixel) to which to "snap to" when zooming the map

0 comments on commit cf3bee3

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