Skip to content
Permalink
Browse files

[processing] Ensure unset parameters are translated to Python

None values when representing parameters as pythong strings
  • Loading branch information
nyalldawson committed May 10, 2018
1 parent e55bb55 commit d05f95f7d5b25cb130724a9a783fb5213c4b376e
Showing with 92 additions and 0 deletions.
  1. +66 −0 src/core/processing/qgsprocessingparameters.cpp
  2. +26 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -1225,6 +1225,9 @@ bool QgsProcessingParameterDefinition::checkValueIsAcceptable( const QVariant &i

QString QgsProcessingParameterDefinition::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -1291,6 +1294,9 @@ QgsProcessingParameterDefinition *QgsProcessingParameterBoolean::clone() const

QString QgsProcessingParameterBoolean::valueAsPythonString( const QVariant &val, QgsProcessingContext & ) const
{
if ( !val.isValid() )
return QStringLiteral( "None" );

if ( val.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
return val.toBool() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
@@ -1344,6 +1350,9 @@ bool QgsProcessingParameterCrs::checkValueIsAcceptable( const QVariant &input, Q

QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -1405,6 +1414,9 @@ bool QgsProcessingParameterMapLayer::checkValueIsAcceptable( const QVariant &inp

QString QgsProcessingParameterMapLayer::valueAsPythonString( const QVariant &val, QgsProcessingContext &context ) const
{
if ( !val.isValid() )
return QStringLiteral( "None" );

if ( val.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );

@@ -1487,6 +1499,9 @@ bool QgsProcessingParameterExtent::checkValueIsAcceptable( const QVariant &input

QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -1574,6 +1589,9 @@ bool QgsProcessingParameterPoint::checkValueIsAcceptable( const QVariant &input,

QString QgsProcessingParameterPoint::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -1714,6 +1732,9 @@ bool QgsProcessingParameterMatrix::checkValueIsAcceptable( const QVariant &input

QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -1874,6 +1895,9 @@ bool QgsProcessingParameterMultipleLayers::checkValueIsAcceptable( const QVarian

QString QgsProcessingParameterMultipleLayers::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -2025,6 +2049,9 @@ bool QgsProcessingParameterNumber::checkValueIsAcceptable( const QVariant &input

QString QgsProcessingParameterNumber::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -2155,6 +2182,9 @@ bool QgsProcessingParameterRange::checkValueIsAcceptable( const QVariant &input,

QString QgsProcessingParameterRange::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -2241,6 +2271,9 @@ bool QgsProcessingParameterRasterLayer::checkValueIsAcceptable( const QVariant &

QString QgsProcessingParameterRasterLayer::valueAsPythonString( const QVariant &val, QgsProcessingContext &context ) const
{
if ( !val.isValid() )
return QStringLiteral( "None" );

if ( val.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );

@@ -2330,6 +2363,9 @@ bool QgsProcessingParameterEnum::checkValueIsAcceptable( const QVariant &input,

QString QgsProcessingParameterEnum::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -2443,6 +2479,9 @@ QgsProcessingParameterDefinition *QgsProcessingParameterString::clone() const

QString QgsProcessingParameterString::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -2525,6 +2564,9 @@ QgsProcessingParameterDefinition *QgsProcessingParameterExpression::clone() cons

QString QgsProcessingParameterExpression::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -2623,6 +2665,9 @@ bool QgsProcessingParameterVectorLayer::checkValueIsAcceptable( const QVariant &

QString QgsProcessingParameterVectorLayer::valueAsPythonString( const QVariant &val, QgsProcessingContext &context ) const
{
if ( !val.isValid() )
return QStringLiteral( "None" );

if ( val.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );

@@ -2723,6 +2768,9 @@ bool QgsProcessingParameterField::checkValueIsAcceptable( const QVariant &input,

QString QgsProcessingParameterField::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -2942,6 +2990,9 @@ bool QgsProcessingParameterFeatureSource::checkValueIsAcceptable( const QVariant

QString QgsProcessingParameterFeatureSource::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -3120,6 +3171,9 @@ bool QgsProcessingParameterFeatureSink::checkValueIsAcceptable( const QVariant &

QString QgsProcessingParameterFeatureSink::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -3322,6 +3376,9 @@ bool QgsProcessingParameterRasterDestination::checkValueIsAcceptable( const QVar

QString QgsProcessingParameterRasterDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -3415,6 +3472,9 @@ bool QgsProcessingParameterFileDestination::checkValueIsAcceptable( const QVaria

QString QgsProcessingParameterFileDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -3628,6 +3688,9 @@ bool QgsProcessingParameterVectorDestination::checkValueIsAcceptable( const QVar

QString QgsProcessingParameterVectorDestination::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

@@ -3800,6 +3863,9 @@ bool QgsProcessingParameterBand::checkValueIsAcceptable( const QVariant &input,

QString QgsProcessingParameterBand::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
{
if ( !value.isValid() )
return QStringLiteral( "None" );

if ( value.canConvert<QgsProperty>() )
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( value.value< QgsProperty >().asExpression() );

0 comments on commit d05f95f

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