Skip to content

Commit d79dd73

Browse files
committedJul 20, 2018
Modernize code
1 parent 4fccc5e commit d79dd73

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
lines changed
 

‎src/3d/terrain/qgsdemterraintileloader_p.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static QByteArray _readDtmData( QgsRasterDataProvider *provider, const QgsRectan
162162
projector->setInput( provider );
163163
input = projector.get();
164164
}
165-
QgsRasterBlock *block = input->block( 1, extent, res, res );
165+
std::unique_ptr< QgsRasterBlock > block( input->block( 1, extent, res, res ) );
166166

167167
QByteArray data;
168168
if ( block )
@@ -183,8 +183,6 @@ static QByteArray _readDtmData( QgsRasterDataProvider *provider, const QgsRectan
183183
floatData[i] = std::numeric_limits<float>::quiet_NaN();
184184
}
185185
}
186-
187-
delete block;
188186
}
189187
return data;
190188
}
@@ -227,15 +225,14 @@ QByteArray QgsDemHeightMapGenerator::renderSynchronously( int x, int y, int z )
227225
QgsRectangle fullExtent = mTilingScheme.tileToExtent( 0, 0, 0 );
228226
extent = extent.intersect( fullExtent );
229227

230-
QgsRasterBlock *block = mDtm->dataProvider()->block( 1, extent, mResolution, mResolution );
228+
std::unique_ptr< QgsRasterBlock > block( mDtm->dataProvider()->block( 1, extent, mResolution, mResolution ) );
231229

232230
QByteArray data;
233231
if ( block )
234232
{
235233
block->convert( Qgis::Float32 ); // currently we expect just floats
236234
data = block->data();
237235
data.detach(); // this should make a deep copy
238-
delete block;
239236
}
240237

241238
return data;
@@ -248,11 +245,10 @@ float QgsDemHeightMapGenerator::heightAt( double x, double y )
248245
QgsRectangle rect = mDtm->extent();
249246
if ( mDtmCoarseData.isEmpty() )
250247
{
251-
QgsRasterBlock *block = mDtm->dataProvider()->block( 1, rect, res, res );
248+
std::unique_ptr< QgsRasterBlock > block( mDtm->dataProvider()->block( 1, rect, res, res ) );
252249
block->convert( Qgis::Float32 );
253250
mDtmCoarseData = block->data();
254251
mDtmCoarseData.detach(); // make a deep copy
255-
delete block;
256252
}
257253

258254
int cellX = ( int )( ( x - rect.xMinimum() ) / rect.width() * res + .5f );

‎src/analysis/raster/qgsrastercalculator.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
6161
{
6262
//prepare search string / tree
6363
QString errorString;
64-
QgsRasterCalcNode *calcNode = QgsRasterCalcNode::parseRasterCalcString( mFormulaString, errorString );
64+
std::unique_ptr< QgsRasterCalcNode > calcNode( QgsRasterCalcNode::parseRasterCalcString( mFormulaString, errorString ) );
6565
if ( !calcNode )
6666
{
6767
//error
@@ -74,12 +74,11 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
7474
{
7575
if ( !it->raster ) // no raster layer in entry
7676
{
77-
delete calcNode;
7877
qDeleteAll( inputBlocks );
7978
return static_cast< int >( InputLayerError );
8079
}
8180

82-
QgsRasterBlock *block = nullptr;
81+
std::unique_ptr< QgsRasterBlock > block;
8382
// if crs transform needed
8483
if ( it->raster->crs() != mOutputCrs )
8584
{
@@ -90,27 +89,23 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
9089

9190
QgsRasterBlockFeedback *rasterBlockFeedback = new QgsRasterBlockFeedback();
9291
QObject::connect( feedback, &QgsFeedback::canceled, rasterBlockFeedback, &QgsRasterBlockFeedback::cancel );
93-
block = proj.block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows, rasterBlockFeedback );
92+
block.reset( proj.block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows, rasterBlockFeedback ) );
9493
if ( rasterBlockFeedback->isCanceled() )
9594
{
96-
delete block;
97-
delete calcNode;
9895
qDeleteAll( inputBlocks );
9996
return static_cast< int >( Canceled );
10097
}
10198
}
10299
else
103100
{
104-
block = it->raster->dataProvider()->block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows );
101+
block.reset( it->raster->dataProvider()->block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows ) );
105102
}
106103
if ( block->isEmpty() )
107104
{
108-
delete block;
109-
delete calcNode;
110105
qDeleteAll( inputBlocks );
111106
return static_cast<int>( MemoryError );
112107
}
113-
inputBlocks.insert( it->ref, block );
108+
inputBlocks.insert( it->ref, block.release() );
114109
}
115110

