Skip to content
Permalink
Browse files

Use unique_ptr over raw array

  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent ffb9d0c commit 662ec7a77c88ec4a5bc8e76b3ef0fc0e34d4367c
Showing with 12 additions and 12 deletions.
  1. +5 −5 src/core/layout/qgslayoutexporter.cpp
  2. +1 −1 src/core/layout/qgslayoutexporter.h
  3. +6 −6 tests/src/core/testqgslayout.cpp
@@ -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();
@@ -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;
@@ -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;

@@ -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;
}

@@ -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;
@@ -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 );
@@ -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 );
@@ -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 ) );
@@ -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 );
@@ -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 );
@@ -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();
}


0 comments on commit 662ec7a

Please sign in to comment.
You can’t perform that action at this time.