Skip to content
Permalink
Browse files

More array and map expression formatting

  • Loading branch information
m-kuhn committed Aug 24, 2018
1 parent 65fd187 commit 8e1aeda464cd478b8c6cea43d094835a1d1d025d
Showing with 18 additions and 13 deletions.
  1. +18 −13 src/core/expression/qgsexpression.cpp
@@ -903,45 +903,50 @@ QString QgsExpression::formatPreviewString( const QVariant &value )
}
else if ( value.type() == QVariant::Map )
{
QString mapStr = QStringLiteral( "{ " );
QString mapStr = QStringLiteral( "{" );
const QVariantMap map = value.toMap();
QString separator;
for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
{
mapStr.append( separator );
if ( separator.isEmpty() )
separator = QStringLiteral( ", " );
separator = QStringLiteral( "," );

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

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

0 comments on commit 8e1aeda

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