Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 17, 2024
1 parent 6cfa8ef commit be79e80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions src/analysis/processing/qgsmetadataalgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QString QgsCopyLayerMetadataAlgorithm::groupId() const

QString QgsCopyLayerMetadataAlgorithm::shortHelpString() const
{
return QObject::tr( "Copies metadata from an input layer to a target layer.\n\nAny existing metadata in the target layer will be replaced." );
return QObject::tr( "Copies metadata from an source layer to a target layer.\n\nAny existing metadata in the target layer will be replaced." );
}

QgsCopyLayerMetadataAlgorithm *QgsCopyLayerMetadataAlgorithm::createInstance() const
Expand All @@ -56,27 +56,27 @@ QgsCopyLayerMetadataAlgorithm *QgsCopyLayerMetadataAlgorithm::createInstance() c

void QgsCopyLayerMetadataAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "INPUT" ), QObject::tr( "Source layer" ) ) );
addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "SOURCE" ), QObject::tr( "Source layer" ) ) );
addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "TARGET" ), QObject::tr( "Target layer" ) ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DEFAULT" ), QObject::tr( "Save metadata as default" ), false ) );
addOutput( new QgsProcessingOutputMapLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Updated layer" ) ) );
}

bool QgsCopyLayerMetadataAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
QgsMapLayer *inputLayer = parameterAsLayer( parameters, QStringLiteral( "INPUT" ), context );
QgsMapLayer *sourceLayer = parameterAsLayer( parameters, QStringLiteral( "SOURCE" ), context );
QgsMapLayer *targetLayer = parameterAsLayer( parameters, QStringLiteral( "TARGET" ), context );
const bool saveAsDefault = parameterAsBool( parameters, QStringLiteral( "DEFAULT" ), context );

if ( !inputLayer )
throw QgsProcessingException( QObject::tr( "Invalid input layer" ) );
if ( !sourceLayer )
throw QgsProcessingException( QObject::tr( "Invalid source layer" ) );

if ( !targetLayer )
throw QgsProcessingException( QObject::tr( "Invalid target layer" ) );

mLayerId = targetLayer->id();

targetLayer->setMetadata( inputLayer->metadata() );
targetLayer->setMetadata( sourceLayer->metadata() );
if ( saveAsDefault )
{
bool ok;
Expand Down Expand Up @@ -348,7 +348,7 @@ QString QgsUpdateLayerMetadataAlgorithm::groupId() const

QString QgsUpdateLayerMetadataAlgorithm::shortHelpString() const
{
return QObject::tr( "Copies all non-empty metadata fields from an input layer to a target layer.\n\nLeaves empty input fields unchaged in the target." );
return QObject::tr( "Copies all non-empty metadata fields from an source layer to a target layer.\n\nLeaves empty input fields unchanged in the target." );
}

QgsUpdateLayerMetadataAlgorithm *QgsUpdateLayerMetadataAlgorithm::createInstance() const
Expand All @@ -358,26 +358,26 @@ QgsUpdateLayerMetadataAlgorithm *QgsUpdateLayerMetadataAlgorithm::createInstance

void QgsUpdateLayerMetadataAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "INPUT" ), QObject::tr( "Source layer" ) ) );
addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "SOURCE" ), QObject::tr( "Source layer" ) ) );
addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "TARGET" ), QObject::tr( "Target layer" ) ) );
addOutput( new QgsProcessingOutputMapLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Updated layer" ) ) );
}

bool QgsUpdateLayerMetadataAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
QgsMapLayer *inputLayer = parameterAsLayer( parameters, QStringLiteral( "INPUT" ), context );
QgsMapLayer *sourceLayer = parameterAsLayer( parameters, QStringLiteral( "SOURCE" ), context );
QgsMapLayer *targetLayer = parameterAsLayer( parameters, QStringLiteral( "TARGET" ), context );

if ( !inputLayer )
throw QgsProcessingException( QObject::tr( "Invalid input layer" ) );
if ( !sourceLayer )
throw QgsProcessingException( QObject::tr( "Invalid source layer" ) );

if ( !targetLayer )
throw QgsProcessingException( QObject::tr( "Invalid target layer" ) );

