Skip to content

Commit 06766c4

Browse files
committedJul 19, 2018
Modernize code
1 parent daa7391 commit 06766c4

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed
 

‎src/core/raster/qgsrasterdataprovider.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,13 @@ QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPointXY &point
284284

285285
for ( int i = 1; i <= bandCount(); i++ )
286286
{
287-
QgsRasterBlock *myBlock = block( i, pixelExtent, 1, 1 );
287+
std::unique_ptr< QgsRasterBlock > bandBlock( block( i, pixelExtent, 1, 1 ) );
288288

289-
if ( myBlock )
289+
if ( bandBlock )
290290
{
291-
double value = myBlock->value( 0 );
291+
double value = bandBlock->value( 0 );
292292

293293
results.insert( i, value );
294-
delete myBlock;
295294
}
296295
else
297296
{

‎src/providers/arcgisrest/qgsamsprovider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,13 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPointXY &point, QgsRa
395395
queryUrl.addQueryItem( QStringLiteral( "imageDisplay" ), QStringLiteral( "%1,%2,%3" ).arg( width ).arg( height ).arg( dpi ) );
396396
queryUrl.addQueryItem( QStringLiteral( "mapExtent" ), QStringLiteral( "%1,%2,%3,%4" ).arg( extent.xMinimum(), 0, 'f' ).arg( extent.yMinimum(), 0, 'f' ).arg( extent.xMaximum(), 0, 'f' ).arg( extent.yMaximum(), 0, 'f' ) );
397397
queryUrl.addQueryItem( QStringLiteral( "tolerance" ), QStringLiteral( "10" ) );
398-
QVariantList queryResults = QgsArcGisRestUtils::queryServiceJSON( queryUrl, mErrorTitle, mError ).value( QStringLiteral( "results" ) ).toList();
398+
const QVariantList queryResults = QgsArcGisRestUtils::queryServiceJSON( queryUrl, mErrorTitle, mError ).value( QStringLiteral( "results" ) ).toList();
399399

400400
QMap<int, QVariant> entries;
401401

402402
if ( format == QgsRaster::IdentifyFormatText )
403403
{
404-
foreach ( const QVariant &result, queryResults )
404+
for ( const QVariant &result : queryResults )
405405
{
406406
const QVariantMap resultMap = result.toMap();
407407
QVariantMap attributesMap = resultMap[QStringLiteral( "attributes" )].toMap();
@@ -415,7 +415,7 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPointXY &point, QgsRa
415415
}
416416
else if ( format == QgsRaster::IdentifyFormatFeature )
417417
{
418-
foreach ( const QVariant &result, queryResults )
418+
for ( const QVariant &result : queryResults )
419419
{
420420
const QVariantMap resultMap = result.toMap();
421421

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,15 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
10221022
}
10231023

10241024
QgsRectangle finalExtent = boundingBox;
1025-
if ( finalExtent.isEmpty() ) finalExtent = extent();
1025+
if ( finalExtent.isEmpty() )
1026+
finalExtent = extent();
10261027

10271028
QgsDebugMsgLevel( QStringLiteral( "myExtent = %1 " ).arg( finalExtent.toString() ), 3 );
10281029

1029-
if ( width == 0 ) width = xSize();
1030-
if ( height == 0 ) height = ySize();
1030+
if ( width == 0 )
1031+
width = xSize();
1032+
if ( height == 0 )
1033+
height = ySize();
10311034

10321035
QgsDebugMsgLevel( QStringLiteral( "theWidth = %1 height = %2" ).arg( width ).arg( height ), 3 );
10331036

@@ -1036,8 +1039,8 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
10361039
double yres = ( finalExtent.height() ) / height;
10371040

10381041
// Offset, not the cell index -> std::floor
1039-
int col = ( int ) std::floor( ( point.x() - finalExtent.xMinimum() ) / xres );
1040-
int row = ( int ) std::floor( ( finalExtent.yMaximum() - point.y() ) / yres );
1042+
int col = static_cast< int >( std::floor( ( point.x() - finalExtent.xMinimum() ) / xres ) );
1043+
int row = static_cast< int >( std::floor( ( finalExtent.yMaximum() - point.y() ) / yres ) );
10411044

10421045
QgsDebugMsgLevel( QStringLiteral( "row = %1 col = %2" ).arg( row ).arg( col ), 3 );
10431046

@@ -1056,14 +1059,14 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
10561059

10571060
for ( int i = 1; i <= bandCount(); i++ )
10581061
{
1059-
QgsRasterBlock *myBlock = block( i, pixelExtent, w, h );
1062+
std::unique_ptr< QgsRasterBlock > bandBlock( block( i, pixelExtent, w, h ) );
10601063

1061-
if ( !myBlock )
1064+
if ( !bandBlock )
10621065
{
10631066
return QgsRasterIdentifyResult( ERR( tr( "Cannot read data" ) ) );
10641067
}
10651068

1066-
double value = myBlock->value( r, c );
1069+
double value = bandBlock->value( r, c );
10671070

10681071
if ( ( sourceHasNoDataValue( i ) && useSourceNoDataValue( i ) &&
10691072
( std::isnan( value ) || qgsDoubleNear( value, sourceNoDataValue( i ) ) ) ) ||
@@ -1082,7 +1085,6 @@ QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPointXY &point, QgsR
10821085
else
10831086
results.insert( i, value );
10841087
}
1085-
delete myBlock;
10861088
}
10871089
return QgsRasterIdentifyResult( QgsRaster::IdentifyFormatValue, results );
10881090
}

0 commit comments

Comments
 (0)
Please sign in to comment.