@@ -51,7 +51,7 @@ QgsVectorLayerExporter::QgsVectorLayerExporter( const QString &uri,
51
51
QgsWkbTypes::Type geometryType,
52
52
const QgsCoordinateReferenceSystem &crs,
53
53
bool overwrite,
54
- const QMap<QString, QVariant> * options )
54
+ const QMap<QString, QVariant> & options )
55
55
: mErrorCount( 0 )
56
56
, mAttributeCount( -1 )
57
57
@@ -78,7 +78,7 @@ QgsVectorLayerExporter::QgsVectorLayerExporter( const QString &uri,
78
78
79
79
// create an empty layer
80
80
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 );
82
82
if ( errorCode () )
83
83
{
84
84
mErrorMessage = errMsg;
@@ -100,8 +100,8 @@ QgsVectorLayerExporter::QgsVectorLayerExporter( const QString &uri,
100
100
if ( providerKey == " ogr" )
101
101
{
102
102
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 ();
105
105
if ( !layerName.isEmpty () )
106
106
{
107
107
uriUpdated += " |layername=" ;
@@ -231,7 +231,7 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
231
231
const QgsCoordinateReferenceSystem &destCRS,
232
232
bool onlySelected,
233
233
QString *errorMessage,
234
- QMap<QString, QVariant> * options,
234
+ const QMap<QString, QVariant> & options,
235
235
QgsFeedback *feedback )
236
236
{
237
237
QgsCoordinateReferenceSystem outputCRS;
@@ -256,10 +256,11 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
256
256
257
257
bool overwrite = false ;
258
258
bool forceSinglePartGeom = false ;
259
- if ( options )
259
+ QMap<QString, QVariant> providerOptions = options;
260
+ if ( !options.isEmpty () )
260
261
{
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 ();
263
264
}
264
265
265
266
QgsFields fields = layer->fields ();
@@ -304,7 +305,7 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
304
305
}
305
306
306
307
QgsVectorLayerExporter *writer =
307
- new QgsVectorLayerExporter ( uri, providerKey, fields, wkbType, outputCRS, overwrite, options );
308
+ new QgsVectorLayerExporter ( uri, providerKey, fields, wkbType, outputCRS, overwrite, providerOptions );
308
309
309
310
// check whether file creation was successful
310
311
ExportError err = writer->errorCode ();
@@ -456,21 +457,21 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
456
457
// QgsVectorLayerExporterTask
457
458
//
458
459
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 )
460
461
: QgsTask( tr( " Exporting %1" ).arg( layer->name () ), QgsTask::CanCancel )
461
462
, mLayer( layer )
462
463
, mOwnsLayer( ownsLayer )
463
464
, mDestUri( uri )
464
465
, mDestProviderKey( providerKey )
465
466
, mDestCrs( destinationCrs )
466
- , mOptions( options ? * options : QMap<QString, QVariant>() )
467
+ , mOptions( options )
467
468
, mOwnedFeedback( new QgsFeedback() )
468
469
{
469
470
if ( mLayer )
470
471
setDependentLayers ( QList< QgsMapLayer * >() << mLayer );
471
472
}
472
473
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 )
474
475
{
475
476
std::unique_ptr< QgsVectorLayerExporterTask > newTask ( new QgsVectorLayerExporterTask ( layer, uri, providerKey, destinationCrs, options ) );
476
477
newTask->mOwnsLayer = true ;
@@ -493,7 +494,7 @@ bool QgsVectorLayerExporterTask::run()
493
494
494
495
mError = QgsVectorLayerExporter::exportLayer (
495
496
mLayer .data (), mDestUri , mDestProviderKey , mDestCrs , false , &mErrorMessage ,
496
- & mOptions , mOwnedFeedback .get () );
497
+ mOptions , mOwnedFeedback .get () );
497
498
498
499
return mError == QgsVectorLayerExporter::NoError;
499
500
}
0 commit comments