Skip to content
Permalink
Browse files
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
  • Loading branch information
pmav99 committed Jun 21, 2019
1 parent eb29f52 commit b30bcbfd195683fa165b55f033b5f077d91905dd
Showing with 10 additions and 8 deletions.
  1. +10 −8 python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
@@ -40,10 +40,7 @@

class Grass7AlgorithmProvider(QgsProcessingProvider):

# Subclasses of `Grass7AlgorithmProvider` should override `descriptionFolder`
# and set its value to their own description folder.
descriptionFolder = Grass7Utils.grassDescriptionPath()

activateSetting = "ACTIVATE_GRASS7"

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

def load(self):
ProcessingConfig.settingIcons[self.name()] = self.icon()
ProcessingConfig.addSetting(Setting(self.name(), self.activateSetting,
self.tr('Activate'), True))
if self.activateSetting:
ProcessingConfig.addSetting(Setting(self.name(), self.activateSetting,
self.tr('Activate'), True))
if isMac():
ProcessingConfig.addSetting(Setting(
self.name(),
@@ -85,7 +83,8 @@ def load(self):
return True

def unload(self):
ProcessingConfig.removeSetting(self.activateSetting)
if self.activateSetting:
ProcessingConfig.removeSetting(self.activateSetting)
if isMac():
ProcessingConfig.removeSetting(Grass7Utils.GRASS_FOLDER)
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS)
@@ -94,10 +93,13 @@ def unload(self):
ProcessingConfig.removeSetting(Grass7Utils.GRASS_USE_VEXTERNAL)

def isActive(self):
return ProcessingConfig.getSetting(self.activateSetting)
if self.activateSetting:
return ProcessingConfig.getSetting(self.activateSetting)
return True

def setActive(self, active):
ProcessingConfig.setSettingValue(self.activateSetting, active)
if self.activateSetting:
ProcessingConfig.setSettingValue(self.activateSetting, active)

def createAlgsList(self):
algs = []

0 comments on commit b30bcbf

Please sign in to comment.