Skip to content

Commit 469eb0d

Browse files
authoredAug 17, 2017
Merge pull request #5034 from nyalldawson/exporter_api
Use const references to options instead of pointers in QgsVectorLayerExporter
2 parents 26a911c + c7affb3 commit 469eb0d

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed
 

‎python/core/qgsvectorlayerexporter.sip

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class QgsVectorLayerExporter : QgsFeatureSink
5252
const QgsCoordinateReferenceSystem &destCRS,
5353
bool onlySelected = false,
5454
QString *errorMessage /Out/ = 0,
55-
QMap<QString, QVariant> *options = 0,
55+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
5656
QgsFeedback *feedback = 0
5757
);
5858
%Docstring
@@ -76,7 +76,7 @@ class QgsVectorLayerExporter : QgsFeatureSink
7676
QgsWkbTypes::Type geometryType,
7777
const QgsCoordinateReferenceSystem &crs,
7878
bool overwrite = false,
79-
const QMap<QString, QVariant> *options = 0 );
79+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>() );
8080
%Docstring
8181
Constructor for QgsVectorLayerExporter.
8282
\param uri URI for destination data source
@@ -152,7 +152,7 @@ class QgsVectorLayerExporterTask : QgsTask
152152
const QString &uri,
153153
const QString &providerKey,
154154
const QgsCoordinateReferenceSystem &destinationCrs,
155-
QMap<QString, QVariant> *options = 0,
155+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
156156
bool ownsLayer = false );
157157
%Docstring
158158
Constructor for QgsVectorLayerExporterTask. Takes a source ``layer``, destination ``uri``
@@ -165,7 +165,7 @@ class QgsVectorLayerExporterTask : QgsTask
165165
const QString &uri,
166166
const QString &providerKey,
167167
const QgsCoordinateReferenceSystem &destinationCrs,
168-
QMap<QString, QVariant> *options = 0 ) /Factory/;
168+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>() ) /Factory/;
169169
%Docstring
170170
Creates a new QgsVectorLayerExporterTask which has ownership over a source ``layer``.
171171
When the export task has completed (successfully or otherwise) ``layer`` will be

‎src/core/processing/qgsprocessingutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
369369
else
370370
{
371371
//create empty layer
372-
std::unique_ptr< QgsVectorLayerExporter > exporter( new QgsVectorLayerExporter( uri, providerKey, fields, geometryType, crs, false, &options ) );
372+
std::unique_ptr< QgsVectorLayerExporter > exporter( new QgsVectorLayerExporter( uri, providerKey, fields, geometryType, crs, false, options ) );
373373
if ( exporter->errorCode() )
374374
return nullptr;
375375

‎src/core/qgsvectorlayerexporter.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ QgsVectorLayerExporter::QgsVectorLayerExporter( const QString &uri,
5151
QgsWkbTypes::Type geometryType,
5252
const QgsCoordinateReferenceSystem &crs,
5353
bool overwrite,
54-
const QMap<QString, QVariant> *options )
54+
const QMap<QString, QVariant> &options )
5555
: mErrorCount( 0 )
5656
, mAttributeCount( -1 )
5757

