Skip to content

Commit ba56ba2

Browse files
committed
[processing] Prefer to log layer source instead of id as it's persistent
1 parent 263ce39 commit ba56ba2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/core/processing/qgsprocessingparameters.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3229,7 +3229,13 @@ QString QgsProcessingParameterFeatureSource::valueAsPythonString( const QVariant
32293229
return QgsProcessingUtils::stringToPythonLiteral( layer->source() );
32303230
}
32313231

3232-
return QgsProcessingUtils::stringToPythonLiteral( value.toString() );
3232+
QString layerString = value.toString();
3233+
3234+
// prefer to use layer source if possible (since it's persistent)
3235+
if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context ) ) )
3236+
layerString = layer->source();
3237+
3238+
return QgsProcessingUtils::stringToPythonLiteral( layerString );
32333239
}
32343240

32353241
QString QgsProcessingParameterFeatureSource::asScriptCode() const

tests/src/analysis/testqgsprocessing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4393,6 +4393,7 @@ void TestQgsProcessing::parameterFeatureSource()
43934393
QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) );
43944394
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( "abc" ) ), context ), QStringLiteral( "'abc'" ) );
43954395
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( v2->id() ) ), context ), QStringLiteral( "'%1'" ).arg( vector2 ) );
4396+
QCOMPARE( def->valueAsPythonString( v2->id(), context ), QStringLiteral( "'%1'" ).arg( vector2 ) );
43964397
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( QgsProperty::fromValue( "abc" ), true ) ), context ), QStringLiteral( "QgsProcessingFeatureSourceDefinition('abc', True)" ) );
43974398
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"abc\" || \"def\"')" ) );
43984399
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) );

0 commit comments

Comments
 (0)