Skip to content
Permalink
Browse files

Adjust representation of arrays and maps in expressions

array representation:

```
array: [ 1, 2, 3 ]
```

before:

```
array: 1, 2, 3
```

map representation:

```
map: { one: 1, two: 2, three: 3 }
```

before

```
map: one: 1, two: 2, three: 3
```
  • Loading branch information
m-kuhn committed Aug 23, 2018
1 parent 0b96fd9 commit 750f63fb6f5e05bc208605ec77eb1bd0f5bf651b
Showing with 19 additions and 9 deletions.
  1. +19 −9 src/core/expression/qgsexpression.cpp
@@ -903,34 +903,44 @@ QString QgsExpression::formatPreviewString( const QVariant &value )
}
else if ( value.type() == QVariant::Map )
{
QString mapStr;
QString mapStr = QStringLiteral( "{ " );
const QVariantMap map = value.toMap();
QString separator;
for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
{
if ( !mapStr.isEmpty() ) mapStr.append( ", " );
mapStr.append( separator );
if ( separator.isEmpty() )
separator = QStringLiteral( ", " );

mapStr.append( it.key() ).append( ": " ).append( formatPreviewString( it.value() ) );
if ( mapStr.length() > MAX_PREVIEW + 3 )
if ( mapStr.length() > MAX_PREVIEW + 5 )
{
mapStr = QString( tr( "%1…" ) ).arg( mapStr.left( MAX_PREVIEW ) );
mapStr = tr( "%1…" ).arg( mapStr.left( MAX_PREVIEW ) );
break;
}
}
mapStr += QStringLiteral( " }" );
return tr( "<i>&lt;map: %1&gt;</i>" ).arg( mapStr );
}
else if ( value.type() == QVariant::List || value.type() == QVariant::StringList )
{
QString listStr;
QString listStr = QStringLiteral( "[ " );
const QVariantList list = value.toList();
for ( QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
QString separator;
for ( const QVariant &arrayValue : list )
{
if ( !listStr.isEmpty() ) listStr.append( ", " );
listStr.append( formatPreviewString( *it ) );
if ( listStr.length() > MAX_PREVIEW + 3 )
listStr.append( separator );
if ( separator.isEmpty() )
separator = QStringLiteral( ", " );

listStr.append( formatPreviewString( arrayValue ) );
if ( listStr.length() > MAX_PREVIEW + 5 )
{
listStr = QString( tr( "%1…" ) ).arg( listStr.left( MAX_PREVIEW ) );
break;
}
}
listStr += QStringLiteral( " ]" );
return tr( "<i>&lt;array: %1&gt;</i>" ).arg( listStr );
}
else

0 comments on commit 750f63f

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