Skip to content

Commit 1173506

Browse files
authoredApr 20, 2018
Merge pull request #6808 from m-kuhn/fixxxxes
Some minor code fixes
2 parents f914762 + 62ca029 commit 1173506

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed
 

‎src/core/symbology/qgsrulebasedrenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ bool QgsRuleBasedRenderer::Rule::isFilterOK( const QgsFeature &f, QgsRenderConte
253253

254254
context->expressionContext().setFeature( f );
255255
QVariant res = mFilter->evaluate( &context->expressionContext() );
256-
return res.toInt() != 0;
256+
return res.toBool();
257257
}
258258

259259
bool QgsRuleBasedRenderer::Rule::isScaleOK( double scale ) const

‎src/gui/qgsmaptoolidentify.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,9 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg
241241
{
242242
Q_UNUSED( cse );
243243
// 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() ) );
245245
}
246246

247-
QgsFeatureList::iterator f_it = featureList.begin();
248-
249247
bool filter = false;
250248

251249
QgsRenderContext context( QgsRenderContext::fromMapSettings( mCanvas->mapSettings() ) );
@@ -258,23 +256,23 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg
258256
filter = renderer->capabilities() & QgsFeatureRenderer::Filter;
259257
}
260258

261-
for ( ; f_it != featureList.end(); ++f_it )
259+
for ( const QgsFeature &feature : qgis::as_const( featureList ) )
262260
{
263261
QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
264262

265-
QgsFeatureId fid = f_it->id();
266-
context.expressionContext().setFeature( *f_it );
263+
QgsFeatureId fid = feature.id();
264+
context.expressionContext().setFeature( feature );
267265

268-
if ( filter && !renderer->willRenderFeature( *f_it, context ) )
266+
if ( filter && !renderer->willRenderFeature( feature, context ) )
269267
continue;
270268

271269
featureCount++;
272270

273-
derivedAttributes.unite( featureDerivedAttributes( &( *f_it ), layer, toLayerCoordinates( layer, point ) ) );
271+
derivedAttributes.unite( featureDerivedAttributes( feature, layer, toLayerCoordinates( layer, point ) ) );
274272

275273
derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : FID_TO_STRING( fid ) );
276274

277-
results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
275+
results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), feature, derivedAttributes ) );
278276
}
279277

280278
if ( renderer )
@@ -341,7 +339,7 @@ QString QgsMapToolIdentify::formatYCoordinate( const QgsPointXY &canvasPoint ) c
341339
return coordinate.split( ',' ).at( 1 );
342340
}
343341

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 )
345343
{
346344
// Calculate derived attributes and insert:
347345
// measure distance or area depending on geometry type
@@ -358,30 +356,30 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
358356

359357
QgsVertexId vId;
360358
QgsPoint closestPoint;
361-
if ( feature->hasGeometry() )
359+
if ( feature.hasGeometry() )
362360
{
363-
geometryType = feature->geometry().type();
364-
wkbType = feature->geometry().wkbType();
361+
geometryType = feature.geometry().type();
362+
wkbType = feature.geometry().wkbType();
365363
//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 );
367365
}
368366

369367
if ( QgsWkbTypes::isMultiType( wkbType ) )
370368
{
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() );
372370
derivedAttributes.insert( tr( "Parts" ), str );
373371
str = QLocale::system().toString( vId.part + 1 );
374372
derivedAttributes.insert( tr( "Part number" ), str );
375373
}
376374

