Navigation Menu

Skip to content

Commit

Permalink
Make setting "Grass7AlgorithProvider.activateSetting" optional.
Browse files Browse the repository at this point in the history
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 authored and nyalldawson committed Jun 29, 2019
1 parent cdef051 commit cccb1d3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
Expand Up @@ -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):
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
Expand All @@ -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 = []
Expand Down

0 comments on commit cccb1d3

Please sign in to comment.