mLayerId = targetLayer->id();

std::unique_ptr<QgsLayerMetadata> md( targetLayer->metadata().clone() );
md->combine( &inputLayer->metadata() );
md->combine( &sourceLayer->metadata() );
targetLayer->setMetadata( *md.get() );

return true;
Expand Down
16 changes: 8 additions & 8 deletions tests/src/analysis/testqgsprocessingalgspt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,22 +1885,22 @@ void TestQgsProcessingAlgsPt2::generateElevationProfileImage()

void TestQgsProcessingAlgsPt2::copyMetadata()
{
std::unique_ptr<QgsVectorLayer> inputLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=epsg:4326&field=pk:int&field=col1:string" ), QStringLiteral( "input" ), QStringLiteral( "memory" ) );
QVERIFY( inputLayer->isValid() );
std::unique_ptr<QgsVectorLayer> sourceLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=epsg:4326&field=pk:int&field=col1:string" ), QStringLiteral( "input" ), QStringLiteral( "memory" ) );
QVERIFY( sourceLayer->isValid() );

std::unique_ptr<QgsVectorLayer> targetLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=epsg:4326&field=pk:int&field=col1:string" ), QStringLiteral( "target" ), QStringLiteral( "memory" ) );
QVERIFY( targetLayer->isValid() );

QgsLayerMetadata md;
md.setTitle( QStringLiteral( "Title" ) );
md.setAbstract( QStringLiteral( "Abstract" ) );
inputLayer->setMetadata( md );
sourceLayer->setMetadata( md );

std::unique_ptr<QgsProcessingAlgorithm> alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:copylayermetadata" ) ) );
QVERIFY( alg != nullptr );

QVariantMap parameters;
parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( inputLayer.get() ) );
parameters.insert( QStringLiteral( "SOURCE" ), QVariant::fromValue( sourceLayer.get() ) );
parameters.insert( QStringLiteral( "TARGET" ), QVariant::fromValue( targetLayer.get() ) );

bool ok = false;
Expand Down Expand Up @@ -2037,8 +2037,8 @@ void TestQgsProcessingAlgsPt2::addHistoryMetadata()

void TestQgsProcessingAlgsPt2::updateMetadata()
{
std::unique_ptr<QgsVectorLayer> inputLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=epsg:4326&field=pk:int&field=col1:string" ), QStringLiteral( "input" ), QStringLiteral( "memory" ) );
QVERIFY( inputLayer->isValid() );
std::unique_ptr<QgsVectorLayer> sourceLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=epsg:4326&field=pk:int&field=col1:string" ), QStringLiteral( "input" ), QStringLiteral( "memory" ) );
QVERIFY( sourceLayer->isValid() );

std::unique_ptr<QgsVectorLayer> targetLayer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=epsg:4326&field=pk:int&field=col1:string" ), QStringLiteral( "target" ), QStringLiteral( "memory" ) );
QVERIFY( targetLayer->isValid() );
Expand All @@ -2047,7 +2047,7 @@ void TestQgsProcessingAlgsPt2::updateMetadata()
mdInput.setTitle( QStringLiteral( "New title" ) );
mdInput.setAbstract( QStringLiteral( "New abstract" ) );
mdInput.setLanguage( QStringLiteral( "Language" ) );
inputLayer->setMetadata( mdInput );
sourceLayer->setMetadata( mdInput );

QgsLayerMetadata mdTarget;
mdTarget.setTitle( QStringLiteral( "Title" ) );
Expand All @@ -2059,7 +2059,7 @@ void TestQgsProcessingAlgsPt2::updateMetadata()
QVERIFY( alg != nullptr );

QVariantMap parameters;
parameters.insert( QStringLiteral( "INPUT" ), QVariant::fromValue( inputLayer.get() ) );
parameters.insert( QStringLiteral( "SOURCE" ), QVariant::fromValue( sourceLayer.get() ) );
parameters.insert( QStringLiteral( "TARGET" ), QVariant::fromValue( targetLayer.get() ) );

bool ok = false;
Expand Down

0 comments on commit be79e80

Please sign in to comment.