Skip to content

Commit 4b8c5be

Browse files
committedJan 9, 2017
Remove some more macros not needed with GDAL>=2 requirement
1 parent b0bc763 commit 4b8c5be

22 files changed

+92
-176
lines changed
 

‎src/analysis/raster/qgskde.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#define M_PI 3.14159265358979323846
2424
#endif
2525

26-
#define TO8F(x) (x).toUtf8().constData()
27-
2826
QgsKernelDensityEstimation::QgsKernelDensityEstimation( const QgsKernelDensityEstimation::Parameters& parameters, const QString& outputFile, const QString& outputFormat )
2927
: mInputLayer( parameters.vectorLayer )
3028
, mOutputFile( outputFile )
@@ -95,7 +93,7 @@ QgsKernelDensityEstimation::Result QgsKernelDensityEstimation::prepare()
9593
return FileCreationError;
9694

9795
// open the raster in GA_Update mode
98-
mDatasetH = GDALOpen( TO8F( mOutputFile ), GA_Update );
96+
mDatasetH = GDALOpen( mOutputFile.toUtf8().constData(), GA_Update );
9997
if ( !mDatasetH )
10098
return FileCreationError;
10199
mRasterBandH = GDALGetRasterBand( mDatasetH, 1 );

‎src/analysis/raster/qgsninecellfilter.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <QProgressDialog>
2222
#include <QFile>
2323

24-
#define TO8F(x) (x).toUtf8().constData()
25-
2624
QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
2725
: mInputFile( inputFile )
2826
, mOutputFile( outputFile )
@@ -204,7 +202,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
204202
if ( p && p->wasCanceled() )
205203
{
206204
//delete the dataset without closing (because it is faster)
207-
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
205+
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
208206
return 7;
209207
}
210208
GDALClose( outputDataset );
@@ -214,7 +212,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
214212