116111
//open output dataset for writing
@@ -175,7 +170,7 @@ int QgsRasterCalculator::processCalculation( QgsFeedback *feedback )
175170
}
176171

177172
//close datasets and release memory
178-
delete calcNode;
173+
calcNode.reset();
179174
qDeleteAll( inputBlocks );
180175
inputBlocks.clear();
181176

‎src/core/raster/qgsrasterchecker.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ bool QgsRasterChecker::runTest( const QString &verifiedKey, QString verifiedUri,
142142

143143
int width = expectedProvider->xSize();
144144
int height = expectedProvider->ySize();
145-
QgsRasterBlock *expectedBlock = expectedProvider->block( band, expectedProvider->extent(), width, height );
146-
QgsRasterBlock *verifiedBlock = verifiedProvider->block( band, expectedProvider->extent(), width, height );
145+
std::unique_ptr< QgsRasterBlock > expectedBlock( expectedProvider->block( band, expectedProvider->extent(), width, height ) );
146+
std::unique_ptr< QgsRasterBlock > verifiedBlock( verifiedProvider->block( band, expectedProvider->extent(), width, height ) );
147147

148148
if ( !expectedBlock || !expectedBlock->isValid() ||
149149
!verifiedBlock || !verifiedBlock->isValid() )
@@ -182,9 +182,6 @@ bool QgsRasterChecker::runTest( const QString &verifiedKey, QString verifiedUri,
182182
htmlTable += QLatin1String( "</table>" );
183183

184184
mReport += htmlTable;
185-
186-
delete expectedBlock;
187-
delete verifiedBlock;
188185
}
189186
delete verifiedProvider;
190187
delete expectedProvider;

‎src/core/raster/qgsrasterinterface.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void QgsRasterInterface::initStatistics( QgsRasterBandStats &statistics,
6969
if ( xRes < srcXRes ) xRes = srcXRes;
7070
if ( yRes < srcYRes ) yRes = srcYRes;
7171
}
72-
QgsDebugMsgLevel( QString( "xRes = %1 yRes = %2" ).arg( xRes ).arg( yRes ), 4 );
72+
QgsDebugMsgLevel( QStringLiteral( "xRes = %1 yRes = %2" ).arg( xRes ).arg( yRes ), 4 );
7373

7474
statistics.width = static_cast <int>( finalExtent.width() / xRes );
7575
statistics.height = static_cast <int>( finalExtent.height() / yRes );
@@ -180,7 +180,7 @@ QgsRasterBandStats QgsRasterInterface::bandStatistics( int bandNo,
180180

181181
QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );
182182

183-
QgsRasterBlock *blk = block( bandNo, myPartExtent, myBlockWidth, myBlockHeight, feedback );
183+
std::unique_ptr< QgsRasterBlock > blk( block( bandNo, myPartExtent, myBlockWidth, myBlockHeight, feedback ) );
184184

185185
// Collect the histogram counts.
186186
for ( qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
@@ -216,7 +216,6 @@ QgsRasterBandStats QgsRasterInterface::bandStatistics( int bandNo,
216216
myMean += myDelta / myRasterBandStats.elementCount;
217217
mySumOfSquares += myDelta * ( myValue - myMean );
218218
}
219-
delete blk;
220219
}
221220
}
222221

@@ -466,7 +465,7 @@ QgsRasterHistogram QgsRasterInterface::histogram( int bandNo,
466465

467466
QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );
468467

469-
QgsRasterBlock *blk = block( bandNo, myPartExtent, myBlockWidth, myBlockHeight, feedback );
468+
std::unique_ptr< QgsRasterBlock > blk( block( bandNo, myPartExtent, myBlockWidth, myBlockHeight, feedback ) );
470469

471470
// Collect the histogram counts.
472471
for ( qgssize i = 0; i < ( static_cast< qgssize >( myBlockHeight ) ) * myBlockWidth; i++ )
@@ -489,7 +488,6 @@ QgsRasterHistogram QgsRasterInterface::histogram( int bandNo,
489488
myHistogram.histogramVector[myBinIndex] += 1;
490489
myHistogram.nonNullCount++;
491490
}
492-
delete blk;
493491
}
494492
}
495493

0 commit comments

Comments
 (0)
Please sign in to comment.