Skip to content
Permalink
Browse files

[processing] c++ base class for providers

Nothing particularly exciting here yet, but this commit
moves the definition of the provider base class to a c++
QgsProcessingProvider abstract base class.

As part of this some existing python methods were renamed
to make their use clearer and to fit with the QGIS c++
api conventions:

- getName was renamed to id
- getDescription was renamed to name
- getIcon was renamed to icon

These API breaks are documented
  • Loading branch information
nyalldawson committed Jan 11, 2017
1 parent 243f01c commit bb24dfe2457cc1d7fa80dcf8641a666a0b53098f
Showing with 327 additions and 181 deletions.
  1. +1 −0 doc/CMakeLists.txt
  2. +4 −0 doc/api_break.dox
  3. +1 −0 python/CMakeLists.txt
  4. +2 −0 python/core/core.sip
  5. +49 −0 python/core/processing/qgsprocessingprovider.sip
  6. +5 −5 python/plugins/processing/algs/exampleprovider/ExampleAlgorithmProvider.py
  7. +5 −5 python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
  8. +8 −8 python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
  9. +7 −7 python/plugins/processing/algs/lidar/LidarToolsAlgorithmProvider.py
  10. +8 −8 python/plugins/processing/algs/otb/OTBAlgorithmProvider.py
  11. +4 −4 python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
  12. +8 −8 python/plugins/processing/algs/r/RAlgorithmProvider.py
  13. +5 −5 python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
  14. +7 −7 python/plugins/processing/algs/taudem/TauDEMAlgorithmProvider.py
  15. +7 −23 python/plugins/processing/core/AlgorithmProvider.py
  16. +1 −1 python/plugins/processing/core/GeoAlgorithm.py
  17. +18 −18 python/plugins/processing/core/Processing.py
  18. +13 −13 python/plugins/processing/core/alglist.py
  19. +2 −2 python/plugins/processing/gui/ConfigDialog.py
  20. +36 −36 python/plugins/processing/gui/ProcessingToolbox.py
  21. +2 −2 python/plugins/processing/gui/ScriptEditorDialog.py
  22. +5 −5 python/plugins/processing/modeler/ModelerAlgorithmProvider.py
  23. +9 −9 python/plugins/processing/modeler/ModelerDialog.py
  24. +3 −6 python/plugins/processing/preconfigured/PreconfiguredAlgorithmProvider.py
  25. +1 −1 python/plugins/processing/script/ScriptAlgorithm.py
  26. +5 −5 python/plugins/processing/script/ScriptAlgorithmProvider.py
  27. +1 −1 python/plugins/processing/script/ScriptSelector.py
  28. +2 −2 python/plugins/processing/tools/help.py
  29. +5 −0 src/core/CMakeLists.txt
  30. +24 −0 src/core/processing/qgsprocessingprovider.cpp
  31. +79 −0 src/core/processing/qgsprocessingprovider.h
@@ -58,6 +58,7 @@ IF(WITH_APIDOC)
${CMAKE_SOURCE_DIR}/src/core/gps
${CMAKE_SOURCE_DIR}/src/core/layertree
${CMAKE_SOURCE_DIR}/src/core/pal
${CMAKE_SOURCE_DIR}/src/core/processing
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
${CMAKE_SOURCE_DIR}/src/gui
@@ -1826,7 +1826,11 @@ optional property map passing down layer level properties to the SLD encoders. I
- setScaleMethodToSymbol was removed. This is now handled using data defined scaling at a symbol layer level
- usedAttributes is now a const method and returns QSet<QString> instead of QStringList