215213
GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
216214
{
217-
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
215+
GDALDatasetH inputDataset = GDALOpen( mInputFile.toUtf8().constData(), GA_ReadOnly );
218216
if ( inputDataset )
219217
{
220218
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -263,7 +261,7 @@ GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALD
263261

264262
//open output file
265263
char **papszOptions = nullptr;
266-
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 1, GDT_Float32, papszOptions );
264+
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), xSize, ySize, 1, GDT_Float32, papszOptions );
267265
if ( !outputDataset )
268266
{
269267
return outputDataset;

‎src/analysis/raster/qgsrastercalculator.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
#include <cpl_string.h>
3030
#include <gdalwarper.h>
3131

32-
#define TO8(x) (x).toUtf8().constData()
33-
#define TO8F(x) (x).toUtf8().constData()
34-
3532
QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
3633
const QgsRectangle& outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry>& rasterEntries )
3734
: mFormulaString( formulaString )
@@ -175,7 +172,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
175172
if ( p && p->wasCanceled() )
176173
{
177174
//delete the dataset without closing (because it is faster)
178-
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
175+
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
179176
return static_cast< int >( Cancelled );
180177
}
181178
GDALClose( outputDataset );
@@ -214,7 +211,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
214211
{
215212
//open output file
216213
char **papszOptions = nullptr;
217-
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
214+
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
218215
if ( !outputDataset )
219216
{
220217
return outputDataset;

‎src/analysis/raster/qgsrelief.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include <QFile>
2929
#include <QTextStream>
3030

31-
#define TO8F(x) (x).toUtf8().constData()
32-
3331
QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
3432
: mInputFile( inputFile )
3533
, mOutputFile( outputFile )
@@ -288,7 +286,7 @@ int QgsRelief::processRaster( QProgressDialog* p )
288286
if ( p && p->wasCanceled() )
289287
{
290288
//delete the dataset without closing (because it is faster)
291-
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
289+
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
292290
return 7;
293291
}
294292
GDALClose( outputDataset );
@@ -411,7 +409,7 @@ bool QgsRelief::setElevationColor( double elevation, int* red, int* green, int*
411409
//duplicated from QgsNineCellFilter. Todo: make common base class
412410
GDALDatasetH QgsRelief::openInputFile( int& nCellsX, int& nCellsY )
413411
{
414-
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
412+
GDALDatasetH inputDataset = GDALOpen( mInputFile.toUtf8().constData(), GA_ReadOnly );
415413
if ( inputDataset )
416414
{
417415
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -465,7 +463,7 @@ GDALDatasetH QgsRelief::openOutputFile( GDALDatasetH inputDataset, GDALDriverH o
465463
papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "PACKBITS" );
466464

467465
//create three band raster (reg, green, blue)
468-
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 3, GDT_Byte, papszOptions );
466+
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), xSize, ySize, 3, GDT_Byte, papszOptions );
469467
if ( !outputDataset )
470468
{
471469
return outputDataset;

‎src/analysis/vector/qgszonalstatistics.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include <QProgressDialog>
2929
#include <QFile>
3030

31-
#define TO8F(x) (x).toUtf8().constData()
32-
3331
QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QString& rasterFile, const QString& attributePrefix, int rasterBand, Statistics stats )
3432
: mRasterFilePath( rasterFile )
3533
, mRasterBand( rasterBand )
@@ -65,7 +63,7 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )
6563

6664
//open the raster layer and the raster band
6765
GDALAllRegister();
68-
GDALDatasetH inputDataset = GDALOpen( TO8F( mRasterFilePath ), GA_ReadOnly );
66+
GDALDatasetH inputDataset = GDALOpen( mRasterFilePath.toUtf8().constData(), GA_ReadOnly );
6967
if ( !inputDataset )
7068
{
7169
return 3;

‎src/app/ogr/qgsnewogrconnection.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include <ogr_api.h>
2727
#include <cpl_error.h>
2828

29-
#define TO8F(x) (x).toUtf8().constData()
30-
3129
QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connType, const QString& connName, Qt::WindowFlags fl )
3230
: QDialog( parent, fl )
3331
, mOriginalConnName( connName )
@@ -85,7 +83,7 @@ void QgsNewOgrConnection::testConnection()
8583
OGRDataSourceH poDS;
8684
OGRSFDriverH pahDriver;
8785
CPLErrorReset();
88-
poDS = OGROpen( TO8F( uri ), false, &pahDriver );
86+
poDS = OGROpen( uri.toUtf8().constData(), false, &pahDriver );
8987
if ( !poDS )
9088
{
9189
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );

‎src/app/qgisapp.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@
266266
#include <gdal_version.h>
267267
#include <proj_api.h>
268268

269-
#define SUPPORT_GEOPACKAGE
270-
271269
//
272270
// Other includes
273271
//
@@ -1962,10 +1960,6 @@ void QgisApp::createMenus()
19621960
*/
19631961

19641962
// Layer menu
1965-
#ifndef SUPPORT_GEOPACKAGE
1966-
mProjectMenu->removeAction( mActionDwgImport );
1967-
mNewLayerMenu->removeAction( mActionNewGeoPackageLayer );
1968-
#endif
19691963

19701964
// Panel and Toolbar Submenus
19711965
mPanelMenu = new QMenu( tr( "Panels" ), this );
@@ -2239,9 +2233,7 @@ void QgisApp::createToolBars()
22392233
bt->setPopupMode( QToolButton::MenuButtonPopup );
22402234
bt->addAction( mActionNewVectorLayer );
22412235
bt->addAction( mActionNewSpatiaLiteLayer );
2242-
#ifdef SUPPORT_GEOPACKAGE
22432236
bt->addAction( mActionNewGeoPackageLayer );
2244-
#endif
22452237
bt->addAction( mActionNewMemoryLayer );
22462238

22472239
QAction* defNewLayerAction = mActionNewVectorLayer;
@@ -2256,11 +2248,9 @@ void QgisApp::createToolBars()
22562248
case 2:
22572249
defNewLayerAction = mActionNewMemoryLayer;
22582250
break;
2259-
#ifdef SUPPORT_GEOPACKAGE
22602251
case 3:
22612252
defNewLayerAction = mActionNewGeoPackageLayer;
22622253
break;
2263-
#endif
22642254
}
22652255
bt->setDefaultAction( defNewLayerAction );
22662256
QAction* newLayerAction = mLayerToolBar->addWidget( bt );

‎src/core/qgsogrutils.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
#include <QTextCodec>
2222
#include <QUuid>
2323

