Skip to content

Commit

Permalink
[processing] Ensure unset parameters are translated to Python
Browse files Browse the repository at this point in the history
None values when representing parameters as pythong strings
  • Loading branch information
nyalldawson committed May 10, 2018
1 parent e55bb55 commit d05f95f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );

Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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() );

Expand Down
Loading

0 comments on commit d05f95f

Please sign in to comment.