Skip to content

Commit 662ec7a

Browse files
committedDec 17, 2017
Use unique_ptr over raw array
1 parent ffb9d0c commit 662ec7a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed
 

‎src/core/layout/qgslayoutexporter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ void QgsLayoutExporter::updatePrinterPageSize( QPrinter &printer, int page )
501501
printer.setPaperSize( pageSizeMM.toQSizeF(), QPrinter::Millimeter );
502502
}
503503

504-
double *QgsLayoutExporter::computeGeoTransform( const QgsLayoutItemMap *map, const QRectF &region, double dpi ) const
504+
std::unique_ptr<double[]> QgsLayoutExporter::computeGeoTransform( const QgsLayoutItemMap *map, const QRectF &region, double dpi ) const
505505
{
506506
if ( !map )
507507
map = mLayout->referenceMap();
@@ -574,7 +574,7 @@ double *QgsLayoutExporter::computeGeoTransform( const QgsLayoutItemMap *map, con
574574
double pixelHeightScale = paperExtent.height() / pageHeightPixels;
575575

576576
// transform matrix
577-
double *t = new double[6];
577+
std::unique_ptr<double[]> t( new double[6] );
578578
t[0] = X0;
579579
t[1] = cosAlpha * pixelWidthScale;
580580
t[2] = -sinAlpha * pixelWidthScale;
@@ -618,7 +618,7 @@ bool QgsLayoutExporter::georeferenceOutput( const QString &file, QgsLayoutItemMa
618618
if ( dpi < 0 )
619619
dpi = mLayout->context().dpi();
620620

621-
double *t = computeGeoTransform( map, exportRegion, dpi );
621+
std::unique_ptr<double[]> t = computeGeoTransform( map, exportRegion, dpi );
622622
if ( !t )
623623
return false;
624624

@@ -628,15 +628,15 @@ bool QgsLayoutExporter::georeferenceOutput( const QString &file, QgsLayoutItemMa
628628
gdal::dataset_unique_ptr outputDS( GDALOpen( file.toLocal8Bit().constData(), GA_Update ) );
629629
if ( outputDS )
630630
{
631-
GDALSetGeoTransform( outputDS.get(), t );
631+
GDALSetGeoTransform( outputDS.get(), t.get() );
632632
#if 0
633633
//TODO - metadata can be set here, e.g.:
634634
GDALSetMetadataItem( outputDS, "AUTHOR", "me", nullptr );
635635
#endif
636636
GDALSetProjection( outputDS.get(), map->crs().toWkt().toLocal8Bit().constData() );
637637
}
638638
CPLSetConfigOption( "GDAL_PDF_DPI", nullptr );
639-
delete[] t;
639+
640640
return true;
641641
}
642642

‎src/core/layout/qgslayoutexporter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class CORE_EXPORT QgsLayoutExporter
321321
*
322322
* \see georeferenceOutput()
323323
*/
324-
double *computeGeoTransform( const QgsLayoutItemMap *referenceMap = nullptr, const QRectF &exportRegion = QRectF(), double dpi = -1 ) const;
324+
std::unique_ptr<double[]> computeGeoTransform( const QgsLayoutItemMap *referenceMap = nullptr, const QRectF &exportRegion = QRectF(), double dpi = -1 ) const;
325325

326326
//! Write a world file
327327
void writeWorldFile( const QString &fileName, double a, double b, double c, double d, double e, double f ) const;

‎tests/src/core/testqgslayout.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void TestQgsLayout::georeference()
762762
QgsLayoutExporter exporter( &l );
763763

764764
// no map
765-
double *t = exporter.computeGeoTransform( nullptr );
765+
std::unique_ptr< double [] > t = exporter.computeGeoTransform( nullptr );
766766
QVERIFY( !t );
767767

768768
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
@@ -777,7 +777,7 @@ void TestQgsLayout::georeference()
777777
QGSCOMPARENEAR( t[3], 3050, 1 );
778778
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
779779
QGSCOMPARENEAR( t[5], -0.211694, 0.0001 );
780-
delete[] t;
780+
t.reset();
781781

782782
// don't specify map
783783
l.setReferenceMap( map );
@@ -788,7 +788,7 @@ void TestQgsLayout::georeference()
788788
QGSCOMPARENEAR( t[3], 3050, 1 );
789789
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
790790
QGSCOMPARENEAR( t[5], -0.211694, 0.0001 );
791-
delete[] t;
791+
t.reset();
792792

793793
// specify extent
794794
t = exporter.computeGeoTransform( map, QRectF( 70, 100, 50, 60 ) );
@@ -798,7 +798,7 @@ void TestQgsLayout::georeference()
798798
QGSCOMPARENEAR( t[3], 2800, 1 );
799799
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
800800
QGSCOMPARENEAR( t[5], -0.211864, 0.0001 );
801-
delete[] t;
801+
t.reset();
802802

803803
// specify dpi
804804
t = exporter.computeGeoTransform( map, QRectF(), 75 );
@@ -808,7 +808,7 @@ void TestQgsLayout::georeference()
808808
QGSCOMPARENEAR( t[3], 3050.0, 1 );
809809
QGSCOMPARENEAR( t[4], 0.0, 4 * DBL_EPSILON );
810810
QGSCOMPARENEAR( t[5], -0.846774, 0.0001 );
811-
delete[] t;
811+
t.reset();
812812

813813
// rotation
814814
map->setMapRotation( 45 );
@@ -819,7 +819,7 @@ void TestQgsLayout::georeference()
819819
QGSCOMPARENEAR( t[3], 2761.611652, 1 );
820820
QGSCOMPARENEAR( t[4], 0.14969, 0.0001 );
821821
QGSCOMPARENEAR( t[5], -0.14969, 0.0001 );
822-
delete[] t;
822+
t.reset();
823823
}
824824

825825

0 commit comments

Comments
 (0)
Please sign in to comment.