@@ -78,7 +78,7 @@ QgsVectorLayerExporter::QgsVectorLayerExporter( const QString &uri,
7878

7979
// create an empty layer
8080
QString errMsg;
81-
mError = pCreateEmpty( uri, fields, geometryType, crs, overwrite, &mOldToNewAttrIdx, &errMsg, options );
81+
mError = pCreateEmpty( uri, fields, geometryType, crs, overwrite, &mOldToNewAttrIdx, &errMsg, !options.isEmpty() ? &options : nullptr );
8282
if ( errorCode() )
8383
{
8484
mErrorMessage = errMsg;
@@ -100,8 +100,8 @@ QgsVectorLayerExporter::QgsVectorLayerExporter( const QString &uri,
100100
if ( providerKey == "ogr" )
101101
{
102102
QString layerName;
103-
if ( options && options->contains( QStringLiteral( "layerName" ) ) )
104-
layerName = options->value( QStringLiteral( "layerName" ) ).toString();
103+
if ( options.contains( QStringLiteral( "layerName" ) ) )
104+
layerName = options.value( QStringLiteral( "layerName" ) ).toString();
105105
if ( !layerName.isEmpty() )
106106
{
107107
uriUpdated += "|layername=";
@@ -231,7 +231,7 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
231231
const QgsCoordinateReferenceSystem &destCRS,
232232
bool onlySelected,
233233
QString *errorMessage,
234-
QMap<QString, QVariant> *options,
234+
const QMap<QString, QVariant> &options,
235235
QgsFeedback *feedback )
236236
{
237237
QgsCoordinateReferenceSystem outputCRS;
@@ -256,10 +256,11 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
256256

257257
bool overwrite = false;
258258
bool forceSinglePartGeom = false;
259-
if ( options )
259+
QMap<QString, QVariant> providerOptions = options;
260+
if ( !options.isEmpty() )
260261
{
261-
overwrite = options->take( QStringLiteral( "overwrite" ) ).toBool();
262-
forceSinglePartGeom = options->take( QStringLiteral( "forceSinglePartGeometryType" ) ).toBool();
262+
overwrite = providerOptions.take( QStringLiteral( "overwrite" ) ).toBool();
263+
forceSinglePartGeom = providerOptions.take( QStringLiteral( "forceSinglePartGeometryType" ) ).toBool();
263264
}
264265

265266
QgsFields fields = layer->fields();
@@ -304,7 +305,7 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
304305
}
305306

306307
QgsVectorLayerExporter *writer =
307-
new QgsVectorLayerExporter( uri, providerKey, fields, wkbType, outputCRS, overwrite, options );
308+
new QgsVectorLayerExporter( uri, providerKey, fields, wkbType, outputCRS, overwrite, providerOptions );
308309

309310
// check whether file creation was successful
310311
ExportError err = writer->errorCode();
@@ -456,21 +457,21 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
456457
// QgsVectorLayerExporterTask
457458
//
458459

459-
QgsVectorLayerExporterTask::QgsVectorLayerExporterTask( QgsVectorLayer *layer, const QString &uri, const QString &providerKey, const QgsCoordinateReferenceSystem &destinationCrs, QMap<QString, QVariant> *options, bool ownsLayer )
460+
QgsVectorLayerExporterTask::QgsVectorLayerExporterTask( QgsVectorLayer *layer, const QString &uri, const QString &providerKey, const QgsCoordinateReferenceSystem &destinationCrs, const QMap<QString, QVariant> &options, bool ownsLayer )
460461
: QgsTask( tr( "Exporting %1" ).arg( layer->name() ), QgsTask::CanCancel )
461462
, mLayer( layer )
462463
, mOwnsLayer( ownsLayer )
463464
, mDestUri( uri )
464465
, mDestProviderKey( providerKey )
465466
, mDestCrs( destinationCrs )
466-
, mOptions( options ? * options : QMap<QString, QVariant>() )
467+
, mOptions( options )
467468
, mOwnedFeedback( new QgsFeedback() )
468469
{
469470
if ( mLayer )
470471
setDependentLayers( QList< QgsMapLayer * >() << mLayer );
471472
}
472473

473-
QgsVectorLayerExporterTask *QgsVectorLayerExporterTask::withLayerOwnership( QgsVectorLayer *layer, const QString &uri, const QString &providerKey, const QgsCoordinateReferenceSystem &destinationCrs, QMap<QString, QVariant> *options )
474+
QgsVectorLayerExporterTask *QgsVectorLayerExporterTask::withLayerOwnership( QgsVectorLayer *layer, const QString &uri, const QString &providerKey, const QgsCoordinateReferenceSystem &destinationCrs, const QMap<QString, QVariant> &options )
474475
{
475476
std::unique_ptr< QgsVectorLayerExporterTask > newTask( new QgsVectorLayerExporterTask( layer, uri, providerKey, destinationCrs, options ) );
476477
newTask->mOwnsLayer = true;
@@ -493,7 +494,7 @@ bool QgsVectorLayerExporterTask::run()
493494

494495
mError = QgsVectorLayerExporter::exportLayer(
495496
mLayer.data(), mDestUri, mDestProviderKey, mDestCrs, false, &mErrorMessage,
496-
&mOptions, mOwnedFeedback.get() );
497+
mOptions, mOwnedFeedback.get() );
497498

498499
return mError == QgsVectorLayerExporter::NoError;
499500
}

‎src/core/qgsvectorlayerexporter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CORE_EXPORT QgsVectorLayerExporter : public QgsFeatureSink
8484
const QgsCoordinateReferenceSystem &destCRS,
8585
bool onlySelected = false,
8686
QString *errorMessage SIP_OUT = 0,
87-
QMap<QString, QVariant> *options = nullptr,
87+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
8888
QgsFeedback *feedback = nullptr
8989
);
9090

@@ -105,7 +105,7 @@ class CORE_EXPORT QgsVectorLayerExporter : public QgsFeatureSink
105105
QgsWkbTypes::Type geometryType,
106106
const QgsCoordinateReferenceSystem &crs,
107107
bool overwrite = false,
108-
const QMap<QString, QVariant> *options = nullptr );
108+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>() );
109109