Processing {#qgis_api_break_3_0_Processing}
----------

- Algorithm providers now subclass the c++ QgsProcessingProvider class, and must be adapted to the API for QgsProcessingProvider. Specifically,
getName() should be replaced with id(), getDescription() with name(), and getIcon with icon().


QGIS 2.4 {#qgis_api_break_2_4}
@@ -106,6 +106,7 @@ INCLUDE_DIRECTORIES(
../src/core/geometry
../src/core/gps
../src/core/layertree
../src/core/processing
../src/core/raster
../src/core/symbology-ng

@@ -259,6 +259,8 @@
%Include layertree/qgslayertreeregistrybridge.sip
%Include layertree/qgslayertreeutils.sip

%Include processing/qgsprocessingprovider.sip

%Include raster/qgsbilinearrasterresampler.sip
%Include raster/qgsbrightnesscontrastfilter.sip
%Include raster/qgscliptominmaxenhancement.sip
@@ -0,0 +1,49 @@
/**
* \class QgsProcessingProvider
* \ingroup core
* Abstract base class for processing providers. An algorithm provider is a set of
* related algorithms, typically from the same external application or related
* to a common area of analysis.
* \note added in QGIS 3.0
*/
class QgsProcessingProvider
{
%TypeHeaderCode
#include <qgsprocessingprovider.h>
%End

public:

QgsProcessingProvider();

virtual ~QgsProcessingProvider();

/**
* Returns an icon for the provider.
*/
virtual QIcon icon() const;

/**
* Returns the unique provider id, used for identifying the provider. This string
* should be a unique, short, character only string, eg "qgis" or "gdal". This
* string should not be localised.
* @see name()
*/
virtual QString id() const = 0;

/**
* Returns the full provider name, which is used to describe the provider within the GUI.
* This string should be localised.
* @see id()
*/
virtual QString name() const = 0;

virtual bool canBeActivated() const;

private:

//! Providers cannot be copied
QgsProcessingProvider( const QgsProcessingProvider& other );
//! Providers cannot be copied
//QgsProcessingProvider& operator=( const QgsProcessingProvider& other );
};
@@ -35,7 +35,7 @@ class ExampleAlgorithmProvider(AlgorithmProvider):
MY_DUMMY_SETTING = 'MY_DUMMY_SETTING'

def __init__(self):
AlgorithmProvider.__init__(self)
super().__init__()

# Deactivate provider by default
self.activate = False
@@ -66,23 +66,23 @@ def unload(self):
ProcessingConfig.removeSetting(
ExampleAlgorithmProvider.MY_DUMMY_SETTING)

def getName(self):
def id(self):
"""This is the name that will appear on the toolbox group.
It is also used to create the command line name of all the
algorithms from this provider.
"""
return 'Example provider'

def getDescription(self):
def name(self):
"""This is the provired full name.
"""
return 'Example algorithms'

def getIcon(self):
def icon(self):
"""We return the default icon.
"""
return AlgorithmProvider.getIcon(self)
return AlgorithmProvider.icon(self)

def _loadAlgorithms(self):
"""Here we fill the list of algorithms in self.algs.
@@ -97,13 +97,13 @@ class GdalAlgorithmProvider(AlgorithmProvider):
"""

def __init__(self):
AlgorithmProvider.__init__(self)
super().__init__()
self.createAlgsList()

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
GdalUtils.GDAL_HELP_PATH,
self.tr('Location of GDAL docs'),
GdalUtils.gdalHelpPath()))
@@ -112,14 +112,14 @@ def unload(self):
AlgorithmProvider.unload(self)
ProcessingConfig.removeSetting(GdalUtils.GDAL_HELP_PATH)

def getDescription(self):
def name(self):
version = GdalUtils.readableVersion()
return 'GDAL ({})'.format(version)

def getName(self):
def id(self):
return 'gdal'

def getIcon(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdal.svg'))

def _loadAlgorithms(self):
@@ -43,26 +43,26 @@
class Grass7AlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
super().__init__()
self.createAlgsList()

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
Grass7Utils.GRASS_FOLDER, self.tr('GRASS7 folder'),
Grass7Utils.grassPath(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
Grass7Utils.GRASS_LOG_COMMANDS,
self.tr('Log execution commands'), False))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
Grass7Utils.GRASS_LOG_CONSOLE,
self.tr('Log console output'), False))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
Grass7Utils.GRASS_HELP_PATH,
self.tr('Location of GRASS docs'),
Grass7Utils.grassHelpPath()))
@@ -97,14 +97,14 @@ def createAlgsList(self):
def _loadAlgorithms(self):
self.algs = self.preloadedAlgs

def getDescription(self):
def name(self):
version = Grass7Utils.installedVersion()
return 'GRASS GIS ({})'.format(version) if version is not None else "GRASS GIS"

def getName(self):
def id(self):
return 'grass7'

def getIcon(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'grass.svg'))

def getSupportedOutputVectorLayerExtensions(self):
@@ -146,7 +146,7 @@
class LidarToolsAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
super().__init__()
self.activate = False

