Skip to content
Permalink
Browse files

QVariantMaps always have string keys

  • Loading branch information
m-kuhn committed Aug 24, 2018
1 parent 0274bc8 commit f9da59646248fb2c3f28b6d247fdabc7cebde1e8
Showing with 5 additions and 5 deletions.
  1. +1 −1 src/core/expression/qgsexpression.cpp
  2. +4 −4 tests/src/core/testqgsexpression.cpp
@@ -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 ) );
@@ -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;

0 comments on commit f9da596

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