Skip to content
Permalink
Browse files

fix zoomToSelected with geometry-less layer or features

  • Loading branch information
3nids committed Jun 15, 2017
1 parent 7aec4d1 commit 14b8435f1b7027b88306d60ba12c9a1a3fa0ad53
Showing with 20 additions and 13 deletions.
  1. +1 −1 src/core/qgsvectorlayer.cpp
  2. +19 −12 src/gui/qgsmapcanvas.cpp
@@ -623,7 +623,7 @@ QgsWkbTypes::Type QgsVectorLayer::wkbType() const

QgsRectangle QgsVectorLayer::boundingBoxOfSelected() const
{
if ( !mValid || mSelectedFeatureIds.isEmpty() ) //no selected features
if ( !mValid || !hasGeometryType() || mSelectedFeatureIds.isEmpty() ) //no selected features
{
return QgsRectangle( 0, 0, 0, 0 );
}
@@ -913,10 +913,17 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer *layer )
layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
}

if ( !layer || layer->selectedFeatureCount() == 0 )
if ( !layer || !layer->hasGeometryType() || layer->selectedFeatureCount() == 0 )
return;

QgsRectangle rect = mapSettings().layerExtentToOutputExtent( layer, layer->boundingBoxOfSelected() );
QgsRectangle rect = layer->boundingBoxOfSelected();
if (rect.isNull())
{
emit messageEmitted( tr( "Cannot zoom to selected feature(s)" ), tr( "No extent could be determined." ), QgsMessageBar::WARNING );
return;
}

rect = mapSettings().layerExtentToOutputExtent( layer, rect );
zoomToFeatureExtent( rect );
} // zoomToSelected

@@ -1029,20 +1036,20 @@ void QgsMapCanvas::panToSelected( QgsVectorLayer *layer )
layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
}

if ( !layer || layer->selectedFeatureCount() == 0 )
if ( !layer || !layer->hasGeometryType() || layer->selectedFeatureCount() == 0 )
return;

QgsRectangle rect = mapSettings().layerExtentToOutputExtent( layer, layer->boundingBoxOfSelected() );
if ( !rect.isNull() )
{
setCenter( rect.center() );
refresh();
}
else
QgsRectangle rect = layer->boundingBoxOfSelected();
if (rect.isNull())
{
emit messageEmitted( tr( "Cannot pan to selected feature(s)" ), tr( "Geometry is NULL" ), QgsMessageBar::WARNING );
emit messageEmitted( tr( "Cannot pan to selected feature(s)" ), tr( "No extent could be determined." ), QgsMessageBar::WARNING );
return;
}
} // panToSelected

rect = mapSettings().layerExtentToOutputExtent( layer, rect );
setCenter( rect.center() );
refresh();
}

void QgsMapCanvas::keyPressEvent( QKeyEvent *e )
{

0 comments on commit 14b8435

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