Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[processing] Prefer to log layer source instead of id as it's persistent
- Loading branch information
|
@@ -3229,7 +3229,13 @@ QString QgsProcessingParameterFeatureSource::valueAsPythonString( const QVariant |
|
|
return QgsProcessingUtils::stringToPythonLiteral( layer->source() ); |
|
|
} |
|
|
|
|
|
return QgsProcessingUtils::stringToPythonLiteral( value.toString() ); |
|
|
QString layerString = value.toString(); |
|
|
|
|
|
// prefer to use layer source if possible (since it's persistent) |
|
|
if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( QgsProcessingUtils::mapLayerFromString( layerString, context ) ) ) |
|
|
layerString = layer->source(); |
|
|
|
|
|
return QgsProcessingUtils::stringToPythonLiteral( layerString ); |
|
|
} |
|
|
|
|
|
QString QgsProcessingParameterFeatureSource::asScriptCode() const |
|
|
|
@@ -4393,6 +4393,7 @@ void TestQgsProcessing::parameterFeatureSource() |
|
|
QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) ); |
|
|
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( "abc" ) ), context ), QStringLiteral( "'abc'" ) ); |
|
|
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( v2->id() ) ), context ), QStringLiteral( "'%1'" ).arg( vector2 ) ); |
|
|
QCOMPARE( def->valueAsPythonString( v2->id(), context ), QStringLiteral( "'%1'" ).arg( vector2 ) ); |
|
|
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( QgsProperty::fromValue( "abc" ), true ) ), context ), QStringLiteral( "QgsProcessingFeatureSourceDefinition('abc', True)" ) ); |
|
|
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProcessingFeatureSourceDefinition( QgsProperty::fromExpression( "\"abc\" || \"def\"" ) ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"abc\" || \"def\"')" ) ); |
|
|
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) ); |
|
|