mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -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
|
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 );
|
return QgsRectangle( 0, 0, 0, 0 );
|
||||||
}
|
}
|
||||||
|
@ -913,10 +913,17 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer *layer )
|
|||||||
layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
|
layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !layer || layer->selectedFeatureCount() == 0 )
|
if ( !layer || !layer->hasGeometryType() || layer->selectedFeatureCount() == 0 )
|
||||||
return;
|
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 );
|
zoomToFeatureExtent( rect );
|
||||||
} // zoomToSelected
|
} // zoomToSelected
|
||||||
|
|
||||||
@ -1029,20 +1036,20 @@ void QgsMapCanvas::panToSelected( QgsVectorLayer *layer )
|
|||||||
layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
|
layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !layer || layer->selectedFeatureCount() == 0 )
|
if ( !layer || !layer->hasGeometryType() || layer->selectedFeatureCount() == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QgsRectangle rect = mapSettings().layerExtentToOutputExtent( layer, layer->boundingBoxOfSelected() );
|
QgsRectangle rect = layer->boundingBoxOfSelected();
|
||||||
if ( !rect.isNull() )
|
if (rect.isNull())
|
||||||
{
|
{
|
||||||
|
emit messageEmitted( tr( "Cannot pan to selected feature(s)" ), tr( "No extent could be determined." ), QgsMessageBar::WARNING );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rect = mapSettings().layerExtentToOutputExtent( layer, rect );
|
||||||
setCenter( rect.center() );
|
setCenter( rect.center() );
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
emit messageEmitted( tr( "Cannot pan to selected feature(s)" ), tr( "Geometry is NULL" ), QgsMessageBar::WARNING );
|
|
||||||
}
|
|
||||||
} // panToSelected
|
|
||||||
|
|
||||||
void QgsMapCanvas::keyPressEvent( QKeyEvent *e )
|
void QgsMapCanvas::keyPressEvent( QKeyEvent *e )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user