mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
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
This commit is contained in:
parent
03f1ae9576
commit
d8b0cdacb7
@ -40,10 +40,7 @@ pluginPath = os.path.normpath(os.path.join(
|
||||
|
||||
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 @@ class Grass7AlgorithmProvider(QgsProcessingProvider):
|
||||
|
||||
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 @@ class Grass7AlgorithmProvider(QgsProcessingProvider):
|
||||
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 @@ class Grass7AlgorithmProvider(QgsProcessingProvider):
|
||||
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 = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user