diff --git a/resources/function_help/json/array b/resources/function_help/json/array
index ee71d768809..ee82b1ab630 100644
--- a/resources/function_help/json/array
+++ b/resources/function_help/json/array
@@ -7,6 +7,6 @@
{"arg":"value1", "syntaxOnly": true},
{"arg":"value2", "syntaxOnly": true},
{"arg":"value", "descOnly": true, "description":"a value"}],
- "examples": [ { "expression":"array(2,10)", "returns":"array: 2, 10"}
+ "examples": [ { "expression":"array(2,10)", "returns":"[ 2, 10 ]"}
]
}
diff --git a/resources/function_help/json/array_append b/resources/function_help/json/array_append
index 4da5a150087..e2865d8ffcf 100644
--- a/resources/function_help/json/array_append
+++ b/resources/function_help/json/array_append
@@ -4,5 +4,5 @@
"description": "Returns an array with the given value added at the end.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"value","description":"the value to add"}],
- "examples": [ { "expression":"array_append(array(1,2,3),4)", "returns":"array: 1,2,3,4"}]
+ "examples": [ { "expression":"array_append(array(1,2,3),4)", "returns":"[ 1, 2, 3, 4 ]"}]
}
diff --git a/resources/function_help/json/array_cat b/resources/function_help/json/array_cat
index 7529a3f7132..2a7be9e06e1 100644
--- a/resources/function_help/json/array_cat
+++ b/resources/function_help/json/array_cat
@@ -7,6 +7,6 @@
{"arg":"array1", "syntaxOnly": true},
{"arg":"array2", "syntaxOnly": true},
{"arg":"array", "descOnly": true, "description":"an array"}],
- "examples": [ { "expression":"array_cat(array(1,2),array(2,3))", "returns":"array: 1,2,2,3"}
+ "examples": [ { "expression":"array_cat(array(1,2),array(2,3))", "returns":"[ 1, 2, 2, 3 ]"}
]
}
diff --git a/resources/function_help/json/array_distinct b/resources/function_help/json/array_distinct
index 7dcf78c101d..a3147156a5b 100644
--- a/resources/function_help/json/array_distinct
+++ b/resources/function_help/json/array_distinct
@@ -4,6 +4,6 @@
"description": "Returns an array containing distinct values of the given array.",
"arguments": [
{"arg":"array","description":"an array"}],
- "examples": [ { "expression":"array_distinct(array(1,2,3,2,1))", "returns":"array: 1,2,3"}
+ "examples": [ { "expression":"array_distinct(array(1,2,3,2,1))", "returns":"[ 1, 2, 3 ]"}
]
}
diff --git a/resources/function_help/json/array_foreach b/resources/function_help/json/array_foreach
index b1b84933cdd..ee27c572898 100644
--- a/resources/function_help/json/array_foreach
+++ b/resources/function_help/json/array_foreach
@@ -7,7 +7,7 @@
{"arg":"expression","description":"an expression to evaluate on each item. The variable `@element` will be replaced by the current value."}
],
"examples": [
- { "expression": "array_foreach(array('a','b','c'),upper(@element))", "returns":"array: 'A', 'B', 'C'"},
- { "expression": "array_foreach(array(1,2,3),@element + 10)", "returns":"array: 11, 12, 13"}
+ { "expression": "array_foreach(array('a','b','c'),upper(@element))", "returns":"[ 'A', 'B', 'C' ]"},
+ { "expression": "array_foreach(array(1,2,3),@element + 10)", "returns":"[ 11, 12, 13 ]"}
]
}
diff --git a/resources/function_help/json/array_insert b/resources/function_help/json/array_insert
index dab0f495cca..8d5160549a2 100644
--- a/resources/function_help/json/array_insert
+++ b/resources/function_help/json/array_insert
@@ -5,5 +5,5 @@
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"pos","description":"the position where to add (0 based)"},
{"arg":"value","description":"the value to add"}],
- "examples": [ { "expression":"array_insert(array(1,2,3),1,100)", "returns":"array: 1,100,2,3"}]
+ "examples": [ { "expression":"array_insert(array(1,2,3),1,100)", "returns":"[ 1, 100, 2, 3 ]"}]
}
diff --git a/resources/function_help/json/array_prepend b/resources/function_help/json/array_prepend
index a5d49c84cb6..8228d4f8216 100644
--- a/resources/function_help/json/array_prepend
+++ b/resources/function_help/json/array_prepend
@@ -4,5 +4,5 @@
"description": "Returns an array with the given value added at the beginning.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"value","description":"the value to add"}],
- "examples": [ { "expression":"array_prepend(array(1,2,3),0)", "returns":"array: 0,1,2,3"}]
+ "examples": [ { "expression":"array_prepend(array(1,2,3),0)", "returns":"[ 0, 1, 2, 3 ]"}]
}
diff --git a/resources/function_help/json/array_remove_all b/resources/function_help/json/array_remove_all
index de1882c0f96..47559bd5e28 100644
--- a/resources/function_help/json/array_remove_all
+++ b/resources/function_help/json/array_remove_all
@@ -4,5 +4,5 @@
"description": "Returns an array with all the entries of the given value removed.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"value","description":"the values to remove"}],
- "examples": [ { "expression":"array_remove_all(array('a','b','c','b'),'b')", "returns":"array: 'a','c'"}]
+ "examples": [ { "expression":"array_remove_all(array('a','b','c','b'),'b')", "returns":"[ 'a', 'c' ]"}]
}
diff --git a/resources/function_help/json/array_remove_at b/resources/function_help/json/array_remove_at
index 191af42c47e..08bcc9046ce 100644
--- a/resources/function_help/json/array_remove_at
+++ b/resources/function_help/json/array_remove_at
@@ -4,5 +4,5 @@
"description": "Returns an array with the given index removed.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"pos","description":"the position to remove (0 based)"}],
- "examples": [ { "expression":"array_remove_at(array(1,2,3),1)", "returns":"array: 1,3"}]
+ "examples": [ { "expression":"array_remove_at(array(1,2,3),1)", "returns":"[ 1, 3 ]"}]
}
diff --git a/resources/function_help/json/array_reverse b/resources/function_help/json/array_reverse
index 06e64dc3186..d84d6c9e83d 100644
--- a/resources/function_help/json/array_reverse
+++ b/resources/function_help/json/array_reverse
@@ -3,5 +3,5 @@
"type": "function",
"description": "Returns the given array with array values in reversed order.",
"arguments": [ {"arg":"array","description":"an array"} ],
- "examples": [ { "expression":"array_reverse(array(2,4,0,10))", "returns":"array: 10,0,4,2"}]
+ "examples": [ { "expression":"array_reverse(array(2,4,0,10))", "returns":"[ 10, 0, 4, 2 ]"}]
}
diff --git a/resources/function_help/json/array_slice b/resources/function_help/json/array_slice
index 6e52117bd94..c527c7bed21 100644
--- a/resources/function_help/json/array_slice
+++ b/resources/function_help/json/array_slice
@@ -17,35 +17,35 @@
],
"examples": [{
"expression": "array_slice(array(1,2,3,4,5),0,3)",
- "returns": "array: 1,2,3,4"
+ "returns": "[ 1, 2, 3, 4 ]"
},
{
"expression": "array_slice(array(1,2,3,4,5),0,-1)",
- "returns": "array: 1,2,3,4,5"
+ "returns": "[ 1, 2, 3, 4, 5 ]"
},
{
"expression": "array_slice(array(1,2,3,4,5),-5,-1)",
- "returns": "array: 1,2,3,4,5"
+ "returns": "[ 1, 2, 3, 4, 5 ]"
},
{
"expression": "array_slice(array(1,2,3,4,5),0,0)",
- "returns": "array: 1"
+ "returns": "[ 1 ]"
},
{
"expression": "array_slice(array(1,2,3,4,5),-2,-1)",
- "returns": "array: 4,5"
+ "returns": "[ 4, 5 ]"
},
{
"expression": "array_slice(array(1,2,3,4,5),-1,-1)",
- "returns": "array: 5"
+ "returns": "[ 5 ]"
},
{
"expression": "array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),1,2)",
- "returns": "array: 'Valmiera','Chugiak'"
+ "returns": "[ 'Valmiera', 'Chugiak' ]"
},
{
"expression": "array_slice(array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),-2,-1)",
- "returns": "array: 'Chugiak','Brighton'"
+ "returns": "[ 'Chugiak', 'Brighton' ]"
}
]
}
diff --git a/resources/function_help/json/generate_series b/resources/function_help/json/generate_series
index e366aadd30c..fc790566fee 100644
--- a/resources/function_help/json/generate_series
+++ b/resources/function_help/json/generate_series
@@ -7,7 +7,7 @@
{"arg":"stop", "description":"value that ends the sequence once reached"},
{"arg":"step","optional":true,"default":"1","description":"value used as the increment between values"}
],
- "examples": [ { "expression":"generate_series('1,5)", "returns":"array: '1', '2', '3', '4', '5'"},
- { "expression":"generate_series('5,1,-1)", "returns":"array: '5', '4', '3', '2', '1'"}
+ "examples": [ { "expression":"generate_series('1,5)", "returns":"[ 1, 2, 3, 4, 5 ]"},
+ { "expression":"generate_series('5,1,-1)", "returns":"[ 5, 4, 3, 2, 1 ]"}
]
}
diff --git a/resources/function_help/json/map b/resources/function_help/json/map
index a3638fce8cc..6691c0945cb 100644
--- a/resources/function_help/json/map
+++ b/resources/function_help/json/map
@@ -10,6 +10,6 @@
{"arg":"value2", "syntaxOnly": true},
{"arg":"key", "descOnly": true, "description":"a key (string)"},
{"arg":"value", "descOnly": true, "description":"a value"}],
- "examples": [ { "expression":"map('1','one','2', 'two')", "returns":"map: 1: 'one', 2: 'two'"}
+ "examples": [ { "expression":"map('1','one','2', 'two')", "returns":"{ '1': 'one', '2': 'two' }"}
]
}
diff --git a/resources/function_help/json/map_akeys b/resources/function_help/json/map_akeys
index b1904a78f3a..d309a0b5fcd 100644
--- a/resources/function_help/json/map_akeys
+++ b/resources/function_help/json/map_akeys
@@ -3,5 +3,5 @@
"type": "function",
"description": "Returns all the keys of a map as an array.",
"arguments": [ {"arg":"map","description":"a map"}],
- "examples": [ { "expression":"map_akeys(map('1','one','2','two'))", "returns":"array: '1', '2'"}]
+ "examples": [ { "expression":"map_akeys(map('1','one','2','two'))", "returns":"[ '1', '2' ]"}]
}
diff --git a/resources/function_help/json/map_avals b/resources/function_help/json/map_avals
index 4ea549a3a10..266c8162405 100644
--- a/resources/function_help/json/map_avals
+++ b/resources/function_help/json/map_avals
@@ -3,5 +3,5 @@
"type": "function",
"description": "Returns all the values of a map as an array.",
"arguments": [ {"arg":"map","description":"a map"}],
- "examples": [ { "expression":"map_avals(map('1','one','2','two'))", "returns":"array: 'one', 'two'"}]
+ "examples": [ { "expression":"map_avals(map('1','one','2','two'))", "returns":"[ 'one', 'two' ]"}]
}
diff --git a/resources/function_help/json/map_concat b/resources/function_help/json/map_concat
index 514e51d643d..bebb5b3ec44 100644
--- a/resources/function_help/json/map_concat
+++ b/resources/function_help/json/map_concat
@@ -7,6 +7,6 @@
{"arg":"map1", "syntaxOnly": true},
{"arg":"map2", "syntaxOnly": true},
{"arg":"map", "descOnly": true, "description":"a map"}],
- "examples": [ { "expression":"map_concat(map('1','one', '2','overridden'),map('2','two', '3','three'))", "returns":"map: 1: 'one, 2: 'two', 3: 'three'"}
+ "examples": [ { "expression":"map_concat(map('1','one', '2','overridden'),map('2','two', '3','three'))", "returns":"{ '1': 'one, '2': 'two', '3': 'three' }"}
]
}
diff --git a/resources/function_help/json/map_delete b/resources/function_help/json/map_delete
index b9a14f00101..719af39b3d9 100644
--- a/resources/function_help/json/map_delete
+++ b/resources/function_help/json/map_delete
@@ -4,5 +4,5 @@
"description": "Returns a map with the given key and its corresponding value deleted.",
"arguments": [ {"arg":"map","description":"a map"},
{"arg":"key","description":"the key to delete"}],
- "examples": [ { "expression":"map_delete(map('1','one','2','two'),'2')", "returns":"map: 1: 'one'"}]
+ "examples": [ { "expression":"map_delete(map('1','one','2','two'),'2')", "returns":"{ '1': 'one' }"}]
}
diff --git a/resources/function_help/json/map_insert b/resources/function_help/json/map_insert
index 0d1fc47f9d1..235558dcf8d 100644
--- a/resources/function_help/json/map_insert
+++ b/resources/function_help/json/map_insert
@@ -5,5 +5,5 @@
"arguments": [ {"arg":"map","description":"a map"},
{"arg":"key","description":"the key to add"},
{"arg":"value","description":"the value to add"}],
- "examples": [ { "expression":"map_insert(map('1','one'),'3','three')", "returns":"map: 1: 'one', 3: 'three'"}]
+ "examples": [ { "expression":"map_insert(map('1','one'),'3','three')", "returns":"{ '1': 'one', '3': 'three' }"}]
}
diff --git a/resources/function_help/json/regexp_matches b/resources/function_help/json/regexp_matches
index 68f914564d0..ab223f8469b 100644
--- a/resources/function_help/json/regexp_matches
+++ b/resources/function_help/json/regexp_matches
@@ -6,7 +6,7 @@
{"arg":"string", "description":"the string to capture groups from against the regular expression"},
{"arg":"regex","description":"the regular expression used to capture groups"},
{"arg":"empty_value","optional":true,"default":"''","description":"the optional string to use as replacement for empty (zero length) matches"}],
- "examples": [ { "expression":"regexp_matches('QGIS=>rocks','(.*)=>(.*)')", "returns":"array: 'QGIS', 'rocks'"},
- { "expression":"regexp_matches('key=>','(.*)=>(.*)','empty value')", "returns":"array: 'key', 'empty value'"}
+ "examples": [ { "expression":"regexp_matches('QGIS=>rocks','(.*)=>(.*)')", "returns":"[ 'QGIS', 'rocks' ]"},
+ { "expression":"regexp_matches('key=>','(.*)=>(.*)','empty value')", "returns":"[ 'key', 'empty value' ]"}
]
}
diff --git a/resources/function_help/json/string_to_array b/resources/function_help/json/string_to_array
index 31e0ffbc9ab..df89d15f4b5 100644
--- a/resources/function_help/json/string_to_array
+++ b/resources/function_help/json/string_to_array
@@ -6,7 +6,7 @@
{"arg":"string", "description":"the input string"},
{"arg":"delimiter","optional":true,"default":"','","description":"the string delimiter used to split the input string"},
{"arg":"empty_value","optional":true,"default":"''","description":"the optional string to use as replacement for empty (zero length) matches"}],
- "examples": [ { "expression":"string_to_array('1,2,3',',')", "returns":"array: '1', '2', '3'"},
- { "expression":"string_to_array('1,,3',',','0')", "returns":"array: '1', '0', '3'"}
+ "examples": [ { "expression":"string_to_array('1,2,3',',')", "returns":"[ '1', '2', '3' ]"},
+ { "expression":"string_to_array('1,,3',',','0')", "returns":"[ '1', '0', '3' ]"}
]
}
diff --git a/src/core/expression/qgsexpression.cpp b/src/core/expression/qgsexpression.cpp
index c6e6575fab6..c27cc23488a 100644
--- a/src/core/expression/qgsexpression.cpp
+++ b/src/core/expression/qgsexpression.cpp
@@ -903,35 +903,50 @@ 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( it.key() ).append( ": " ).append( formatPreviewString( it.value() ) );
- if ( mapStr.length() > MAX_PREVIEW + 3 )
+ mapStr.append( separator );
+ if ( separator.isEmpty() )
+ separator = QStringLiteral( "," );
+
+ mapStr.append( QStringLiteral( " '%1': %2" ).arg( it.key(), formatPreviewString( it.value() ) ) );
+ if ( mapStr.length() > MAX_PREVIEW - 3 )
{
- mapStr = QString( tr( "%1…" ) ).arg( mapStr.left( MAX_PREVIEW ) );
+ mapStr = tr( "%1…" ).arg( mapStr.left( MAX_PREVIEW - 2 ) );
break;
}
}
- return tr( "<map: %1>" ).arg( mapStr );
+ if ( !map.empty() )
+ mapStr += QStringLiteral( " " );
+ mapStr += QStringLiteral( "}" );
+ return 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( " " );
+ listStr.append( formatPreviewString( arrayValue ) );
+ 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;
}
}
- return tr( "<array: %1>" ).arg( listStr );
+ if ( !list.empty() )
+ listStr += QStringLiteral( " " );
+ listStr += QStringLiteral( "]" );
+ return listStr;
}
else
{
diff --git a/src/gui/qgsexpressionbuilderwidget.cpp b/src/gui/qgsexpressionbuilderwidget.cpp
index 2f918e6ad74..a2d5601bd4e 100644
--- a/src/gui/qgsexpressionbuilderwidget.cpp
+++ b/src/gui/qgsexpressionbuilderwidget.cpp
@@ -279,7 +279,7 @@ void QgsExpressionBuilderWidget::btnNewFile_pressed()
bool ok;
QString text = QInputDialog::getText( this, tr( "Enter new file name" ),
tr( "File name:" ), QLineEdit::Normal,
- QLatin1String( "" ), &ok );
+ QString(), &ok );
if ( ok && !text.isEmpty() )
{
newFunctionFile( text );
@@ -348,7 +348,7 @@ void QgsExpressionBuilderWidget::loadFieldNames( const QgsFields &fields )
{
QString fieldName = fields.at( i ).name();
fieldNames << fieldName;
- registerItem( QStringLiteral( "Fields and Values" ), fieldName, " \"" + fieldName + "\" ", QLatin1String( "" ), QgsExpressionItem::Field, false, i );
+ registerItem( QStringLiteral( "Fields and Values" ), fieldName, " \"" + fieldName + "\" ", QString(), QgsExpressionItem::Field, false, i );
}
// highlighter->addFields( fieldNames );
}
@@ -426,7 +426,7 @@ void QgsExpressionBuilderWidget::registerItem( const QString &group,
else
{
// If the group doesn't exist yet we make it first.
- QgsExpressionItem *newgroupNode = new QgsExpressionItem( QgsExpression::group( group ), QLatin1String( "" ), QgsExpressionItem::Header );
+ QgsExpressionItem *newgroupNode = new QgsExpressionItem( QgsExpression::group( group ), QString(), QgsExpressionItem::Header );
newgroupNode->setData( group, Qt::UserRole );
//Recent group should always be last group
newgroupNode->setData( group.startsWith( QLatin1String( "Recent (" ) ) ? 2 : 1, QgsExpressionItem::CUSTOM_SORT_ROLE );
@@ -628,9 +628,9 @@ void QgsExpressionBuilderWidget::txtExpressionString_textChanged()
if ( text.isEmpty() )
{
lblPreview->clear();
- lblPreview->setStyleSheet( QLatin1String( "" ) );
- txtExpressionString->setToolTip( QLatin1String( "" ) );
- lblPreview->setToolTip( QLatin1String( "" ) );
+ lblPreview->setStyleSheet( QString() );
+ txtExpressionString->setToolTip( QString() );
+ lblPreview->setToolTip( QString() );
emit expressionParsed( false );
setParserError( true );
setEvalError( true );
@@ -1064,7 +1064,7 @@ QString QgsExpressionBuilderWidget::helpStylesheet() const
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem *expressionItem )
{
if ( !expressionItem )
- return QLatin1String( "" );
+ return QString();
QString helpContents = expressionItem->getHelpText();
diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp
index 31de43dd430..53be6d510a0 100644
--- a/tests/src/core/testqgsexpression.cpp
+++ b/tests/src/core/testqgsexpression.cpp
@@ -3114,24 +3114,24 @@ class TestQgsExpression: public QObject
void test_formatPreviewString()
{
- QCOMPARE( QgsExpression::formatPreviewString( QVariant( "hello" ) ), QString( "'hello'" ) );
- QCOMPARE( QgsExpression::formatPreviewString( QVariant( QVariantMap() ) ), QString( "<map: >" ) );
+ QCOMPARE( QgsExpression::formatPreviewString( QVariant( "hello" ) ), QStringLiteral( "'hello'" ) );
+ QCOMPARE( QgsExpression::formatPreviewString( QVariant( QVariantMap() ) ), QStringLiteral( "{}" ) );
QVariantMap map;
map[QStringLiteral( "1" )] = "One";
map[QStringLiteral( "2" )] = "Two";
- QCOMPARE( QgsExpression::formatPreviewString( QVariant( map ) ), QString( "<map: 1: 'One', 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 ) ), QString( "<map: 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… }" ) );
QVariantList list;
list << 1 << 2 << 3;
- QCOMPARE( QgsExpression::formatPreviewString( QVariant( list ) ), QString( "<array: 1, 2, 3>" ) );
+ QCOMPARE( QgsExpression::formatPreviewString( QVariant( list ) ), QStringLiteral( "[ 1, 2, 3 ]" ) );
QStringList stringList;
stringList << QStringLiteral( "One" ) << QStringLiteral( "Two" ) << QStringLiteral( "A very long string that is going to be truncated" );
QCOMPARE( QgsExpression::formatPreviewString( QVariant( stringList ) ),
- QString( "<array: 'One', 'Two', 'A very long string that is going to be trunca…>" ) );
+ QStringLiteral( "[ 'One', 'Two', 'A very long string that is going to be tr… ]" ) );
}
};