Skip to content
Permalink
Browse files

[processing] Formalise object design for ContextAction, allow icons t…

…o be set
  • Loading branch information
nyalldawson committed Feb 1, 2019
1 parent 9b2e601 commit f77cf4fae45517c954e2275f004eadb1fb1f405d
@@ -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
@@ -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
@@ -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)

@@ -38,6 +38,7 @@
class DeleteModelAction(ContextAction):

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

def isEnabled(self):
@@ -36,6 +36,7 @@
class EditModelAction(ContextAction):

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

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

from processing.core.ProcessingConfig import ProcessingConfig, Setting

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

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

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

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

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

def isEnabled(self):
@@ -40,6 +40,7 @@
class DeleteScriptAction(ContextAction):

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

def isEnabled(self):
@@ -41,6 +41,7 @@
class EditScriptAction(ContextAction):

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

def isEnabled(self):

0 comments on commit f77cf4f

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