diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index e584b303f47e..1e63b724a070 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -8328,6 +8328,10 @@ void QgisApp::makeMemoryLayerPermanent( QgsVectorLayer *layer ) source += QStringLiteral( "|layername=%1" ).arg( newLayerName ); vl->setDataSource( source, vl->name(), QStringLiteral( "ogr" ), options ); vl->triggerRepaint(); + // we don't want this flag anymore -- the layer has changed format and from now on + // primary keys should be retained if it's exported to a new file + vl->removeCustomProperty( QStringLiteral( "OnConvertFormatRegeneratePrimaryKey" ) ); + mLayerTreeView->refreshLayerSymbology( vl->id() ); this->visibleMessageBar()->pushMessage( tr( "Layer Saved" ), tr( "Successfully saved scratch layer to %2" ).arg( QUrl::fromLocalFile( newFilename ).toString(), QDir::toNativeSeparators( newFilename ) ), @@ -8608,8 +8612,14 @@ QString QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbology options.saveMetadata = dialog->persistMetadata(); options.layerMetadata = vlayer->metadata(); + QgsFeatureSink::SinkFlags sinkFlags; + if ( vlayer->customProperty( QStringLiteral( "OnConvertFormatRegeneratePrimaryKey" ) ).toBool() ) + { + sinkFlags.setFlag( QgsFeatureSink::RegeneratePrimaryKey, true ); + } + bool addToCanvas = dialog->addToCanvas(); - QgsVectorFileWriterTask *writerTask = new QgsVectorFileWriterTask( vlayer, vectorFilename, options ); + QgsVectorFileWriterTask *writerTask = new QgsVectorFileWriterTask( vlayer, vectorFilename, options, sinkFlags ); // when writer is successful: connect( writerTask, &QgsVectorFileWriterTask::completed, this, [onSuccess, addToCanvas, encoding, vectorFilename, format]( const QString & newFilename, const QString & newLayer )