mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
fix zoomToSelected with geometry-less layer or features
This commit is contained in:
parent
7aec4d1a5f
commit
14b8435f1b
@ -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() )
|
||||
QgsRectangle rect = layer->boundingBoxOfSelected();
|
||||
if (rect.isNull())
|
||||
{
|
||||
setCenter( rect.center() );
|
||||
refresh();
|
||||
emit messageEmitted( tr( "Cannot pan to selected feature(s)" ), tr( "No extent could be determined." ), QgsMessageBar::WARNING );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit messageEmitted( tr( "Cannot pan to selected feature(s)" ), tr( "Geometry is NULL" ), QgsMessageBar::WARNING );
|
||||
}
|
||||
} // panToSelected
|
||||
|
||||
rect = mapSettings().layerExtentToOutputExtent( layer, rect );
|
||||
setCenter( rect.center() );
|
||||
refresh();
|
||||
}
|
||||
|
||||
void QgsMapCanvas::keyPressEvent( QKeyEvent *e )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user