377375
if ( geometryType == QgsWkbTypes::LineGeometry )
378376
{
379-
double dist = calc.measureLength( feature->geometry() );
377+
double dist = calc.measureLength( feature.geometry() );
380378
dist = calc.convertLengthMeasurement( dist, displayDistanceUnits() );
381379
QString str = formatDistance( dist );
382380
derivedAttributes.insert( tr( "Length" ), str );
383381

384-
const QgsAbstractGeometry *geom = feature->geometry().constGet();
382+
const QgsAbstractGeometry *geom = feature.geometry().constGet();
385383
if ( geom )
386384
{
387385
str = QLocale::system().toString( geom->nCoordinates() );
@@ -407,41 +405,41 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
407405
}
408406
else if ( geometryType == QgsWkbTypes::PolygonGeometry )
409407
{
410-
double area = calc.measureArea( feature->geometry() );
408+
double area = calc.measureArea( feature.geometry() );
411409
area = calc.convertAreaMeasurement( area, displayAreaUnits() );
412410
QString str = formatArea( area );
413411
derivedAttributes.insert( tr( "Area" ), str );
414412

415-
double perimeter = calc.measurePerimeter( feature->geometry() );
413+
double perimeter = calc.measurePerimeter( feature.geometry() );
416414
perimeter = calc.convertLengthMeasurement( perimeter, displayDistanceUnits() );
417415
str = formatDistance( perimeter );
418416
derivedAttributes.insert( tr( "Perimeter" ), str );
419417

420-
str = QLocale::system().toString( feature->geometry().constGet()->nCoordinates() );
418+
str = QLocale::system().toString( feature.geometry().constGet()->nCoordinates() );
421419
derivedAttributes.insert( tr( "Vertices" ), str );
422420

423421
//add details of closest vertex to identify point
424-
closestVertexAttributes( *feature->geometry().constGet(), vId, layer, derivedAttributes );
422+
closestVertexAttributes( *feature.geometry().constGet(), vId, layer, derivedAttributes );
425423
}
426424
else if ( geometryType == QgsWkbTypes::PointGeometry )
427425
{
428426
if ( QgsWkbTypes::flatType( wkbType ) == QgsWkbTypes::Point )
429427
{
430428
// 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() );
432430
QString str = formatXCoordinate( pnt );
433431
derivedAttributes.insert( QStringLiteral( "X" ), str );
434432
str = formatYCoordinate( pnt );
435433
derivedAttributes.insert( QStringLiteral( "Y" ), str );
436434

437435
if ( QgsWkbTypes::hasZ( wkbType ) )
438436
{
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 );
440438
derivedAttributes.insert( QStringLiteral( "Z" ), str );
441439
}
442440
if ( QgsWkbTypes::hasM( wkbType ) )
443441
{
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 );
445443
derivedAttributes.insert( QStringLiteral( "M" ), str );
446444
}
447445
}
@@ -450,7 +448,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
450448
//multipart
451449

452450
//add details of closest vertex to identify point
453-
const QgsAbstractGeometry *geom = feature->geometry().constGet();
451+
const QgsAbstractGeometry *geom = feature.geometry().constGet();
454452
{
455453
closestVertexAttributes( *geom, vId, layer, derivedAttributes );
456454
}
@@ -482,10 +480,10 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
482480
catch ( QgsCsException &cse )
483481
{
484482
Q_UNUSED( cse );
485-
QgsDebugMsg( QString( "coordinate not reprojectable: %1" ).arg( cse.what() ) );
483+
QgsDebugMsg( QStringLiteral( "coordinate not reprojectable: %1" ).arg( cse.what() ) );
486484
return false;
487485
}
488-
QgsDebugMsg( QString( "point = %1 %2" ).arg( point.x() ).arg( point.y() ) );
486+
QgsDebugMsg( QStringLiteral( "point = %1 %2" ).arg( point.x() ).arg( point.y() ) );
489487

490488
if ( !layer->extent().contains( point ) )
491489
return false;
@@ -541,9 +539,9 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
541539
int width = std::round( viewExtent.width() / mapUnitsPerPixel );
542540
int height = std::round( viewExtent.height() / mapUnitsPerPixel );
543541

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 ) );
547545

548546
identifyResult = dprovider->identify( point, format, viewExtent, width, height );
549547
}
@@ -634,7 +632,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
634632
}
635633

636634
QMap< QString, QString > derAttributes = derivedAttributes;
637-
derAttributes.unite( featureDerivedAttributes( &feature, layer ) );
635+
derAttributes.unite( featureDerivedAttributes( feature, layer ) );
638636

639637
IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join( QStringLiteral( " / " ) ), featureStore.fields(), feature, derAttributes );
640638

@@ -646,7 +644,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
646644
}
647645
else // text or html
648646
{
649-
QgsDebugMsg( QString( "%1 HTML or text values" ).arg( values.size() ) );
647+
QgsDebugMsg( QStringLiteral( "%1 HTML or text values" ).arg( values.size() ) );
650648
for ( auto it = values.constBegin(); it != values.constEnd(); ++it )
651649
{
652650
QString value = it.value().toString();

‎src/gui/qgsmaptoolidentify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
189189
*/
190190
QString formatArea( double area ) const;
191191

192-
QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
192+
QMap< QString, QString > featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
193193

194194
/**
195195
* Adds details of the closest vertex to derived attributes

0 commit comments

Comments
 (0)
Please sign in to comment.