diff --git a/src/analysis/processing/qgsalgorithmmergevector.cpp b/src/analysis/processing/qgsalgorithmmergevector.cpp index a73a73e4231a..4d312ae0466b 100644 --- a/src/analysis/processing/qgsalgorithmmergevector.cpp +++ b/src/analysis/processing/qgsalgorithmmergevector.cpp @@ -17,7 +17,7 @@ #include "qgsalgorithmmergevector.h" #include "qgsvectorlayer.h" - +#include "qgsprocessingparameters.h" ///@cond PRIVATE QString QgsMergeVectorAlgorithm::name() const @@ -50,6 +50,9 @@ void QgsMergeVectorAlgorithm::initAlgorithm( const QVariantMap & ) addParameter( new QgsProcessingParameterMultipleLayers( QStringLiteral( "LAYERS" ), QObject::tr( "Input layers" ), Qgis::ProcessingSourceType::Vector ) ); addParameter( new QgsProcessingParameterCrs( QStringLiteral( "CRS" ), QObject::tr( "Destination CRS" ), QVariant(), true ) ); addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Merged" ) ) ); + + // new boolean parameter to add source layer information + addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "ADD_SOURCE_FIELDS" ), QObject::tr( "Add source layer information (layer name and path)" ), true ) ); } QString QgsMergeVectorAlgorithm::shortDescription() const @@ -62,7 +65,7 @@ QString QgsMergeVectorAlgorithm::shortHelpString() const return QObject::tr( "This algorithm combines multiple vector layers of the same geometry type into a single one.\n\n" "The attribute table of the resulting layer will contain the fields from all input layers. " "If fields with the same name but different types are found then the exported field will be automatically converted into a string type field. " - "New fields storing the original layer name and source are also added.\n\n" + "Optionally, new fields storing the original layer name and source can be added.\n\n" "If any input layers contain Z or M values, then the output layer will also contain these values. Similarly, " "if any of the input layers are multi-part, the output layer will also be a multi-part layer.\n\n" "Optionally, the destination coordinate reference system (CRS) for the merged layer can be set. If it is not set, the CRS will be " @@ -83,6 +86,8 @@ QVariantMap QgsMergeVectorAlgorithm::processAlgorithm( const QVariantMap ¶me { const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral( "LAYERS" ), context ); + const bool addSourceFields = parameterAsBool( parameters, QStringLiteral( "ADD_SOURCE_FIELDS" ), context ); + QgsFields outputFields; long totalFeatureCount = 0; Qgis::WkbType outputType = Qgis::WkbType::Unknown; @@ -185,16 +190,20 @@ QVariantMap QgsMergeVectorAlgorithm::processAlgorithm( const QVariantMap ¶me } bool addLayerField = false; - if ( outputFields.lookupField( QStringLiteral( "layer" ) ) < 0 ) - { - outputFields.append( QgsField( QStringLiteral( "layer" ), QMetaType::Type::QString, QString() ) ); - addLayerField = true; - } bool addPathField = false; - if ( outputFields.lookupField( QStringLiteral( "path" ) ) < 0 ) + if ( addSourceFields ) // add source layer information { - outputFields.append( QgsField( QStringLiteral( "path" ), QMetaType::Type::QString, QString() ) ); - addPathField = true; + if ( outputFields.lookupField( QStringLiteral( "layer" ) ) < 0 ) + { + outputFields.append( QgsField( QStringLiteral( "layer" ), QMetaType::Type::QString, QString() ) ); + addLayerField = true; + } + + if ( outputFields.lookupField( QStringLiteral( "path" ) ) < 0 ) + { + outputFields.append( QgsField( QStringLiteral( "path" ), QMetaType::Type::QString, QString() ) ); + addPathField = true; + } } QString dest;