Skip to content

Commit b9d44e1

Browse files
committed
Fix zooming to identified features containing mixed point and non-point geometries always growing on each identification
1 parent 926ea79 commit b9d44e1

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/core/featurelistextentcontroller.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,31 @@ void FeatureListExtentController::zoomToSelected( bool skipIfIntersects ) const
9696

9797
void 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
}

src/core/utils/featureutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ QString FeatureUtils::displayName( QgsVectorLayer *layer, const QgsFeature &feat
7575
return name;
7676
}
7777

78-
QgsRectangle FeatureUtils::extent( QgsQuickMapSettings *mapSettings, QgsVectorLayer *layer, const QgsFeature &feature )
78+
QgsRectangle FeatureUtils::extent( QgsQuickMapSettings *mapSettings, QgsVectorLayer *layer, const QgsFeature &feature, bool skipSinglePointLogic )
7979
{
8080
if ( mapSettings && layer && layer->geometryType() != Qgis::GeometryType::Unknown && layer->geometryType() != Qgis::GeometryType::Null )
8181
{
@@ -85,7 +85,7 @@ QgsRectangle FeatureUtils::extent( QgsQuickMapSettings *mapSettings, QgsVectorLa
8585
{
8686
geom.transform( ct );
8787
QgsRectangle extent;
88-
if ( geom.type() == Qgis::GeometryType::Point && geom.constGet()->partCount() == 1 )
88+
if ( !skipSinglePointLogic && geom.type() == Qgis::GeometryType::Point && geom.constGet()->partCount() == 1 )
8989
{
9090
extent = mapSettings->extent();
9191
QgsVector delta = QgsPointXY( geom.asPoint() ) - extent.center();

src/core/utils/featureutils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ class QFIELD_CORE_EXPORT FeatureUtils : public QObject
7070
* \param mapSettings the map settings used to determine the CRS
7171
* \param layer the vector layer containing the feature
7272
* \param feature the feature from which the geometry will be used
73+
* \param skipSinglePointLogic when TRUE, the special handling for determining a single point extent will be skipped
7374
* \returns a QgsRectangle extent
7475
*/
75-
static Q_INVOKABLE QgsRectangle extent( QgsQuickMapSettings *mapSettings, QgsVectorLayer *layer, const QgsFeature &feature );
76+
static Q_INVOKABLE QgsRectangle extent( QgsQuickMapSettings *mapSettings, QgsVectorLayer *layer, const QgsFeature &feature, bool skipSinglePointLogic = false );
7677

7778
/**
7879
* Returns a list of features while attempting to parse a GeoJSON \a string. If the string could not

0 commit comments

Comments
 (0)