Skip to content

Commit

Permalink
Fix conversion of direct vector layer parameters to python strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 20, 2017
1 parent f867b65 commit d2a90f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -2565,6 +2565,10 @@ QString QgsProcessingParameterFeatureSource::valueAsPythonString( const QVariant
}
}
}
else if ( QgsVectorLayer *layer = qobject_cast< QgsVectorLayer * >( qvariant_cast<QObject *>( value ) ) )
{
return layer->source().prepend( '\'' ).append( '\'' );
}

return value.toString().prepend( '\'' ).append( '\'' );
}
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsprocessing.cpp
Expand Up @@ -3442,6 +3442,7 @@ void TestQgsProcessing::parameterFeatureSource()
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')" ) );
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( v2 ), context ), QStringLiteral( "'%1'" ).arg( vector2 ) );

QVariantMap map = def->toVariantMap();
QgsProcessingParameterFeatureSource fromMap( "x" );
Expand Down

0 comments on commit d2a90f4

Please sign in to comment.