Skip to content
Permalink
Browse files

[processing] Prefer to log layer source instead of id as it's persistent

(cherry-picked from ba56ba2)
  • Loading branch information
nyalldawson committed Jul 25, 2018
1 parent 79b7084 commit f43c8587508b2babb110d2e28ad457335c52187a
Showing with 8 additions and 1 deletion.
  1. +7 −1 src/core/processing/qgsprocessingparameters.cpp
  2. +1 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -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')" ) );

0 comments on commit f43c858

Please sign in to comment.
You can’t perform that action at this time.