Skip to content

Commit

Permalink
QVariantMaps always have string keys
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 24, 2018
1 parent 0274bc8 commit f9da596
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpression.cpp
Expand Up @@ -912,7 +912,7 @@ QString QgsExpression::formatPreviewString( const QVariant &value )
if ( separator.isEmpty() )
separator = QStringLiteral( "," );

mapStr.append( QStringLiteral( " %1: %2" ).arg( quotedValue( it.key() ), formatPreviewString( it.value() ) ) );
mapStr.append( QStringLiteral( " '%1': %2" ).arg( it.key(), formatPreviewString( it.value() ) ) );
if ( mapStr.length() > MAX_PREVIEW - 3 )
{
mapStr = tr( "%1…" ).arg( mapStr.left( MAX_PREVIEW - 2 ) );
Expand Down
8 changes: 4 additions & 4 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -3112,11 +3112,11 @@ class TestQgsExpression: public QObject
QCOMPARE( QgsExpression::formatPreviewString( QVariant( QVariantMap() ) ), QStringLiteral( "{}" ) );

QVariantMap map;
map[1] = "One";
map[2] = "Two";
QCOMPARE( QgsExpression::formatPreviewString( QVariant( map ) ), QStringLiteral( "{ 1: 'One', 2: 'Two' }" ) );
map[QStringLiteral( "1" )] = "One";
map[QStringLiteral( "2" )] = "Two";
QCOMPARE( QgsExpression::formatPreviewString( QVariant( map ) ), QStringLiteral( "{ '1': 'One', 2: 'Two' }" ) );
map[QStringLiteral( "3" )] = "A very long string that is going to be truncated";
QCOMPARE( QgsExpression::formatPreviewString( QVariant( map ) ), QStringLiteral( "{ 1: 'One', 2: 'Two', '3': 'A very long string that is going to … }" ) );
QCOMPARE( QgsExpression::formatPreviewString( QVariant( map ) ), QStringLiteral( "{ '1': 'One', '2': 'Two', '3': 'A very long string that is going to … }" ) );

QVariantList list;
list << 1 << 2 << 3;
Expand Down

0 comments on commit f9da596

Please sign in to comment.