24-
#define TO8(x) (x).toUtf8().constData()
25-
#define TO8F(x) (x).toUtf8().constData()
26-
#define FROM8(x) QString::fromUtf8(x)
27-
2824
QgsFeature QgsOgrUtils::readOgrFeature( OGRFeatureH ogrFet, const QgsFields& fields, QTextCodec* encoding )
2925
{
3026
QgsFeature feature;
@@ -233,21 +229,21 @@ QgsFeatureList QgsOgrUtils::stringToFeatureList( const QString& string, const Qg
233229

234230
// create memory file system object from string buffer
235231
QByteArray ba = string.toUtf8();
236-
VSIFCloseL( VSIFileFromMemBuffer( TO8( randomFileName ), reinterpret_cast< GByte* >( ba.data() ),
232+
VSIFCloseL( VSIFileFromMemBuffer( randomFileName.toUtf8().constData(), reinterpret_cast< GByte* >( ba.data() ),
237233
static_cast< vsi_l_offset >( ba.size() ), FALSE ) );
238234

239-
OGRDataSourceH hDS = OGROpen( TO8( randomFileName ), false, nullptr );
235+
OGRDataSourceH hDS = OGROpen( randomFileName.toUtf8().constData(), false, nullptr );
240236
if ( !hDS )
241237
{
242-
VSIUnlink( TO8( randomFileName ) );
238+
VSIUnlink( randomFileName.toUtf8().constData() );
243239
return features;
244240
}
245241

246242
OGRLayerH ogrLayer = OGR_DS_GetLayer( hDS, 0 );
247243
if ( !ogrLayer )
248244
{
249245
OGR_DS_Destroy( hDS );
250-
VSIUnlink( TO8( randomFileName ) );
246+
VSIUnlink( randomFileName.toUtf8().constData() );
251247
return features;
252248
}
253249

@@ -262,7 +258,7 @@ QgsFeatureList QgsOgrUtils::stringToFeatureList( const QString& string, const Qg
262258
}
263259

264260
OGR_DS_Destroy( hDS );
265-
VSIUnlink( TO8( randomFileName ) );
261+
VSIUnlink( randomFileName.toUtf8().constData() );
266262

267263
return features;
268264
}
@@ -277,21 +273,21 @@ QgsFields QgsOgrUtils::stringToFields( const QString& string, QTextCodec* encodi
277273

278274
// create memory file system object from buffer
279275
QByteArray ba = string.toUtf8();
280-
VSIFCloseL( VSIFileFromMemBuffer( TO8( randomFileName ), reinterpret_cast< GByte* >( ba.data() ),
276+
VSIFCloseL( VSIFileFromMemBuffer( randomFileName.toUtf8().constData(), reinterpret_cast< GByte* >( ba.data() ),
281277
static_cast< vsi_l_offset >( ba.size() ), FALSE ) );
282278

283-
OGRDataSourceH hDS = OGROpen( TO8( randomFileName ), false, nullptr );
279+
OGRDataSourceH hDS = OGROpen( randomFileName.toUtf8().constData(), false, nullptr );
284280
if ( !hDS )
285281
{
286-
VSIUnlink( TO8( randomFileName ) );
282+
VSIUnlink( randomFileName.toUtf8().constData() );
287283
return fields;
288284
}
289285

290286
OGRLayerH ogrLayer = OGR_DS_GetLayer( hDS, 0 );
291287
if ( !ogrLayer )
292288
{
293289
OGR_DS_Destroy( hDS );
294-
VSIUnlink( TO8( randomFileName ) );
290+
VSIUnlink( randomFileName.toUtf8().constData() );
295291
return fields;
296292
}
297293

@@ -304,6 +300,6 @@ QgsFields QgsOgrUtils::stringToFields( const QString& string, QTextCodec* encodi
304300
}
305301

306302
OGR_DS_Destroy( hDS );
307-
VSIUnlink( TO8( randomFileName ) );
303+
VSIUnlink( randomFileName.toUtf8().constData() );
308304
return fields;
309305
}

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
#include <cpl_conv.h>
5151
#include <gdal.h>
5252

53-
#define TO8F(x) (x).toUtf8().constData()
54-
5553
QgsVectorFileWriter::FieldValueConverter::FieldValueConverter()
5654
{
5755
}
@@ -275,9 +273,9 @@ void QgsVectorFileWriter::init( QString vectorFileName,
275273

276274
// create the data source
277275
if ( action == CreateOrOverwriteFile )
278-
mDS = OGR_Dr_CreateDataSource( poDriver, TO8F( vectorFileName ), options );
276+
mDS = OGR_Dr_CreateDataSource( poDriver, vectorFileName.toUtf8().constData(), options );
279277
else
280-
mDS = OGROpen( TO8F( vectorFileName ), TRUE, nullptr );
278+
mDS = OGROpen( vectorFileName.toUtf8().constData(), TRUE, nullptr );
281279

282280
if ( options )
283281
{
@@ -309,7 +307,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
309307
for ( int i = 0; i < layer_count; i++ )
310308
{
311309
OGRLayerH hLayer = OGR_DS_GetLayer( mDS, i );
312-
if ( EQUAL( OGR_L_GetName( hLayer ), TO8F( layerName ) ) )
310+
if ( EQUAL( OGR_L_GetName( hLayer ), layerName.toUtf8().constData() ) )
313311
{
314312
if ( OGR_DS_DeleteLayer( mDS, i ) != OGRERR_NONE )
315313
{
@@ -377,9 +375,9 @@ void QgsVectorFileWriter::init( QString vectorFileName,
377375
CPLSetConfigOption( "SHAPE_ENCODING", "" );
378376

379377
if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
380-
mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), mOgrRef, wkbType, options );
378+
mLayer = OGR_DS_CreateLayer( mDS, layerName.toUtf8().constData(), mOgrRef, wkbType, options );
381379
else
382-
mLayer = OGR_DS_GetLayerByName( mDS, TO8F( layerName ) );
380+
mLayer = OGR_DS_GetLayerByName( mDS, layerName.toUtf8().constData() );
383381

384382
if ( options )
385383
{
@@ -2609,11 +2607,11 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
26092607
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().constData() );
26102608
if ( poDriver )
26112609
{
2612-
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
2610+
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, QString( "/vsimem/spatialitetest.sqlite" ).toUtf8().constData(), options );
26132611
if ( ds )
26142612
{
26152613
writableDrivers << QStringLiteral( "SpatiaLite" );
2616-
OGR_Dr_DeleteDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ) );
2614+
OGR_Dr_DeleteDataSource( poDriver, QString( "/vsimem/spatialitetest.sqlite" ).toUtf8().constData() );
26172615
OGR_DS_Destroy( ds );
26182616
}
26192617
}
@@ -3013,7 +3011,7 @@ QStringList QgsVectorFileWriter::concatenateOptions( const QMap<QString, QgsVect
30133011
QgsVectorFileWriter::EditionCapabilities QgsVectorFileWriter::editionCapabilities( const QString& datasetName )
30143012
{
30153013
OGRSFDriverH hDriver = nullptr;
3016-
OGRDataSourceH hDS = OGROpen( TO8F( datasetName ), TRUE, &hDriver );
3014+
OGRDataSourceH hDS = OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver );
30173015
if ( !hDS )
30183016
return 0;
30193017
QString drvName = OGR_Dr_GetName( hDriver );
@@ -3054,15 +3052,15 @@ bool QgsVectorFileWriter::targetLayerExists( const QString& datasetName,
30543052
const QString& layerNameIn )
30553053
{
30563054
OGRSFDriverH hDriver = nullptr;
3057-
OGRDataSourceH hDS = OGROpen( TO8F( datasetName ), TRUE, &hDriver );
3055+
OGRDataSourceH hDS = OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver );
30583056
if ( !hDS )
30593057
return false;
30603058

30613059
QString layerName( layerNameIn );
30623060
if ( layerName.isEmpty() )
30633061
layerName = QFileInfo( datasetName ).baseName();
30643062

3065-
bool ret = OGR_DS_GetLayerByName( hDS, TO8F( layerName ) );
3063+
bool ret = OGR_DS_GetLayerByName( hDS, layerName.toUtf8().constData() );
30663064
OGR_DS_Destroy( hDS );
30673065
return ret;
30683066
}
@@ -3074,10 +3072,10 @@ bool QgsVectorFileWriter::areThereNewFieldsToCreate( const QString& datasetName,
30743072
const QgsAttributeList& attributes )
30753073
{
30763074
OGRSFDriverH hDriver = nullptr;
3077-
OGRDataSourceH hDS = OGROpen( TO8F( datasetName ), TRUE, &hDriver );
3075+
OGRDataSourceH hDS = OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver );
30783076
if ( !hDS )
30793077
return false;
3080-
OGRLayerH hLayer = OGR_DS_GetLayerByName( hDS, TO8F( layerName ) );
3078+
OGRLayerH hLayer = OGR_DS_GetLayerByName( hDS, layerName.toUtf8().constData() );
30813079
if ( !hLayer )
30823080
{
30833081
OGR_DS_Destroy( hDS );
@@ -3088,7 +3086,7 @@ bool QgsVectorFileWriter::areThereNewFieldsToCreate( const QString& datasetName,
30883086
Q_FOREACH ( int idx, attributes )
30893087
{
30903088
QgsField fld = layer->fields().at( idx );
3091-
if ( OGR_FD_GetFieldIndex( defn, TO8F( fld.name() ) ) < 0 )
3089+
if ( OGR_FD_GetFieldIndex( defn, fld.name().toUtf8().constData() ) < 0 )
30923090
{
30933091
ret = true;
30943092
break;

0 commit comments

Comments
 (0)
Please sign in to comment.