Skip to content

Commit

Permalink
Merge pull request #3500 from pvalsecc/array_exprs
Browse files Browse the repository at this point in the history
Add expression functions for arrays and maps
  • Loading branch information
nyalldawson authored Sep 20, 2016
2 parents 49e76a8 + 758bc72 commit 03923eb
Show file tree
Hide file tree
Showing 24 changed files with 564 additions and 55 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ scripts/astyle.exe
scripts/Debug
scripts/qgisstyle*
scripts/RelWithDebInfo
src/core/qgscontexthelp_texts.cpp
src/core/qgsexpression_texts.cpp
tests/testdata/cache/
tests/testdata/checker360by180.asc.aux.xml
tests/testdata/grass/wgs84/test/.gislock
Expand Down
12 changes: 12 additions & 0 deletions resources/function_help/json/array
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "array",
"type": "function",
"description": "Returns an array containing all the values passed as parameter.",
"variableLenArguments": true,
"arguments": [
{"arg":"value1", "syntaxOnly": true},
{"arg":"value2", "syntaxOnly": true},
{"arg":"value", "descOnly": true, "description":"a value"}],
"examples": [ { "expression":"array(2,10)", "returns":"array: 2, 10"}
]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_append
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_append",
"type": "function",
"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"}]
}
12 changes: 12 additions & 0 deletions resources/function_help/json/array_cat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "array_cat",
"type": "function",
"description": "Returns an array containing all the given arrays concatenated.",
"variableLenArguments": true,
"arguments": [
{"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"}
]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_contains
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_contains",
"type": "function",
"description": "Returns true if an array contains the given value.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"value","description":"the value to search"}],
"examples": [ { "expression":"array_contains(array(1,2,3),2)", "returns":"true"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_find
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_find",
"type": "function",
"description": "Returns the index (0 for the first one) of a value within an array. Returns -1 if the value is not found.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"value","description":"the value to search"}],
"examples": [ { "expression":"array_find(array(1,2,3),2)", "returns":"1"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_get
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_get",
"type": "function",
"description": "Returns the Nth value (0 for the first one) of an array.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"index","description":"the index to get (0 based)"}],
"examples": [ { "expression":"array_get(array('a','b','c'),1)", "returns":"'b'"}]
}
9 changes: 9 additions & 0 deletions resources/function_help/json/array_insert
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "array_insert",
"type": "function",
"description": "Returns an array with the given value added at the given position.",
"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"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_intersect
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_intersect",
"type": "function",
"description": "Returns true if any element of array1 exists in array2.",
"arguments": [ {"arg":"array1","description":"an array"},
{"arg":"array2","description":"an other array"}],
"examples": [ { "expression":"array_intersect(array(1,2,3,4),array(4,0,2,5))", "returns":"true"}]
}
7 changes: 7 additions & 0 deletions resources/function_help/json/array_length
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "array_length",
"type": "function",
"description": "Returns the number of elements of an array.",
"arguments": [ {"arg":"array","description":"an array"}],
"examples": [ { "expression":"array_length(array(1,2,3))", "returns":"3"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_prepend
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_prepend",
"type": "function",
"description": "Returns an array with the given value added at the begining.",
"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"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_remove_all
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_remove_all",
"type": "function",
"description": "Returns an array with all the entries of the given value removed.",
"arguments": [ {"arg":"array","description":"an array"},
{"arg":"value","description":"the value to add"}],
"examples": [ { "expression":"array_remove_all(array('a','b','c','b'),'b')", "returns":"array: 'a','c'"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/array_remove_at
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "array_remove_at",
"type": "function",
"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"}]
}
15 changes: 15 additions & 0 deletions resources/function_help/json/map
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "map",
"type": "function",
"description": "Returns a map containing all the keys and values passed as pair of parameters.",
"variableLenArguments": true,
"arguments": [
{"arg":"key1", "syntaxOnly": true},
{"arg":"value1", "syntaxOnly": true},
{"arg":"key2", "syntaxOnly": true},
{"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'"}
]
}
7 changes: 7 additions & 0 deletions resources/function_help/json/map_akeys
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "map_akeys",
"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'"}]
}
7 changes: 7 additions & 0 deletions resources/function_help/json/map_avals
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "map_avals",
"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'"}]
}
12 changes: 12 additions & 0 deletions resources/function_help/json/map_concat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "map_concat",
"type": "function",
"description": "Returns a map containing all the entries of the given map. If two maps contain the same key, the value of the second map is taken.",
"variableLenArguments": true,
"arguments": [
{"arg":"map1", "syntaxOnly": true},
{"arg":"map2", "syntaxOnly": true},
{"arg":"map", "descOnly": true, "description":"a map"}],
"examples": [ { "expression":"map_concat(map('1','one', '2','overriden'),map('2','two', '3','three'))", "returns":"map: 1: 'one, 2: 'two', 3: 'three'"}
]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/map_delete
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "map_delete",
"type": "function",
"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'"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/map_exist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "map_exist",
"type": "function",
"description": "Returns true if the given key exists in the map.",
"arguments": [ {"arg":"map","description":"a map"},
{"arg":"key","description":"the key to lookup"}],
"examples": [ { "expression":"map_exist(map('1','one','2','two'),'3')", "returns":"false"}]
}
8 changes: 8 additions & 0 deletions resources/function_help/json/map_get
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "map_get",
"type": "function",
"description": "Returns the value of a map, given it's key.",
"arguments": [ {"arg":"map","description":"a map"},
{"arg":"key","description":"the key to lookup"}],
"examples": [ { "expression":"map_get(map('1','one','2','two'),'2')", "returns":"'two'"}]
}
9 changes: 9 additions & 0 deletions resources/function_help/json/map_insert
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "map_insert",
"type": "function",
"description": "Returns a map with an added key/value.",
"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'"}]
}
Loading

0 comments on commit 03923eb

Please sign in to comment.