Skip to content

Commit

Permalink
Use unique_ptr over raw array
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 17, 2017
1 parent ffb9d0c commit 662ec7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/core/layout/qgslayoutexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void QgsLayoutExporter::updatePrinterPageSize( QPrinter &printer, int page )
printer.setPaperSize( pageSizeMM.toQSizeF(), QPrinter::Millimeter );
}

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

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

double *t = computeGeoTransform( map, exportRegion, dpi );
std::unique_ptr<double[]> t = computeGeoTransform( map, exportRegion, dpi );
if ( !t )
return false;

Expand All @@ -628,15 +628,15 @@ bool QgsLayoutExporter::georeferenceOutput( const QString &file, QgsLayoutItemMa
gdal::dataset_unique_ptr outputDS( GDALOpen( file.toLocal8Bit().constData(), GA_Update ) );
if ( outputDS )
{
GDALSetGeoTransform( outputDS.get(), t );
GDALSetGeoTransform( outputDS.get(), t.get() );
#if 0
//TODO - metadata can be set here, e.g.:
GDALSetMetadataItem( outputDS, "AUTHOR", "me", nullptr );
#endif
GDALSetProjection( outputDS.get(), map->crs().toWkt().toLocal8Bit().constData() );
}
CPLSetConfigOption( "GDAL_PDF_DPI", nullptr );
delete[] t;

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class CORE_EXPORT QgsLayoutExporter
*
* \see georeferenceOutput()
*/
double *computeGeoTransform( const QgsLayoutItemMap *referenceMap = nullptr, const QRectF &exportRegion = QRectF(), double dpi = -1 ) const;
std::unique_ptr<double[]> computeGeoTransform( const QgsLayoutItemMap *referenceMap = nullptr, const QRectF &exportRegion = QRectF(), double dpi = -1 ) const;

//! Write a world file
void writeWorldFile( const QString &fileName, double a, double b, double c, double d, double e, double f ) const;
Expand Down
12 changes: 6 additions & 6 deletions tests/src/core/testqgslayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ void TestQgsLayout::georeference()
QgsLayoutExporter exporter( &l );

// no map
double *t = exporter.computeGeoTransform( nullptr );
std::unique_ptr< double [] > t = exporter.computeGeoTransform( nullptr );
QVERIFY( !t );

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

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

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

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

// rotation
map->setMapRotation( 45 );
Expand All @@ -819,7 +819,7 @@ void TestQgsLayout::georeference()
QGSCOMPARENEAR( t[3], 2761.611652, 1 );
QGSCOMPARENEAR( t[4], 0.14969, 0.0001 );
QGSCOMPARENEAR( t[5], -0.14969, 0.0001 );
delete[] t;
t.reset();
}


Expand Down

0 comments on commit 662ec7a

Please sign in to comment.