Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[needs-docs][processing] move providers actions into the processing
panel toolbar (#6150)
  • Loading branch information
nirvn committed Jan 24, 2018
1 parent 5dc8c3f commit c5d9830
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
1 change: 0 additions & 1 deletion python/plugins/processing/ProcessingPlugin.py
Expand Up @@ -206,7 +206,6 @@ def initGui(self):
self.modelerAction.triggered.connect(self.openModeler)
self.iface.registerMainWindowAction(self.modelerAction, 'Ctrl+Alt+M')
self.menu.addAction(self.modelerAction)
self.toolbox.processingToolbar.addAction(self.modelerAction)

self.historyAction = QAction(
QIcon(os.path.join(cmd_folder, 'images', 'history.svg')),
Expand Down
45 changes: 15 additions & 30 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -30,7 +30,7 @@

from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QCoreApplication
from qgis.PyQt.QtWidgets import QMenu, QAction, QTreeWidgetItem, QLabel, QMessageBox
from qgis.PyQt.QtWidgets import QToolButton, QToolBar, QMenu, QAction, QTreeWidgetItem, QLabel, QMessageBox
from qgis.utils import iface
from qgis.core import (QgsApplication,
QgsProcessingAlgorithm)
Expand Down Expand Up @@ -149,12 +149,11 @@ def _filterItem(self, item, text):
show = (showChild or show) and item not in list(self.disabledProviderItems.values())
item.setHidden(not show)
return show
elif isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
elif isinstance(item, TreeAlgorithmItem):
# hide if every part of text is not contained somewhere in either the item text or item user role
item_text = [item.text(0).lower(), item.data(0, ProcessingToolbox.NAME_ROLE).lower()]
if isinstance(item, TreeAlgorithmItem):
item_text.append(item.alg.id())
item_text.extend(item.data(0, ProcessingToolbox.TAG_ROLE))
item_text.append(item.alg.id())
item_text.extend(item.data(0, ProcessingToolbox.TAG_ROLE))

hide = bool(text) and not all(
any(part in t for t in item_text)
Expand Down Expand Up @@ -227,14 +226,11 @@ def showPopupMenu(self, point):
editRenderingStylesAction.triggered.connect(
self.editRenderingStyles)
popupmenu.addAction(editRenderingStylesAction)

if isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
data = item.alg if isinstance(item, TreeAlgorithmItem) else item.action
actions = ProviderContextMenuActions.actions
if len(actions) > 0:
popupmenu.addSeparator()
for action in actions:
action.setData(data, self)
action.setData(item.alg, self)
if action.isEnabled():
contextMenuAction = QAction(action.name,
self.algorithmTree)
Expand Down Expand Up @@ -303,10 +299,6 @@ def executeAlgorithm(self):
ret, results = execute(alg, parameters, context, feedback)
handleAlgorithmResults(alg, context, feedback)
feedback.close()
if isinstance(item, TreeActionItem):
action = item.action
action.setData(self)
action.execute()

def fillTree(self):
self.fillTreeUsingProviders()
Expand Down Expand Up @@ -426,14 +418,17 @@ def addAlgorithmsFromProvider(self, provider, parent):

if provider.id() in ProviderActions.actions:
actions = ProviderActions.actions[provider.id()]
toolbarButton = QToolButton()
toolbarButton.setIcon(provider.icon())
toolbarButton.setToolTip(provider.name())
toolbarButton.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(provider.name(), self)
for action in actions:
if action.group in groups:
groupItem = groups[action.group]
else:
groupItem = TreeGroupItem(action.group)
groups[action.group] = groupItem
algItem = TreeActionItem(action)
groupItem.addChild(algItem)
act = QAction(action.name, menu)
act.triggered.connect(action.execute)
menu.addAction(act)
toolbarButton.setMenu(menu)
self.processingToolbar.addWidget(toolbarButton)

text = provider.name()

Expand Down Expand Up @@ -492,16 +487,6 @@ def setInactive(self):
self.setForeground(0, Qt.darkGray)


class TreeActionItem(QTreeWidgetItem):

def __init__(self, action):
QTreeWidgetItem.__init__(self)
self.action = action
self.setText(0, action.i18n_name)
self.setIcon(0, action.getIcon())
self.setData(0, ProcessingToolbox.NAME_ROLE, action.name)


class TreeProviderItem(QTreeWidgetItem):

def __init__(self, provider, tree, toolbox):
Expand Down

0 comments on commit c5d9830

Please sign in to comment.