@@ -190,12 +190,12 @@ void QgsMapToolIdentify::deactivate()
190190 QgsMapTool::deactivate ();
191191}
192192
193- bool QgsMapToolIdentify::identifyLayer ( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, LayerType layerType )
193+ bool QgsMapToolIdentify::identifyLayer ( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify:: LayerType layerType )
194194{
195195 return identifyLayer ( results, layer, QgsGeometry::fromPointXY ( point ), viewExtent, mapUnitsPerPixel, layerType );
196196}
197197
198- bool QgsMapToolIdentify::identifyLayer ( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, LayerType layerType )
198+ bool QgsMapToolIdentify::identifyLayer ( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify:: LayerType layerType )
199199{
200200 if ( layer->type () == QgsMapLayer::RasterLayer && layerType.testFlag ( RasterLayer ) )
201201 {
@@ -232,16 +232,22 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<QgsMapToolIdentify::Identify
232232 QMap< QString, QString > commonDerivedAttributes;
233233
234234 QgsGeometry selectionGeom = geometry;
235- bool isPointOrRectangle = true ; // TODO: replace with a proper check
235+ bool isPointOrRectangle;
236236 QgsPointXY point;
237237 bool isSingleClick = selectionGeom.type () == QgsWkbTypes::PointGeometry;
238238 if ( isSingleClick )
239239 {
240+ isPointOrRectangle = true ;
240241 point = selectionGeom.asPoint ();
241242
242243 commonDerivedAttributes.insert ( tr ( " (clicked coordinate X)" ), formatXCoordinate ( point ) );
243244 commonDerivedAttributes.insert ( tr ( " (clicked coordinate Y)" ), formatYCoordinate ( point ) );
244245 }
246+ else
247+ {
248+ // we have a polygon - maybe it is a rectangle - in such case we can avoid costly insterestion tests later
249+ isPointOrRectangle = QgsGeometry::fromRect ( selectionGeom.boundingBox () ).isGeosEqual ( selectionGeom );
250+ }
245251
246252 int featureCount = 0 ;
247253
@@ -261,16 +267,17 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<QgsMapToolIdentify::Identify
261267 else
262268 {
263269 r = toLayerCoordinates ( layer, selectionGeom.boundingBox () );
270+
271+ if ( !isPointOrRectangle )
272+ {
273+ QgsCoordinateTransform ct ( mCanvas ->mapSettings ().destinationCrs (), layer->crs (), mCanvas ->mapSettings ().transformContext () );
274+ if ( ct.isValid () )
275+ selectionGeom.transform ( ct );
276+ }
264277 }
265278
266279 QgsFeatureIterator fit = layer->getFeatures ( QgsFeatureRequest ().setFilterRect ( r ).setFlags ( QgsFeatureRequest::ExactIntersect ) );
267280 QgsFeature f;
268-
269-
270- QgsCoordinateTransform ct = QgsCoordinateTransform ( mCanvas ->mapSettings ().destinationCrs (), layer->crs (), mCanvas ->mapSettings ().transformContext () );
271- if ( ct.isValid () )
272- selectionGeom.transform ( ct );
273-
274281 while ( fit.nextFeature ( f ) )
275282 {
276283 if ( isPointOrRectangle || selectionGeom.intersects ( f.geometry () ) )
0 commit comments