@@ -96,25 +96,31 @@ void FeatureListExtentController::zoomToSelected( bool skipIfIntersects ) const
9696
9797void FeatureListExtentController::zoomToAllFeatures () const
9898{
99- if ( !mModel || !mMapSettings || mModel ->rowCount ( QModelIndex () ) == 0 )
99+ if ( !mModel || !mMapSettings )
100+ {
100101 return ;
102+ }
101103
102- QgsRectangle combinedExtent;
103- bool hasNonPointGeometry = false ;
104+ const int rowCount = mModel ->rowCount ( QModelIndex () );
105+ if ( rowCount == 0 )
106+ {
107+ return ;
108+ }
104109
110+ bool isSinglePointGeometry = rowCount == 1 ; // Further assessed down below
111+ QgsRectangle combinedExtent;
105112 for ( int i = 0 ; i < mModel ->rowCount ( QModelIndex () ); ++i )
106113 {
107114 const QModelIndex index = mModel ->index ( i, 0 );
108115 QgsVectorLayer *layer = qvariant_cast<QgsVectorLayer *>( mModel ->data ( index, MultiFeatureListModel::LayerRole ) );
109- const QgsFeature feature = mModel ->data ( index, MultiFeatureListModel::FeatureRole ).value <QgsFeature>();
110-
111116 if ( !layer || layer->geometryType () == Qgis::GeometryType::Unknown || layer->geometryType () == Qgis::GeometryType::Null )
112117 {
113118 continue ;
114119 }
115120
116121 try
117122 {
123+ const QgsFeature feature = mModel ->data ( index, MultiFeatureListModel::FeatureRole ).value <QgsFeature>();
118124 const QgsGeometry geom ( feature.geometry () );
119125 if ( geom.isNull () )
120126 {
@@ -123,10 +129,10 @@ void FeatureListExtentController::zoomToAllFeatures() const
123129
124130 if ( geom.type () != Qgis::GeometryType::Point || geom.constGet ()->partCount () > 1 )
125131 {
126- hasNonPointGeometry = true ;
132+ isSinglePointGeometry = false ;
127133 }
128134
129- const QgsRectangle extent = FeatureUtils::extent ( mMapSettings , layer, feature );
135+ const QgsRectangle extent = FeatureUtils::extent ( mMapSettings , layer, feature, !isSinglePointGeometry );
130136 if ( extent.isNull () )
131137 {
132138 continue ;
@@ -153,7 +159,7 @@ void FeatureListExtentController::zoomToAllFeatures() const
153159 const double buffer = std::max ( combinedExtent.width (), combinedExtent.height () ) * 0.5 ;
154160 combinedExtent = combinedExtent.buffered ( buffer );
155161
156- const double scale = ( mKeepScale || !hasNonPointGeometry ) ? -1 : mMapSettings ->computeScaleForExtent ( combinedExtent, true );
162+ const double scale = ( mKeepScale || isSinglePointGeometry ) ? -1 : mMapSettings ->computeScaleForExtent ( combinedExtent, true );
157163 emit requestJumpToPoint ( QgsPoint ( combinedExtent.center () ), scale, true );
158164 }
159165}
0 commit comments