Skip to content

Commit bb24dfe

Browse files
committed
[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
1 parent 243f01c commit bb24dfe

31 files changed

Lines changed: 327 additions & 181 deletions

‎doc/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ IF(WITH_APIDOC)
5858
${CMAKE_SOURCE_DIR}/src/core/gps
5959
${CMAKE_SOURCE_DIR}/src/core/layertree
6060
${CMAKE_SOURCE_DIR}/src/core/pal
61+
${CMAKE_SOURCE_DIR}/src/core/processing
6162
${CMAKE_SOURCE_DIR}/src/core/raster
6263
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
6364
${CMAKE_SOURCE_DIR}/src/gui

‎doc/api_break.dox‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,11 @@ optional property map passing down layer level properties to the SLD encoders. I
18261826
- setScaleMethodToSymbol was removed. This is now handled using data defined scaling at a symbol layer level
18271827
- usedAttributes is now a const method and returns QSet<QString> instead of QStringList
18281828

1829+
Processing {#qgis_api_break_3_0_Processing}
1830+
----------
18291831

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

18311835

18321836
QGIS 2.4 {#qgis_api_break_2_4}

‎python/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ INCLUDE_DIRECTORIES(
106106
../src/core/geometry
107107
../src/core/gps
108108
../src/core/layertree
109+
../src/core/processing
109110
../src/core/raster
110111
../src/core/symbology-ng
111112

‎python/core/core.sip‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@
259259
%Include layertree/qgslayertreeregistrybridge.sip
260260
%Include layertree/qgslayertreeutils.sip
261261

262+
%Include processing/qgsprocessingprovider.sip
263+
262264
%Include raster/qgsbilinearrasterresampler.sip
263265
%Include raster/qgsbrightnesscontrastfilter.sip
264266
%Include raster/qgscliptominmaxenhancement.sip
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* \class QgsProcessingProvider
3+
* \ingroup core
4+
* Abstract base class for processing providers. An algorithm provider is a set of
5+
* related algorithms, typically from the same external application or related
6+
* to a common area of analysis.
7+
* \note added in QGIS 3.0
8+
*/
9+
class QgsProcessingProvider
10+
{
11+
%TypeHeaderCode
12+
#include <qgsprocessingprovider.h>
13+
%End
14+
15+
public:
16+
17+
QgsProcessingProvider();
18+
19+
virtual ~QgsProcessingProvider();
20+
21+
/**
22+
* Returns an icon for the provider.
23+
*/
24+
virtual QIcon icon() const;
25+
26+
/**
27+
* Returns the unique provider id, used for identifying the provider. This string
28+
* should be a unique, short, character only string, eg "qgis" or "gdal". This
29+
* string should not be localised.
30+
* @see name()
31+
*/
32+
virtual QString id() const = 0;
33+
34+
/**
35+
* Returns the full provider name, which is used to describe the provider within the GUI.
36+
* This string should be localised.
37+
* @see id()
38+
*/
39+
virtual QString name() const = 0;
40+
41+
virtual bool canBeActivated() const;
42+
43+
private:
44+
45+
//! Providers cannot be copied
46+
QgsProcessingProvider( const QgsProcessingProvider& other );
47+
//! Providers cannot be copied
48+
//QgsProcessingProvider& operator=( const QgsProcessingProvider& other );
49+
};

‎python/plugins/processing/algs/exampleprovider/ExampleAlgorithmProvider.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ExampleAlgorithmProvider(AlgorithmProvider):
3535
MY_DUMMY_SETTING = 'MY_DUMMY_SETTING'
3636

3737
def __init__(self):
38-
AlgorithmProvider.__init__(self)
38+
super().__init__()
3939

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

69-
def getName(self):
69+
def id(self):
7070
"""This is the name that will appear on the toolbox group.
7171
7272
It is also used to create the command line name of all the
7373
algorithms from this provider.
7474
"""
7575
return 'Example provider'
7676

77-
def getDescription(self):
77+
def name(self):
7878
"""This is the provired full name.
7979
"""
8080
return 'Example algorithms'
8181

82-
def getIcon(self):
82+
def icon(self):
8383
"""We return the default icon.
8484
"""
85-
return AlgorithmProvider.getIcon(self)
85+
return AlgorithmProvider.icon(self)
8686

8787
def _loadAlgorithms(self):
8888
"""Here we fill the list of algorithms in self.algs.

‎python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ class GdalAlgorithmProvider(AlgorithmProvider):
9797
"""
9898

9999
def __init__(self):
100-
AlgorithmProvider.__init__(self)
100+
super().__init__()
101101
self.createAlgsList()
102102

103103
def initializeSettings(self):
104104
AlgorithmProvider.initializeSettings(self)
105105
ProcessingConfig.addSetting(Setting(
106-
self.getDescription(),
106+
self.name(),
107107
GdalUtils.GDAL_HELP_PATH,
108108
self.tr('Location of GDAL docs'),
109109
GdalUtils.gdalHelpPath()))
@@ -112,14 +112,14 @@ def unload(self):
112112
AlgorithmProvider.unload(self)
113113
ProcessingConfig.removeSetting(GdalUtils.GDAL_HELP_PATH)
114114

115-
def getDescription(self):
115+
def name(self):
116116
version = GdalUtils.readableVersion()
117117
return 'GDAL ({})'.format(version)
118118

119-
def getName(self):
119+
def id(self):
120120
return 'gdal'
121121

122-
def getIcon(self):
122+
def icon(self):
123123
return QIcon(os.path.join(pluginPath, 'images', 'gdal.svg'))
124124

125125
def _loadAlgorithms(self):

‎python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@
4343
class Grass7AlgorithmProvider(AlgorithmProvider):
4444

4545
def __init__(self):
46-
AlgorithmProvider.__init__(self)
46+
super().__init__()
4747
self.createAlgsList()
4848

4949
def initializeSettings(self):
5050
AlgorithmProvider.initializeSettings(self)
5151
if isWindows() or isMac():
5252
ProcessingConfig.addSetting(Setting(
53-
self.getDescription(),
53+
self.name(),
5454
Grass7Utils.GRASS_FOLDER, self.tr('GRASS7 folder'),
5555
Grass7Utils.grassPath(), valuetype=Setting.FOLDER))
5656
ProcessingConfig.addSetting(Setting(
57-
self.getDescription(),
57+
self.name(),
5858
Grass7Utils.GRASS_LOG_COMMANDS,
5959
self.tr('Log execution commands'), False))
6060
ProcessingConfig.addSetting(Setting(
61-
self.getDescription(),
61+
self.name(),
6262
Grass7Utils.GRASS_LOG_CONSOLE,
6363
self.tr('Log console output'), False))
6464
ProcessingConfig.addSetting(Setting(
65-
self.getDescription(),
65+
self.name(),
6666
Grass7Utils.GRASS_HELP_PATH,
6767
self.tr('Location of GRASS docs'),
6868
Grass7Utils.grassHelpPath()))
@@ -97,14 +97,14 @@ def createAlgsList(self):
9797
def _loadAlgorithms(self):
9898
self.algs = self.preloadedAlgs
9999

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

104-
def getName(self):
104+
def id(self):
105105
return 'grass7'
106106

107-
def getIcon(self):
107+
def icon(self):
108108
return QIcon(os.path.join(pluginPath, 'images', 'grass.svg'))
109109

110110
def getSupportedOutputVectorLayerExtensions(self):

‎python/plugins/processing/algs/lidar/LidarToolsAlgorithmProvider.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
class LidarToolsAlgorithmProvider(AlgorithmProvider):
147147

148148
def __init__(self):
149-
AlgorithmProvider.__init__(self)
149+
super().__init__()
150150
self.activate = False
151151

152152
def _loadAlgorithms(self):
@@ -222,28 +222,28 @@ def _loadAlgorithms(self):
222222
def initializeSettings(self):
223223
AlgorithmProvider.initializeSettings(self)
224224
ProcessingConfig.addSetting(Setting(
225-
self.getDescription(),
225+
self.name(),
226226
LAStoolsUtils.LASTOOLS_FOLDER,
227227
self.tr('LAStools folder'), LAStoolsUtils.LAStoolsPath(),
228228
valuetype=Setting.FOLDER))
229229
ProcessingConfig.addSetting(Setting(
230-
self.getDescription(),
230+
self.name(),
231231
FusionUtils.FUSION_FOLDER,
232232
self.tr('Fusion folder'), FusionUtils.FusionPath(),
233233
valuetype=Setting.FOLDER))
234234
if not isWindows():
235235
ProcessingConfig.addSetting(Setting(
236-
self.getDescription(),
236+
self.name(),
237237
LAStoolsUtils.WINE_FOLDER,
238238
self.tr('Wine folder'), '', valuetype=Setting.FOLDER))
239239

240-
def getName(self):
240+
def id(self):
241241
return 'lidartools'
242242

243-
def getDescription(self):
243+
def name(self):
244244
return self.tr('Tools for LiDAR data')
245245

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

249249
def getSupportedOutputTableExtensions(self):

‎python/plugins/processing/algs/otb/OTBAlgorithmProvider.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
class OTBAlgorithmProvider(AlgorithmProvider):
4545

4646
def __init__(self):
47-
AlgorithmProvider.__init__(self)
47+
super().__init__()
4848
self.activate = True
4949

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

54-
def getName(self):
54+
def id(self):
5555
return "otb"
5656

57-
def getIcon(self):
57+
def icon(self):
5858
return QIcon(os.path.join(pluginPath, 'images', 'otb.png'))
5959

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

8787
def initializeSettings(self):
8888
AlgorithmProvider.initializeSettings(self)
89-
ProcessingConfig.addSetting(Setting(self.getDescription(),
89+
ProcessingConfig.addSetting(Setting(self.name(),
9090
OTBUtils.OTB_FOLDER,
9191
self.tr("OTB command line tools folder"), OTBUtils.findOtbPath(),
9292
valuetype=Setting.FOLDER))
93-
ProcessingConfig.addSetting(Setting(self.getDescription(),
93+
ProcessingConfig.addSetting(Setting(self.name(),
9494
OTBUtils.OTB_LIB_FOLDER,
9595
self.tr("OTB applications folder"), OTBUtils.findOtbLibPath(),
9696
valuetype=Setting.FOLDER))
97-
ProcessingConfig.addSetting(Setting(self.getDescription(),
97+
ProcessingConfig.addSetting(Setting(self.name(),
9898
OTBUtils.OTB_SRTM_FOLDER,
9999
self.tr("SRTM tiles folder"), OTBUtils.otbSRTMPath(),
100100
valuetype=Setting.FOLDER))
101-
ProcessingConfig.addSetting(Setting(self.getDescription(),
101+
ProcessingConfig.addSetting(Setting(self.name(),
102102
OTBUtils.OTB_GEOID_FILE,
103103
self.tr("Geoid file"), OTBUtils.otbGeoidPath(),
104104
valuetype=Setting.FOLDER))

0 commit comments

Comments
 (0)