110110
//! QgsVectorLayerExporter cannot be copied
111111
QgsVectorLayerExporter( const QgsVectorLayerExporter &rh ) = delete;
@@ -195,7 +195,7 @@ class CORE_EXPORT QgsVectorLayerExporterTask : public QgsTask
195195
const QString &uri,
196196
const QString &providerKey,
197197
const QgsCoordinateReferenceSystem &destinationCrs,
198-
QMap<QString, QVariant> *options = nullptr,
198+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>(),
199199
bool ownsLayer = false );
200200

201201
/**
@@ -208,7 +208,7 @@ class CORE_EXPORT QgsVectorLayerExporterTask : public QgsTask
208208
const QString &uri,
209209
const QString &providerKey,
210210
const QgsCoordinateReferenceSystem &destinationCrs,
211-
QMap<QString, QVariant> *options = nullptr ) SIP_FACTORY;
211+
const QMap<QString, QVariant> &options = QMap<QString, QVariant>() ) SIP_FACTORY;
212212

213213
virtual void cancel() override;
214214

‎src/providers/ogr/qgsgeopackagedataitems.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ bool QgsGeoPackageConnectionItem::handleDrop( const QMimeData *data, Qt::DropAct
322322
tr( "Destination layer <b>%1</b> already exists. Do you want to overwrite it?" ).arg( u.name ), QMessageBox::Yes | QMessageBox::No ) == QMessageBox::Yes )
323323
{
324324

325-
std::unique_ptr< QMap<QString, QVariant> > options( new QMap<QString, QVariant> );
326-
options->insert( QStringLiteral( "driverName" ), QStringLiteral( "GPKG" ) );
327-
options->insert( QStringLiteral( "update" ), true );
328-
options->insert( QStringLiteral( "overwrite" ), true );
329-
options->insert( QStringLiteral( "layerName" ), u.name );
325+
QVariantMap options;
326+
options.insert( QStringLiteral( "driverName" ), QStringLiteral( "GPKG" ) );
327+
options.insert( QStringLiteral( "update" ), true );
328+
options.insert( QStringLiteral( "overwrite" ), true );
329+
options.insert( QStringLiteral( "layerName" ), u.name );
330330

331-
std::unique_ptr< QgsVectorLayerExporterTask > exportTask( new QgsVectorLayerExporterTask( srcLayer, uri, QStringLiteral( "ogr" ), srcLayer->crs(), options.get(), owner ) );
331+
std::unique_ptr< QgsVectorLayerExporterTask > exportTask( new QgsVectorLayerExporterTask( srcLayer, uri, QStringLiteral( "ogr" ), srcLayer->crs(), options, owner ) );
332332

333333
// when export is successful:
334334
connect( exportTask.get(), &QgsVectorLayerExporterTask::exportComplete, this, [ = ]()

‎src/providers/postgres/qgspostgresdataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData *data, const QString &toSc
244244
uri.setSchema( toSchema );
245245
}
246246

247-
std::unique_ptr< QgsVectorLayerExporterTask > exportTask( new QgsVectorLayerExporterTask( srcLayer, uri.uri( false ), QStringLiteral( "postgres" ), srcLayer->crs(), nullptr, owner ) );
247+
std::unique_ptr< QgsVectorLayerExporterTask > exportTask( new QgsVectorLayerExporterTask( srcLayer, uri.uri( false ), QStringLiteral( "postgres" ), srcLayer->crs(), QVariantMap(), owner ) );
248248

249249
// when export is successful:
250250
connect( exportTask.get(), &QgsVectorLayerExporterTask::exportComplete, this, [ = ]()

‎src/providers/spatialite/qgsspatialitedataitems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ bool QgsSLConnectionItem::handleDrop( const QMimeData *data, Qt::DropAction )
229229
destUri.setDataSource( QString(), u.name, srcLayer->geometryType() != QgsWkbTypes::NullGeometry ? QStringLiteral( "geom" ) : QString() );
230230
QgsDebugMsg( "URI " + destUri.uri() );
231231

232-
std::unique_ptr< QgsVectorLayerExporterTask > exportTask( new QgsVectorLayerExporterTask( srcLayer, destUri.uri(), QStringLiteral( "spatialite" ), srcLayer->crs(), nullptr, owner ) );
232+
std::unique_ptr< QgsVectorLayerExporterTask > exportTask( new QgsVectorLayerExporterTask( srcLayer, destUri.uri(), QStringLiteral( "spatialite" ), srcLayer->crs(), QVariantMap(), owner ) );
233233

234234
// when export is successful:
235235
connect( exportTask.get(), &QgsVectorLayerExporterTask::exportComplete, this, [ = ]()

0 commit comments

Comments
 (0)
Please sign in to comment.