Skip to content
Permalink
Browse files

[processing] Fix Python representation of matrix parameter values wit…

…h null entries
  • Loading branch information
nyalldawson committed Jun 13, 2018
1 parent 0da3069 commit 59938c83ccf5ab0666627ff4ed89960b96b6f730
Showing with 14 additions and 2 deletions.
  1. +12 −2 src/core/processing/qgsprocessingparameters.cpp
  2. +2 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -1869,13 +1869,23 @@ QString QgsProcessingParameterMatrix::valueAsPythonString( const QVariant &value
QStringList parts2;
Q_FOREACH ( const QVariant &v2, v.toList() )
{
parts2 << v2.toString();
if ( v2.isNull() || !v2.isValid() )
parts2 << QStringLiteral( "None" );
else if ( v2.toString().isEmpty() )
parts2 << QStringLiteral( "''" );
else
parts2 << v2.toString();
}
parts << parts2.join( ',' ).prepend( '[' ).append( ']' );
}
else
{
parts << v.toString();
if ( v.isNull() || !v.isValid() )
parts << QStringLiteral( "None" );
else if ( v.toString().isEmpty() )
parts << QStringLiteral( "''" );
else
parts << v.toString();
}
}

@@ -2864,6 +2864,8 @@ void TestQgsProcessing::parameterMatrix()
QCOMPARE( def->valueAsPythonString( 5, context ), QStringLiteral( "[5]" ) );
QCOMPARE( def->valueAsPythonString( QVariantList() << 1 << 2 << 3, context ), QStringLiteral( "[1,2,3]" ) );
QCOMPARE( def->valueAsPythonString( QVariantList() << ( QVariantList() << 1 << 2 << 3 ) << ( QVariantList() << 1 << 2 << 3 ), context ), QStringLiteral( "[1,2,3,1,2,3]" ) );
QCOMPARE( def->valueAsPythonString( QVariantList() << ( QVariantList() << 1 << QVariant() << 3 ) << ( QVariantList() << QVariant() << 2 << 3 ), context ), QStringLiteral( "[1,None,3,None,2,3]" ) );
QCOMPARE( def->valueAsPythonString( QVariantList() << ( QVariantList() << 1 << QString( "" ) << 3 ) << ( QVariantList() << 1 << 2 << QString( "" ) ), context ), QStringLiteral( "[1,'',3,1,2,'']" ) );
QCOMPARE( def->valueAsPythonString( "1,2,3", context ), QStringLiteral( "[1,2,3]" ) );
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) );

0 comments on commit 59938c8

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