Skip to content

Commit

Permalink
[processing] c++ base class for providers
Browse files Browse the repository at this point in the history
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 bb24dfe
Show file tree
Hide file tree
Showing 31 changed files with 327 additions and 181 deletions.
1 change: 1 addition & 0 deletions doc/CMakeLists.txt
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions python/core/core.sip
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions python/core/processing/qgsprocessingprovider.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 );
};
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
Expand Up @@ -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()))
Expand All @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
Expand Up @@ -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()))
Expand Down Expand Up @@ -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):
Expand Down
Expand Up @@ -146,7 +146,7 @@
class LidarToolsAlgorithmProvider(AlgorithmProvider):

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

def _loadAlgorithms(self):
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions python/plugins/processing/algs/otb/OTBAlgorithmProvider.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -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(),
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions python/plugins/processing/algs/r/RAlgorithmProvider.py
Expand Up @@ -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))
Expand All @@ -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):
Expand All @@ -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):
Expand Down

1 comment on commit bb24dfe

@m-kuhn
Copy link
Member

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wheeeeee!

Please sign in to comment.