Skip to content

Commit cccb1d3

Browse files
pmav99nyalldawson
authored andcommitted
Make setting "Grass7AlgorithProvider.activateSetting" optional.
This change makes it easier to subclass `Grass7AlgorithProvider` which allows e.g. to expose GRASS Addons as QGIS plugins. Disclaimer: `Grass7AlgorithProvider` is a private API and it may change without warning. 3rd parties that rely on this should expect that their code will break in future releases. For more info please check the comments at #30252 Nevertheless, it currently is possible to subclass with something like this: class CustomGrassBasedProvider(Grass7AlgorithmProvider): # Set descriptionFolder to our own description directory descriptionFolder = os.path.join(os.path.dirname(__file__), 'description') # 3rd party plugins don't need an activation/deactivation setting activateSetting = None # define the rest of the methods that are needed (e.g. name(), id() etc) # ... Fixes #30241 Continues #9202
1 parent cdef051 commit cccb1d3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@
4040

4141
class Grass7AlgorithmProvider(QgsProcessingProvider):
4242

43-
# Subclasses of `Grass7AlgorithmProvider` should override `descriptionFolder`
44-
# and set its value to their own description folder.
4543
descriptionFolder = Grass7Utils.grassDescriptionPath()
46-
4744
activateSetting = "ACTIVATE_GRASS7"
4845

4946
def __init__(self):
@@ -52,8 +49,9 @@ def __init__(self):
5249

5350
def load(self):
5451
ProcessingConfig.settingIcons[self.name()] = self.icon()
55-
ProcessingConfig.addSetting(Setting(self.name(), self.activateSetting,
56-
self.tr('Activate'), True))
52+
if self.activateSetting:
53+
ProcessingConfig.addSetting(Setting(self.name(), self.activateSetting,
54+
self.tr('Activate'), True))
5755
if isMac():
5856
ProcessingConfig.addSetting(Setting(
5957
self.name(),
@@ -85,7 +83,8 @@ def load(self):
8583
return True
8684

8785
def unload(self):
88-
ProcessingConfig.removeSetting(self.activateSetting)
86+
if self.activateSetting:
87+
ProcessingConfig.removeSetting(self.activateSetting)
8988
if isMac():
9089
ProcessingConfig.removeSetting(Grass7Utils.GRASS_FOLDER)
9190
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS)
@@ -94,10 +93,13 @@ def unload(self):
9493
ProcessingConfig.removeSetting(Grass7Utils.GRASS_USE_VEXTERNAL)
9594

9695
def isActive(self):
97-
return ProcessingConfig.getSetting(self.activateSetting)
96+
if self.activateSetting:
97+
return ProcessingConfig.getSetting(self.activateSetting)
98+
return True
9899

99100
def setActive(self, active):
100-
ProcessingConfig.setSettingValue(self.activateSetting, active)
101+
if self.activateSetting:
102+
ProcessingConfig.setSettingValue(self.activateSetting, active)
101103

102104
def createAlgsList(self):
103105
algs = []

0 commit comments

Comments
 (0)