Skip to content

Commit 750f63f

Browse files
committed
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 ```
1 parent 0b96fd9 commit 750f63f

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/core/expression/qgsexpression.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -903,34 +903,44 @@ QString QgsExpression::formatPreviewString( const QVariant &value )
903903
}
904904
else if ( value.type() == QVariant::Map )
905905
{
906-
QString mapStr;
906+
QString mapStr = QStringLiteral( "{ " );
907907
const QVariantMap map = value.toMap();
908+
QString separator;
908909
for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
909910
{
910-
if ( !mapStr.isEmpty() ) mapStr.append( ", " );
911+
mapStr.append( separator );
912+
if ( separator.isEmpty() )
913+
separator = QStringLiteral( ", " );
914+
911915
mapStr.append( it.key() ).append( ": " ).append( formatPreviewString( it.value() ) );
912-
if ( mapStr.length() > MAX_PREVIEW + 3 )
916+
if ( mapStr.length() > MAX_PREVIEW + 5 )
913917
{
914-
mapStr = QString( tr( "%1…" ) ).arg( mapStr.left( MAX_PREVIEW ) );
918+
mapStr = tr( "%1…" ).arg( mapStr.left( MAX_PREVIEW ) );
915919
break;
916920
}
917921
}
922+
mapStr += QStringLiteral( " }" );
918923
return tr( "<i>&lt;map: %1&gt;</i>" ).arg( mapStr );
919924
}
920925
else if ( value.type() == QVariant::List || value.type() == QVariant::StringList )
921926
{
922-
QString listStr;
927+
QString listStr = QStringLiteral( "[ " );
923928
const QVariantList list = value.toList();
924-
for ( QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
929+
QString separator;
930+
for ( const QVariant &arrayValue : list )
925931
{
926-
if ( !listStr.isEmpty() ) listStr.append( ", " );
927-
listStr.append( formatPreviewString( *it ) );
928-
if ( listStr.length() > MAX_PREVIEW + 3 )
932+
listStr.append( separator );
933+
if ( separator.isEmpty() )
934+
separator = QStringLiteral( ", " );
935+
936+
listStr.append( formatPreviewString( arrayValue ) );
937+
if ( listStr.length() > MAX_PREVIEW + 5 )
929938
{
930939
listStr = QString( tr( "%1…" ) ).arg( listStr.left( MAX_PREVIEW ) );
931940
break;
932941
}
933942
}
943+
listStr += QStringLiteral( " ]" );
934944
return tr( "<i>&lt;array: %1&gt;</i>" ).arg( listStr );
935945
}
936946
else

0 commit comments

Comments
 (0)