Skip to content

Commit

Permalink
[processing] Fix Python representation of matrix parameter values wit…
Browse files Browse the repository at this point in the history
…h null entries
  • Loading branch information
nyalldawson committed Jun 13, 2018
1 parent 0da3069 commit 59938c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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')" ) );

Expand Down

0 comments on commit 59938c8

Please sign in to comment.