Skip to content

Commit f77cf4f

Browse files
committed
[processing] Formalise object design for ContextAction, allow icons to be set
1 parent 9b2e601 commit f77cf4f

9 files changed

+25
-1
lines changed

python/plugins/processing/gui/ContextAction.py

+14
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@
2727

2828

2929
from qgis.PyQt.QtCore import QCoreApplication
30+
from qgis.PyQt.QtGui import QIcon
3031

3132

3233
class ContextAction:
3334

35+
def __init__(self):
36+
self.name = None
37+
self.is_separator = False
38+
3439
def setData(self, itemData, toolbox):
3540
self.itemData = itemData
3641
self.toolbox = toolbox
@@ -39,3 +44,12 @@ def tr(self, string, context=''):
3944
if context == '':
4045
context = self.__class__.__name__
4146
return QCoreApplication.translate(context, string)
47+
48+
def icon(self):
49+
return QIcon()
50+
51+
def isEnabled(self):
52+
return True
53+
54+
def execute(self):
55+
pass

python/plugins/processing/gui/ProcessingToolbox.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,12 @@ def showPopupMenu(self, point):
192192
popupmenu.addSeparator()
193193
for action in actions:
194194
action.setData(alg, self)
195-
if action.isEnabled():
195+
if action.is_separator:
196+
popupmenu.addSeparator()
197+
elif action.isEnabled():
196198
contextMenuAction = QAction(action.name,
197199
popupmenu)
200+
contextMenuAction.setIcon(action.icon())
198201
contextMenuAction.triggered.connect(action.execute)
199202
popupmenu.addAction(contextMenuAction)
200203

python/plugins/processing/modeler/DeleteModelAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
class DeleteModelAction(ContextAction):
3939

4040
def __init__(self):
41+
super().__init__()
4142
self.name = QCoreApplication.translate('DeleteModelAction', 'Delete Model…')
4243

4344
def isEnabled(self):

python/plugins/processing/modeler/EditModelAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
class EditModelAction(ContextAction):
3737

3838
def __init__(self):
39+
super().__init__()
3940
self.name = QCoreApplication.translate('EditModelAction', 'Edit Model…')
4041

4142
def isEnabled(self):

python/plugins/processing/modeler/ModelerAlgorithmProvider.py

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
from processing.core.ProcessingConfig import ProcessingConfig, Setting
4141

42+
from processing.gui.ContextAction import ContextAction
4243
from processing.gui.ProviderActions import (ProviderActions,
4344
ProviderContextMenuActions)
4445

python/plugins/processing/preconfigured/DeletePreconfiguredAlgorithmAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
class DeletePreconfiguredAlgorithmAction(ContextAction):
3737

3838
def __init__(self):
39+
super().__init__()
3940
self.name = QCoreApplication.translate('DeletePreconfiguredAlgorithmAction', 'Delete Preconfigured Algorithm…')
4041

4142
def isEnabled(self):

python/plugins/processing/preconfigured/NewPreconfiguredAlgorithmAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
class NewPreconfiguredAlgorithmAction(ContextAction):
3737

3838
def __init__(self):
39+
super().__init__()
3940
self.name = QCoreApplication.translate('NewPreconfiguredAlgorithmAction', 'Create Preconfigured Algorithm…')
4041

4142
def isEnabled(self):

python/plugins/processing/script/DeleteScriptAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
class DeleteScriptAction(ContextAction):
4141

4242
def __init__(self):
43+
super().__init__()
4344
self.name = QCoreApplication.translate("DeleteScriptAction", "Delete Script…")
4445

4546
def isEnabled(self):

python/plugins/processing/script/EditScriptAction.py

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
class EditScriptAction(ContextAction):
4242

4343
def __init__(self):
44+
super().__init__()
4445
self.name = QCoreApplication.translate("EditScriptAction", "Edit Script…")
4546

4647
def isEnabled(self):

0 commit comments

Comments
 (0)