Skip to content
Permalink
Browse files

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

  • Loading branch information
nyalldawson committed Jul 25, 2018
1 parent 263ce39 commit ba56ba21335d017617dc7138d54104554ad5752c
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 ba56ba2

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