Skip to content

Commit

Permalink
fix zoomToSelected with geometry-less layer or features
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jun 15, 2017
1 parent 7aec4d1 commit 14b8435
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
31 changes: 19 additions & 12 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 )
{
Expand Down

0 comments on commit 14b8435

Please sign in to comment.