Skip to content

Commit

Permalink
[processing] Allow algorithms to specify tags
Browse files Browse the repository at this point in the history
Tags are used while searching in the toolbox. This should help with
finding algorithms when the exact name is not known, eg
you could search for "envelope" or "bounds" and find the
'Polygon from Layer Extent' algorithm.

At the moment it's quite hard to discover algorithms which exist
when you don't know what their called and have to instead search
for every possible naming variant which could exist...
  • Loading branch information
nyalldawson committed Nov 8, 2016
1 parent 1a4f8f5 commit 3550cc9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions python/plugins/processing/algs/qgis/ExtentFromLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def getIcon(self):
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Polygon from layer extent')
self.group, self.i18n_group = self.trAlgorithm('Vector general tools')
self.tags = self.tr('extent,envelope,bounds,bounding,boundary,layer')

self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Input layer')))
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/qgis/MergeLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def getIcon(self):
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Merge lines')
self.group, self.i18n_group = self.trAlgorithm('Vector geometry tools')
self.tags = self.tr('line,merge,join,parts')

self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE]))
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/core/GeoAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def __init__(self):
self.name, self.i18n_name = '', ''
self.group, self.i18n_group = '', ''

# Tags
self.tags = ''

# The crs taken from input layers (if possible), and used when
# loading output layers
self.crs = None
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/gui/ProcessingToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def _filterItem(self, item, text):
item_text = [item.text(0).lower(), item.data(0, Qt.UserRole).lower()]
if isinstance(item, TreeAlgorithmItem):
item_text.append(item.alg.commandLineName())
item_text.extend(item.data(0, Qt.UserRole + 1))

hide = bool(text) and not all(
any(part in t for t in item_text)
Expand Down Expand Up @@ -355,6 +356,7 @@ def __init__(self, alg):
self.setToolTip(0, name)
self.setText(0, name)
self.setData(0, Qt.UserRole, nameEn)
self.setData(0, Qt.UserRole + 1, alg.tags.split(','))


class TreeActionItem(QTreeWidgetItem):
Expand Down
11 changes: 10 additions & 1 deletion python/plugins/processing/modeler/ModelerDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def fillAlgorithmTree(self):
def fillAlgorithmTreeUsingProviders(self):
self.algorithmTree.clear()
text = str(self.searchBox.text())
search_strings = text.split(' ')
allAlgs = algList.algs
for providerName in list(allAlgs.keys()):
name = 'ACTIVATE_' + providerName.upper().replace(' ', '_')
Expand All @@ -486,7 +487,15 @@ def fillAlgorithmTreeUsingProviders(self):
continue
if alg.commandLineName() == self.alg.commandLineName():
continue
if text == '' or text.lower() in alg.name.lower():

item_text = [alg.name.lower()]
item_text.extend(alg.tags.split(','))

show = not search_strings or all(
any(part in t for t in item_text)
for part in search_strings)

if show:
if alg.group in groups:
groupItem = groups[alg.group]
else:
Expand Down

0 comments on commit 3550cc9

Please sign in to comment.