def _loadAlgorithms(self):
@@ -222,28 +222,28 @@ def _loadAlgorithms(self):
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
LAStoolsUtils.LASTOOLS_FOLDER,
self.tr('LAStools folder'), LAStoolsUtils.LAStoolsPath(),
valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
FusionUtils.FUSION_FOLDER,
self.tr('Fusion folder'), FusionUtils.FusionPath(),
valuetype=Setting.FOLDER))
if not isWindows():
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
LAStoolsUtils.WINE_FOLDER,
self.tr('Wine folder'), '', valuetype=Setting.FOLDER))

def getName(self):
def id(self):
return 'lidartools'

def getDescription(self):
def name(self):
return self.tr('Tools for LiDAR data')

def getIcon(self):
def icon(self):
return QIcon(os.path.dirname(__file__) + '/../../images/tool.png')

def getSupportedOutputTableExtensions(self):
@@ -44,17 +44,17 @@
class OTBAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
super().__init__()
self.activate = True

def getDescription(self):
def name(self):
version = OTBUtils.getInstalledVersion()
return "Orfeo ToolBox ({})".format(version) if version is not None else "Orfeo ToolBox"

def getName(self):
def id(self):
return "otb"

def getIcon(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'otb.png'))

def _loadAlgorithms(self):
@@ -86,19 +86,19 @@ def _loadAlgorithms(self):

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(self.getDescription(),
ProcessingConfig.addSetting(Setting(self.name(),
OTBUtils.OTB_FOLDER,
self.tr("OTB command line tools folder"), OTBUtils.findOtbPath(),
valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
ProcessingConfig.addSetting(Setting(self.name(),
OTBUtils.OTB_LIB_FOLDER,
self.tr("OTB applications folder"), OTBUtils.findOtbLibPath(),
valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
ProcessingConfig.addSetting(Setting(self.name(),
OTBUtils.OTB_SRTM_FOLDER,
self.tr("SRTM tiles folder"), OTBUtils.otbSRTMPath(),
valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
ProcessingConfig.addSetting(Setting(self.name(),
OTBUtils.OTB_GEOID_FILE,
self.tr("Geoid file"), OTBUtils.otbGeoidPath(),
valuetype=Setting.FOLDER))
@@ -196,7 +196,7 @@
class QGISAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
super().__init__()
self._icon = QIcon(os.path.join(pluginPath, 'images', 'qgis.svg'))

self.alglist = [SumLines(), PointsInPolygon(),
@@ -297,13 +297,13 @@ def initializeSettings(self):
def unload(self):
AlgorithmProvider.unload(self)

def getName(self):
def id(self):
return 'qgis'

def getDescription(self):
def name(self):
return 'QGIS'

def getIcon(self):
def icon(self):
return self._icon

def _loadAlgorithms(self):
@@ -50,7 +50,7 @@
class RAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
super().__init__()
self.activate = False
self.actions.append(CreateNewScriptAction(
'Create new R script', CreateNewScriptAction.SCRIPT_R))
@@ -62,20 +62,20 @@ def __init__(self):
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(
self.getDescription(), RUtils.RSCRIPTS_FOLDER,
self.name(), RUtils.RSCRIPTS_FOLDER,
self.tr('R Scripts folder'), RUtils.defaultRScriptsFolder(),
valuetype=Setting.MULTIPLE_FOLDERS))
if isWindows():
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
RUtils.R_FOLDER, self.tr('R folder'), RUtils.RFolder(),
valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
RUtils.R_LIBS_USER, self.tr('R user library folder'),
RUtils.RLibs(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(
self.getDescription(),
self.name(),
RUtils.R_USE64, self.tr('Use 64 bit version'), False))

def unload(self):
@@ -86,13 +86,13 @@ def unload(self):
ProcessingConfig.removeSetting(RUtils.R_LIBS_USER)
ProcessingConfig.removeSetting(RUtils.R_USE64)

def getIcon(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'r.svg'))

def getDescription(self):
def name(self):
return 'R scripts'

def getName(self):
def id(self):
return 'r'

def _loadAlgorithms(self):

1 comment on commit bb24dfe

@m-kuhn

This comment has been minimized.

Copy link
Member

@m-kuhn m-kuhn commented on bb24dfe Jan 11, 2017

Wheeeeee!

Please sign in to comment.
You can’t perform that action at this time.