Skip to content
Permalink
Browse files

Move groups from QGIS (and QGIS native) provider to top level items

in processing toolbox

Helps aid in user discoverability of these algorithms, and
indicates to users that these should generally be the
preferred algorithm choices if duplicates exist from other
providers.
  • Loading branch information
nyalldawson committed Jun 24, 2017
1 parent 6efa765 commit 8f586ef020f6dca2826a01a43080d192fde66ce4
@@ -348,16 +348,91 @@ def fillTreeUsingProviders(self):
self.disabledProviderItems = {}
disabled = []
for provider in QgsApplication.processingRegistry().providers():
if provider.isActive():
providerItem = TreeProviderItem(provider, self.algorithmTree, self)
if provider.id() in ('qgis', 'native'):
self.addAlgorithmsFromProvider(provider, self.algorithmTree.invisibleRootItem())
else:
disabled.append(provider)
if provider.isActive():
providerItem = TreeProviderItem(provider, self.algorithmTree, self)
else:
disabled.append(provider)
self.algorithmTree.sortItems(0, Qt.AscendingOrder)
for provider in disabled:
providerItem = TreeProviderItem(provider, self.algorithmTree, self)
providerItem.setHidden(True)
self.disabledProviderItems[provider.id()] = providerItem

def addAlgorithmsFromProvider(self, provider, parent):
groups = {}
count = 0
algs = provider.algorithms()
active = provider.isActive()

# Add algorithms
for alg in algs:
if alg.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox:
continue
groupItem = None
if alg.group() in groups:
groupItem = groups[alg.group()]
else:
# check if group already exists
for i in range(parent.childCount()):
if parent.child(i).text(0) == alg.group():
groupItem = parent.child(i)
groups[alg.group()] = groupItem
break

if not groupItem:
groupItem = QTreeWidgetItem()
name = alg.group()
if not active:
groupItem.setForeground(0, Qt.darkGray)
groupItem.setText(0, name)
groupItem.setToolTip(0, name)
if provider.id() in ('qgis', 'native'):
groupItem.setIcon(0, provider.icon())
groups[alg.group()] = groupItem
algItem = TreeAlgorithmItem(alg)
if not active:
algItem.setForeground(0, Qt.darkGray)
groupItem.addChild(algItem)
count += 1

if provider.id() in ProviderActions.actions:
actions = ProviderActions.actions[provider.id()]
for action in actions:
if action.group in groups:
groupItem = groups[action.group]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0, action.group)
groups[action.group] = groupItem
algItem = TreeActionItem(action)
groupItem.addChild(algItem)

text = provider.name()

if not provider.id() in ('qgis', 'native'):
if not active:
def activateProvider():
self.activateProvider(provider.id())

label = QLabel(text + "&nbsp;&nbsp;&nbsp;&nbsp;<a href='%s'>Activate</a>")
label.setStyleSheet("QLabel {background-color: white; color: grey;}")
label.linkActivated.connect(activateProvider)
self.algorithmTree.setItemWidget(item, 0, label)

else:
text += QCoreApplication.translate("TreeProviderItem", " [{0} geoalgorithms]").format(count)
parent.setText(0, text)
parent.setToolTip(0, parent.text(0))

for groupItem in list(groups.values()):
parent.addChild(groupItem)

if not provider.id() in ('qgis', 'native'):
parent.setHidden(parent.childCount() == 0)


class TreeAlgorithmItem(QTreeWidgetItem):

@@ -400,58 +475,4 @@ def refresh(self):
self.populate()

def populate(self):
groups = {}
count = 0
algs = self.provider.algorithms()
active = self.provider.isActive()

# Add algorithms
for alg in algs:
if alg.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox:
continue
if alg.group() in groups:
groupItem = groups[alg.group()]
else:
groupItem = QTreeWidgetItem()
name = alg.group()
if not active:
groupItem.setForeground(0, Qt.darkGray)
groupItem.setText(0, name)
groupItem.setToolTip(0, name)
groups[alg.group()] = groupItem
algItem = TreeAlgorithmItem(alg)
if not active:
algItem.setForeground(0, Qt.darkGray)
groupItem.addChild(algItem)
count += 1

if self.provider.id() in ProviderActions.actions:
actions = ProviderActions.actions[self.provider.id()]
for action in actions:
if action.group in groups:
groupItem = groups[action.group]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0, action.group)
groups[action.group] = groupItem
algItem = TreeActionItem(action)
groupItem.addChild(algItem)

text = self.provider.name()

if not active:
def activateProvider():
self.toolbox.activateProvider(self.provider.id())
label = QLabel(text + "&nbsp;&nbsp;&nbsp;&nbsp;<a href='%s'>Activate</a>")
label.setStyleSheet("QLabel {background-color: white; color: grey;}")
label.linkActivated.connect(activateProvider)
self.tree.setItemWidget(self, 0, label)

else:
text += QCoreApplication.translate("TreeProviderItem", " [{0} geoalgorithms]").format(count)
self.setText(0, text)
self.setToolTip(0, self.text(0))
for groupItem in list(groups.values()):
self.addChild(groupItem)

self.setHidden(self.childCount() == 0)
self.toolbox.addAlgorithmsFromProvider(self.provider, self)
@@ -598,6 +598,7 @@ def fillAlgorithmTreeUsingProviders(self):
self.algorithmTree.clear()
text = str(self.searchBox.text())
search_strings = text.split(' ')
qgis_groups = {}
for provider in QgsApplication.processingRegistry().providers():
if not provider.isActive():
continue
@@ -620,12 +621,18 @@ def fillAlgorithmTreeUsingProviders(self):
if show:
if alg.group() in groups:
groupItem = groups[alg.group()]
elif provider.id() in ('qgis', 'native') and alg.group() in qgis_groups:
groupItem = qgis_groups[alg.group()]
else:
groupItem = QTreeWidgetItem()
name = alg.group()
groupItem.setText(0, name)
groupItem.setToolTip(0, name)
groups[alg.group()] = groupItem
if provider.id() in ('qgis', 'native'):
groupItem.setIcon(0, provider.icon())
qgis_groups[alg.group()] = groupItem
else:
groups[alg.group()] = groupItem
algItem = TreeAlgorithmItem(alg)
groupItem.addChild(algItem)

@@ -642,6 +649,13 @@ def fillAlgorithmTreeUsingProviders(self):
if text != '':
groupItem.setExpanded(True)

if len(qgis_groups) > 0:
for groupItem in list(qgis_groups.values()):
self.algorithmTree.addTopLevelItem(groupItem)
for groupItem in list(qgis_groups.values()):
if text != '':
groupItem.setExpanded(True)

self.algorithmTree.sortItems(0, Qt.AscendingOrder)


1 comment on commit 8f586ef

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn commented on 8f586ef Jun 24, 2017

Good move

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