@@ -241,11 +241,9 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg
241
241
{
242
242
Q_UNUSED ( cse );
243
243
// catch exception for 'invalid' point and proceed with no features found
244
- QgsDebugMsg ( QString ( " Caught CRS exception %1" ).arg ( cse.what () ) );
244
+ QgsDebugMsg ( QStringLiteral ( " Caught CRS exception %1" ).arg ( cse.what () ) );
245
245
}
246
246
247
- QgsFeatureList::iterator f_it = featureList.begin ();
248
-
249
247
bool filter = false ;
250
248
251
249
QgsRenderContext context ( QgsRenderContext::fromMapSettings ( mCanvas ->mapSettings () ) );
@@ -258,23 +256,23 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg
258
256
filter = renderer->capabilities () & QgsFeatureRenderer::Filter;
259
257
}
260
258
261
- for ( ; f_it != featureList. end (); ++f_it )
259
+ for ( const QgsFeature &feature : qgis::as_const ( featureList ) )
262
260
{
263
261
QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
264
262
265
- QgsFeatureId fid = f_it-> id ();
266
- context.expressionContext ().setFeature ( *f_it );
263
+ QgsFeatureId fid = feature. id ();
264
+ context.expressionContext ().setFeature ( feature );
267
265
268
- if ( filter && !renderer->willRenderFeature ( *f_it , context ) )
266
+ if ( filter && !renderer->willRenderFeature ( feature , context ) )
269
267
continue ;
270
268
271
269
featureCount++;
272
270
273
- derivedAttributes.unite ( featureDerivedAttributes ( &( *f_it ) , layer, toLayerCoordinates ( layer, point ) ) );
271
+ derivedAttributes.unite ( featureDerivedAttributes ( feature , layer, toLayerCoordinates ( layer, point ) ) );
274
272
275
273
derivedAttributes.insert ( tr ( " feature id" ), fid < 0 ? tr ( " new feature" ) : FID_TO_STRING ( fid ) );
276
274
277
- results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), *f_it , derivedAttributes ) );
275
+ results->append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ), feature , derivedAttributes ) );
278
276
}
279
277
280
278
if ( renderer )
@@ -341,7 +339,7 @@ QString QgsMapToolIdentify::formatYCoordinate( const QgsPointXY &canvasPoint ) c
341
339
return coordinate.split ( ' ,' ).at ( 1 );
342
340
}
343
341
344
- QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes ( QgsFeature * feature, QgsMapLayer *layer, const QgsPointXY &layerPoint )
342
+ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes ( const QgsFeature & feature, QgsMapLayer *layer, const QgsPointXY &layerPoint )
345
343
{
346
344
// Calculate derived attributes and insert:
347
345
// measure distance or area depending on geometry type
@@ -358,30 +356,30 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
358
356
359
357
QgsVertexId vId;
360
358
QgsPoint closestPoint;
361
- if ( feature-> hasGeometry () )
359
+ if ( feature. hasGeometry () )
362
360
{
363
- geometryType = feature-> geometry ().type ();
364
- wkbType = feature-> geometry ().wkbType ();
361
+ geometryType = feature. geometry ().type ();
362
+ wkbType = feature. geometry ().wkbType ();
365
363
// find closest vertex to clicked point
366
- closestPoint = QgsGeometryUtils::closestVertex ( *feature-> geometry ().constGet (), QgsPoint ( layerPoint.x (), layerPoint.y () ), vId );
364
+ closestPoint = QgsGeometryUtils::closestVertex ( *feature. geometry ().constGet (), QgsPoint ( layerPoint.x (), layerPoint.y () ), vId );
367
365
}
368
366
369
367
if ( QgsWkbTypes::isMultiType ( wkbType ) )
370
368
{
371
- QString str = QLocale::system ().toString ( static_cast <const QgsGeometryCollection *>( feature-> geometry ().constGet () )->numGeometries () );
369
+ QString str = QLocale::system ().toString ( static_cast <const QgsGeometryCollection *>( feature. geometry ().constGet () )->numGeometries () );
372
370
derivedAttributes.insert ( tr ( " Parts" ), str );
373
371
str = QLocale::system ().toString ( vId.part + 1 );
374
372
derivedAttributes.insert ( tr ( " Part number" ), str );
375
373
}
376
374
377
375
if ( geometryType == QgsWkbTypes::LineGeometry )
378
376
{
379
- double dist = calc.measureLength ( feature-> geometry () );
377
+ double dist = calc.measureLength ( feature. geometry () );
380
378
dist = calc.convertLengthMeasurement ( dist, displayDistanceUnits () );
381
379
QString str = formatDistance ( dist );
382
380
derivedAttributes.insert ( tr ( " Length" ), str );
383
381
384
- const QgsAbstractGeometry *geom = feature-> geometry ().constGet ();
382
+ const QgsAbstractGeometry *geom = feature. geometry ().constGet ();
385
383
if ( geom )
386
384
{
387
385
str = QLocale::system ().toString ( geom->nCoordinates () );
@@ -407,41 +405,41 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
407
405
}
408
406
else if ( geometryType == QgsWkbTypes::PolygonGeometry )
409
407
{
410
- double area = calc.measureArea ( feature-> geometry () );
408
+ double area = calc.measureArea ( feature. geometry () );
411
409
area = calc.convertAreaMeasurement ( area, displayAreaUnits () );
412
410
QString str = formatArea ( area );
413
411
derivedAttributes.insert ( tr ( " Area" ), str );
414
412
415
- double perimeter = calc.measurePerimeter ( feature-> geometry () );
413
+ double perimeter = calc.measurePerimeter ( feature. geometry () );
416
414
perimeter = calc.convertLengthMeasurement ( perimeter, displayDistanceUnits () );
417
415
str = formatDistance ( perimeter );
418
416
derivedAttributes.insert ( tr ( " Perimeter" ), str );
419
417
420
- str = QLocale::system ().toString ( feature-> geometry ().constGet ()->nCoordinates () );
418
+ str = QLocale::system ().toString ( feature. geometry ().constGet ()->nCoordinates () );
421
419
derivedAttributes.insert ( tr ( " Vertices" ), str );
422
420
423
421
// add details of closest vertex to identify point
424
- closestVertexAttributes ( *feature-> geometry ().constGet (), vId, layer, derivedAttributes );
422
+ closestVertexAttributes ( *feature. geometry ().constGet (), vId, layer, derivedAttributes );
425
423
}
426
424
else if ( geometryType == QgsWkbTypes::PointGeometry )
427
425
{
428
426
if ( QgsWkbTypes::flatType ( wkbType ) == QgsWkbTypes::Point )
429
427
{
430
428
// Include the x and y coordinates of the point as a derived attribute
431
- QgsPointXY pnt = mCanvas ->mapSettings ().layerToMapCoordinates ( layer, feature-> geometry ().asPoint () );
429
+ QgsPointXY pnt = mCanvas ->mapSettings ().layerToMapCoordinates ( layer, feature. geometry ().asPoint () );
432
430
QString str = formatXCoordinate ( pnt );
433
431
derivedAttributes.insert ( QStringLiteral ( " X" ), str );
434
432
str = formatYCoordinate ( pnt );
435
433
derivedAttributes.insert ( QStringLiteral ( " Y" ), str );
436
434
437
435
if ( QgsWkbTypes::hasZ ( wkbType ) )
438
436
{
439
- str = QLocale::system ().toString ( static_cast <const QgsPoint *>( feature-> geometry ().constGet () )->z (), ' g' , 10 );
437
+ str = QLocale::system ().toString ( static_cast <const QgsPoint *>( feature. geometry ().constGet () )->z (), ' g' , 10 );
440
438
derivedAttributes.insert ( QStringLiteral ( " Z" ), str );
441
439
}
442
440
if ( QgsWkbTypes::hasM ( wkbType ) )
443
441
{
444
- str = QLocale::system ().toString ( static_cast <const QgsPoint *>( feature-> geometry ().constGet () )->m (), ' g' , 10 );
442
+ str = QLocale::system ().toString ( static_cast <const QgsPoint *>( feature. geometry ().constGet () )->m (), ' g' , 10 );
445
443
derivedAttributes.insert ( QStringLiteral ( " M" ), str );
446
444
}
447
445
}
@@ -450,7 +448,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
450
448
// multipart
451
449
452
450
// add details of closest vertex to identify point
453
- const QgsAbstractGeometry *geom = feature-> geometry ().constGet ();
451
+ const QgsAbstractGeometry *geom = feature. geometry ().constGet ();
454
452
{
455
453
closestVertexAttributes ( *geom, vId, layer, derivedAttributes );
456
454
}
@@ -482,10 +480,10 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
482
480
catch ( QgsCsException &cse )
483
481
{
484
482
Q_UNUSED ( cse );
485
- QgsDebugMsg ( QString ( " coordinate not reprojectable: %1" ).arg ( cse.what () ) );
483
+ QgsDebugMsg ( QStringLiteral ( " coordinate not reprojectable: %1" ).arg ( cse.what () ) );
486
484
return false ;
487
485
}
488
- QgsDebugMsg ( QString ( " point = %1 %2" ).arg ( point.x () ).arg ( point.y () ) );
486
+ QgsDebugMsg ( QStringLiteral ( " point = %1 %2" ).arg ( point.x () ).arg ( point.y () ) );
489
487
490
488
if ( !layer->extent ().contains ( point ) )
491
489
return false ;
@@ -541,9 +539,9 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
541
539
int width = std::round ( viewExtent.width () / mapUnitsPerPixel );
542
540
int height = std::round ( viewExtent.height () / mapUnitsPerPixel );
543
541
544
- QgsDebugMsg ( QString ( " viewExtent.width = %1 viewExtent.height = %2" ).arg ( viewExtent.width () ).arg ( viewExtent.height () ) );
545
- QgsDebugMsg ( QString ( " width = %1 height = %2" ).arg ( width ).arg ( height ) );
546
- QgsDebugMsg ( QString ( " xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg ( viewExtent.width () / width ).arg ( viewExtent.height () / height ).arg ( mapUnitsPerPixel ) );
542
+ QgsDebugMsg ( QStringLiteral ( " viewExtent.width = %1 viewExtent.height = %2" ).arg ( viewExtent.width () ).arg ( viewExtent.height () ) );
543
+ QgsDebugMsg ( QStringLiteral ( " width = %1 height = %2" ).arg ( width ).arg ( height ) );
544
+ QgsDebugMsg ( QStringLiteral ( " xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg ( viewExtent.width () / width ).arg ( viewExtent.height () / height ).arg ( mapUnitsPerPixel ) );
547
545
548
546
identifyResult = dprovider->identify ( point, format, viewExtent, width, height );
549
547
}
@@ -634,7 +632,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
634
632
}
635
633
636
634
QMap< QString, QString > derAttributes = derivedAttributes;
637
- derAttributes.unite ( featureDerivedAttributes ( & feature, layer ) );
635
+ derAttributes.unite ( featureDerivedAttributes ( feature, layer ) );
638
636
639
637
IdentifyResult identifyResult ( qobject_cast<QgsMapLayer *>( layer ), labels.join ( QStringLiteral ( " / " ) ), featureStore.fields (), feature, derAttributes );
640
638
@@ -646,7 +644,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
646
644
}
647
645
else // text or html
648
646
{
649
- QgsDebugMsg ( QString ( " %1 HTML or text values" ).arg ( values.size () ) );
647
+ QgsDebugMsg ( QStringLiteral ( " %1 HTML or text values" ).arg ( values.size () ) );
650
648
for ( auto it = values.constBegin (); it != values.constEnd (); ++it )
651
649
{
652
650
QString value = it.value ().toString ();
0 commit comments