@@ -7160,22 +7160,23 @@ void QgisApp::attributeTable( QgsAttributeTableFilterModel::FilterMode filter )
7160
7160
// the dialog will be deleted by itself on close
7161
7161
}
7162
7162
7163
- void QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer )
7163
+ QString QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer, const bool defaultAddToCanvas )
7164
7164
{
7165
7165
if ( !rasterLayer )
7166
7166
rasterLayer = qobject_cast<QgsRasterLayer *>( activeLayer() );
7167
7167
7168
7168
if ( !rasterLayer )
7169
7169
{
7170
- return;
7170
+ return QString() ;
7171
7171
}
7172
7172
7173
7173
QgsRasterLayerSaveAsDialog d( rasterLayer, rasterLayer->dataProvider(),
7174
7174
mMapCanvas->extent(), rasterLayer->crs(),
7175
7175
mMapCanvas->mapSettings().destinationCrs(),
7176
7176
this );
7177
+ d.setAddToCanvas( defaultAddToCanvas );
7177
7178
if ( d.exec() == QDialog::Rejected )
7178
- return;
7179
+ return QString() ;
7179
7180
7180
7181
QgsSettings settings;
7181
7182
settings.setValue( QStringLiteral( "UI/lastRasterFileDir" ), QFileInfo( d.outputFileName() ).absolutePath() );
@@ -7205,7 +7206,7 @@ void QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer )
7205
7206
if ( !pipe->set( rasterLayer->dataProvider()->clone() ) )
7206
7207
{
7207
7208
QgsDebugMsg( QStringLiteral( "Cannot set pipe provider" ) );
7208
- return;
7209
+ return QString() ;
7209
7210
}
7210
7211
7211
7212
QgsRasterNuller *nuller = new QgsRasterNuller();
@@ -7216,7 +7217,7 @@ void QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer )
7216
7217
if ( !pipe->insert( 1, nuller ) )
7217
7218
{
7218
7219
QgsDebugMsg( QStringLiteral( "Cannot set pipe nuller" ) );
7219
- return;
7220
+ return QString() ;
7220
7221
}
7221
7222
7222
7223
// add projector if necessary
@@ -7227,7 +7228,7 @@ void QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer )
7227
7228
if ( !pipe->insert( 2, projector ) )
7228
7229
{
7229
7230
QgsDebugMsg( QStringLiteral( "Cannot set pipe projector" ) );
7230
- return;
7231
+ return QString() ;
7231
7232
}
7232
7233
}
7233
7234
}
@@ -7240,14 +7241,14 @@ void QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer )
7240
7241
if ( !projector )
7241
7242
{
7242
7243
QgsDebugMsg( QStringLiteral( "Cannot get pipe projector" ) );
7243
- return;
7244
+ return QString() ;
7244
7245
}
7245
7246
projector->setCrs( rasterLayer->crs(), d.outputCrs() );
7246
7247
}
7247
7248
7248
7249
if ( !pipe->last() )
7249
7250
{
7250
- return;
7251
+ return QString() ;
7251
7252
}
7252
7253
fileWriter.setCreateOptions( d.createOptions() );
7253
7254
@@ -7309,26 +7310,28 @@ void QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer )
7309
7310
} );
7310
7311
7311
7312
QgsApplication::taskManager()->addTask( writerTask );
7313
+ return d.outputFileName();
7312
7314
}
7313
7315
7314
7316
7315
- void QgisApp::saveAsFile( QgsMapLayer *layer, bool onlySelected )
7317
+ QString QgisApp::saveAsFile( QgsMapLayer *layer, const bool onlySelected, const bool defaultToAddToMap )
7316
7318
{
7317
7319
if ( !layer )
7318
7320
layer = activeLayer();
7319
7321
7320
7322
if ( !layer )
7321
- return;
7323
+ return QString() ;
7322
7324
7323
7325
QgsMapLayer::LayerType layerType = layer->type();
7324
7326
if ( layerType == QgsMapLayer::RasterLayer )
7325
7327
{
7326
- saveAsRasterFile( qobject_cast<QgsRasterLayer *>( layer ) );
7328
+ return saveAsRasterFile( qobject_cast<QgsRasterLayer *>( layer ), defaultToAddToMap );
7327
7329
}
7328
7330
else if ( layerType == QgsMapLayer::VectorLayer )
7329
7331
{
7330
- saveAsVectorFileGeneral( qobject_cast<QgsVectorLayer *>( layer ), true, onlySelected );
7332
+ return saveAsVectorFileGeneral( qobject_cast<QgsVectorLayer *>( layer ), true, onlySelected, defaultToAddToMap );
7331
7333
}
7334
+ return QString();
7332
7335
}
7333
7336
7334
7337
void QgisApp::makeMemoryLayerPermanent( QgsVectorLayer *layer )
@@ -7371,7 +7374,7 @@ void QgisApp::makeMemoryLayerPermanent( QgsVectorLayer *layer )
7371
7374
}
7372
7375
};
7373
7376
7374
- saveAsVectorFileGeneral( layer, true, false, onSuccess, onFailure, 0, tr( "Save Scratch Layer" ) );
7377
+ saveAsVectorFileGeneral( layer, true, false, true, onSuccess, onFailure, 0, tr( "Save Scratch Layer" ) );
7375
7378
}
7376
7379
7377
7380
void QgisApp::saveAsLayerDefinition()
@@ -7475,15 +7478,15 @@ QgisAppFieldValueConverter *QgisAppFieldValueConverter::clone() const
7475
7478
7476
7479
///@endcond
7477
7480
7478
- void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption, bool onlySelected )
7481
+ QString QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption, bool onlySelected, bool defaultToAddToMap )
7479
7482
{
7480
7483
if ( !vlayer )
7481
7484
{
7482
7485
vlayer = qobject_cast<QgsVectorLayer *>( activeLayer() ); // FIXME: output of multiple layers at once?
7483
7486
}
7484
7487
7485
7488
if ( !vlayer )
7486
- return;
7489
+ return QString() ;
7487
7490
7488
7491
const QString layerId = vlayer->id();
7489
7492
@@ -7521,10 +7524,10 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
7521
7524
}
7522
7525
};
7523
7526
7524
- saveAsVectorFileGeneral( vlayer, symbologyOption, onlySelected, onSuccess, onFailure );
7527
+ return saveAsVectorFileGeneral( vlayer, symbologyOption, onlySelected, defaultToAddToMap , onSuccess, onFailure );
7525
7528
}
7526
7529
7527
- void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption, bool onlySelected, const std::function<void( const QString &, bool, const QString &, const QString &, const QString & )> &onSuccess, const std::function<void ( int, const QString & )> &onFailure, int options, const QString &dialogTitle )
7530
+ QString QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption, bool onlySelected, bool defaultToAddToMap , const std::function<void( const QString &, bool, const QString &, const QString &, const QString & )> &onSuccess, const std::function<void ( int, const QString & )> &onFailure, int options, const QString &dialogTitle )
7528
7531
{
7529
7532
QgsCoordinateReferenceSystem destCRS;
7530
7533
@@ -7540,11 +7543,13 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
7540
7543
dialog->setMapCanvas( mMapCanvas );
7541
7544
dialog->setIncludeZ( QgsWkbTypes::hasZ( vlayer->wkbType() ) );
7542
7545
dialog->setOnlySelected( onlySelected );
7546
+ dialog->setAddToCanvas( defaultToAddToMap );
7543
7547
7548
+ QString vectorFilename;
7544
7549
if ( dialog->exec() == QDialog::Accepted )
7545
7550
{
7546
7551
QString encoding = dialog->encoding();
7547
- QString vectorFilename = dialog->filename();
7552
+ vectorFilename = dialog->filename();
7548
7553
QString format = dialog->format();
7549
7554
QStringList datasourceOptions = dialog->datasourceOptions();
7550
7555
bool autoGeometryType = dialog->automaticGeometryType();
@@ -7612,6 +7617,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
7612
7617
}
7613
7618
7614
7619
delete dialog;
7620
+ return vectorFilename;
7615
7621
}
7616
7622
7617
7623
void QgisApp::layerProperties()
0 commit comments