Skip to content

Commit

Permalink
[processing] Formalise object design for ContextAction, allow icons t…
Browse files Browse the repository at this point in the history
…o be set
  • Loading branch information
nyalldawson committed Feb 1, 2019
1 parent 9b2e601 commit f77cf4f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions python/plugins/processing/gui/ContextAction.py
Expand Up @@ -27,10 +27,15 @@


from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtGui import QIcon


class ContextAction:

def __init__(self):
self.name = None
self.is_separator = False

def setData(self, itemData, toolbox):
self.itemData = itemData
self.toolbox = toolbox
Expand All @@ -39,3 +44,12 @@ def tr(self, string, context=''):
if context == '':
context = self.__class__.__name__
return QCoreApplication.translate(context, string)

def icon(self):
return QIcon()

def isEnabled(self):
return True

def execute(self):
pass
5 changes: 4 additions & 1 deletion python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -192,9 +192,12 @@ def showPopupMenu(self, point):
popupmenu.addSeparator()
for action in actions:
action.setData(alg, self)
if action.isEnabled():
if action.is_separator:
popupmenu.addSeparator()
elif action.isEnabled():
contextMenuAction = QAction(action.name,
popupmenu)
contextMenuAction.setIcon(action.icon())
contextMenuAction.triggered.connect(action.execute)
popupmenu.addAction(contextMenuAction)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/modeler/DeleteModelAction.py
Expand Up @@ -38,6 +38,7 @@
class DeleteModelAction(ContextAction):

def __init__(self):
super().__init__()
self.name = QCoreApplication.translate('DeleteModelAction', 'Delete Model…')

def isEnabled(self):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/modeler/EditModelAction.py
Expand Up @@ -36,6 +36,7 @@
class EditModelAction(ContextAction):

def __init__(self):
super().__init__()
self.name = QCoreApplication.translate('EditModelAction', 'Edit Model…')

def isEnabled(self):
Expand Down
Expand Up @@ -39,6 +39,7 @@

from processing.core.ProcessingConfig import ProcessingConfig, Setting

from processing.gui.ContextAction import ContextAction
from processing.gui.ProviderActions import (ProviderActions,
ProviderContextMenuActions)

Expand Down
Expand Up @@ -36,6 +36,7 @@
class DeletePreconfiguredAlgorithmAction(ContextAction):

def __init__(self):
super().__init__()
self.name = QCoreApplication.translate('DeletePreconfiguredAlgorithmAction', 'Delete Preconfigured Algorithm…')

def isEnabled(self):
Expand Down
Expand Up @@ -36,6 +36,7 @@
class NewPreconfiguredAlgorithmAction(ContextAction):

def __init__(self):
super().__init__()
self.name = QCoreApplication.translate('NewPreconfiguredAlgorithmAction', 'Create Preconfigured Algorithm…')

def isEnabled(self):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/script/DeleteScriptAction.py
Expand Up @@ -40,6 +40,7 @@
class DeleteScriptAction(ContextAction):

def __init__(self):
super().__init__()
self.name = QCoreApplication.translate("DeleteScriptAction", "Delete Script…")

def isEnabled(self):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/script/EditScriptAction.py
Expand Up @@ -41,6 +41,7 @@
class EditScriptAction(ContextAction):

def __init__(self):
super().__init__()
self.name = QCoreApplication.translate("EditScriptAction", "Edit Script…")

def isEnabled(self):
Expand Down

0 comments on commit f77cf4f

Please sign in to comment.