Skip to content

Commit

Permalink
Merge pull request #4311 from nyalldawson/proc_c4
Browse files Browse the repository at this point in the history
Simple c++ base class for processing algorithms
  • Loading branch information
nyalldawson committed Apr 4, 2017
2 parents 85e83e1 + d2a242a commit 51517fd
Show file tree
Hide file tree
Showing 249 changed files with 3,413 additions and 1,056 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -273,6 +273,7 @@
%Include layertree/qgslayertreeregistrybridge.sip
%Include layertree/qgslayertreeutils.sip

%Include processing/qgsprocessingalgorithm.sip
%Include processing/qgsprocessingfeedback.sip
%Include processing/qgsprocessingprovider.sip
%Include processing/qgsprocessingregistry.sip
Expand Down
99 changes: 99 additions & 0 deletions python/core/processing/qgsprocessingalgorithm.sip
@@ -0,0 +1,99 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsProcessingAlgorithm
{
%Docstring
Abstract base class for processing algorithms.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsprocessingalgorithm.h"
%End
public:

enum Flag
{
FlagHideFromToolbox,
FlagHideFromModeler,
FlagSupportsBatch,
FlagDeprecated
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;

QgsProcessingAlgorithm();
%Docstring
Constructor for QgsProcessingAlgorithm.
%End

virtual ~QgsProcessingAlgorithm();

virtual QString name() const = 0;
%Docstring
Returns the algorithm name, used for identifying the algorithm. This string
should be fixed for the algorithm, and must not be localised. The name should
be unique within each provider. Names should contain lowercase alphanumeric characters
only and no spaces or other formatting characters.
\see displayName()
\see group()
\see tags()
%End

virtual QString displayName() const = 0;
%Docstring
Returns the translated algorithm name, which should be used for any user-visible display
of the algorithm name.
\see name()
%End

virtual QStringList tags() const;
%Docstring
Returns a list of tags which relate to the algorithm, and are used to assist users in searching
for suitable algorithms. These tags should be localised.
%End

virtual QIcon icon() const;
%Docstring
Returns an icon for the algorithm.
\see svgIconPath()
%End

virtual QString svgIconPath() const;
%Docstring
Returns a path to an SVG version of the algorithm's icon.
\see icon()
%End

virtual QString group() const;
%Docstring
Returns the name of the group this algorithm belongs to. This string
should be localised.
\see tags()
%End

virtual Flags flags() const;
%Docstring
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
%End

};
QFlags<QgsProcessingAlgorithm::Flag> operator|(QgsProcessingAlgorithm::Flag f1, QFlags<QgsProcessingAlgorithm::Flag> f2);



/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingalgorithm.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
29 changes: 29 additions & 0 deletions python/core/processing/qgsprocessingprovider.sip
Expand Up @@ -66,6 +66,35 @@ class QgsProcessingProvider
missing external dependencies).
%End

virtual QStringList supportedOutputRasterLayerExtensions() const;
%Docstring
Returns a list of the raster format file extensions supported by this provider.
\see supportedOutputVectorLayerExtensions()
\see supportedOutputTableExtensions()
%End

virtual QStringList supportedOutputVectorLayerExtensions() const;
%Docstring
Returns a list of the vector format file extensions supported by this provider.
\see supportedOutputRasterLayerExtensions()
\see supportedOutputTableExtensions()
\see supportsNonFileBasedOutput()
%End

virtual QStringList supportedOutputTableExtensions() const;
%Docstring
Returns a list of the table format file extensions supported by this provider.
\see supportedOutputRasterLayerExtensions()
\see supportedOutputVectorLayerExtensions()
%End

virtual bool supportsNonFileBasedOutput() const;
%Docstring
Returns true if the provider supports non-file based outputs (such as memory layers
or direct database outputs).
\see supportedOutputVectorLayerExtensions()
%End

private:
QgsProcessingProvider( const QgsProcessingProvider &other );
};
Expand Down
17 changes: 11 additions & 6 deletions python/plugins/processing/algs/exampleprovider/ExampleAlgorithm.py
Expand Up @@ -54,17 +54,22 @@ class ExampleAlgorithm(GeoAlgorithm):
OUTPUT_LAYER = 'OUTPUT_LAYER'
INPUT_LAYER = 'INPUT_LAYER'

def name(self):
# Unique (non-user visible) name of algorithm
return 'create_copy_of_layer'

def displayName(self):
# The name that the user will see in the toolbox
return self.tr('Create copy of layer')

def group(self):
return self.tr('Algorithms for vector layers')

def defineCharacteristics(self):
"""Here we define the inputs and output of the algorithm, along
with some other properties.
"""

# The name that the user will see in the toolbox
self.name, self.i18n_name = self.trAlgorithm('Create copy of layer')

# The branch of the toolbox under which the algorithm will appear
self.group, self.i18n_group = self.trAlgorithm('Algorithms for vector layers')

# We add the input vector layer. It can have any kind of geometry
# It is a mandatory (not optional) one, hence the False argument
self.addParameter(ParameterVector(self.INPUT_LAYER,
Expand Down
14 changes: 10 additions & 4 deletions python/plugins/processing/algs/gdal/AssignProjection.py
Expand Up @@ -46,13 +46,19 @@ class AssignProjection(GdalAlgorithm):
CRS = 'CRS'
OUTPUT = 'OUTPUT'

def getIcon(self):
def name(self):
return 'assignprojection'

def displayName(self):
return self.tr('Assign projection')

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'projection-add.png'))

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Assign projection')
self.group, self.i18n_group = self.trAlgorithm('Raster projections')
def group(self):
return self.tr('Raster projections')

def defineCharacteristics(self):
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer'), False))
self.addParameter(ParameterCrs(self.CRS,
self.tr('Desired CRS'), ''))
Expand Down
14 changes: 10 additions & 4 deletions python/plugins/processing/algs/gdal/ClipByExtent.py
Expand Up @@ -53,13 +53,19 @@ class ClipByExtent(GdalAlgorithm):
RTYPE = 'RTYPE'
TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']

def getIcon(self):
def name(self):
return 'cliprasterbyextent'

def displayName(self):
return self.tr('Clip raster by extent')

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-clip.png'))

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Clip raster by extent')
self.group, self.i18n_group = self.trAlgorithm('Raster extraction')
def group(self):
return self.tr('Raster extraction')

def defineCharacteristics(self):
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer')))
self.addParameter(ParameterString(self.NO_DATA,
self.tr("Nodata value, leave blank to take the nodata value from input"),
Expand Down
14 changes: 10 additions & 4 deletions python/plugins/processing/algs/gdal/ClipByMask.py
Expand Up @@ -62,13 +62,19 @@ class ClipByMask(GdalAlgorithm):
RTYPE = 'RTYPE'
TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']

def getIcon(self):
def name(self):
return 'cliprasterbymasklayer'

def displayName(self):
return self.tr('Clip raster by mask layer')

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-clip.png'))

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Clip raster by mask layer')
self.group, self.i18n_group = self.trAlgorithm('Raster extraction')
def group(self):
return self.tr('Raster extraction')

def defineCharacteristics(self):
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer'), False))
self.addParameter(ParameterVector(self.MASK, self.tr('Mask layer'),
[dataobjects.TYPE_VECTOR_POLYGON]))
Expand Down
13 changes: 8 additions & 5 deletions python/plugins/processing/algs/gdal/ColorRelief.py
Expand Up @@ -47,13 +47,16 @@ class ColorRelief(GdalAlgorithm):

MATCHING_MODES = ['"0,0,0,0" RGBA', 'Exact color', 'Nearest color']

#def getIcon(self):
# filepath = os.path.dirname(__file__) + '/icons/dem.png'
# return QIcon(filepath)
def name(self):
return 'colorrelief'

def displayName(self):
return self.tr('Color relief')

def group(self):
return self.tr('Raster analysis')

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Color relief')
self.group, self.i18n_group = self.trAlgorithm('Raster analysis')
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer')))
self.addParameter(ParameterNumber(
self.BAND, self.tr('Band number'), 1, 99, 1))
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/processing/algs/gdal/GdalAlgorithm.py
Expand Up @@ -46,12 +46,12 @@ class GdalAlgorithm(GeoAlgorithm):

def __init__(self):
GeoAlgorithm.__init__(self)
self._icon = None

def getIcon(self):
if self._icon is None:
self._icon = QgsApplication.getThemeIcon("/providerGdal.svg")
return self._icon
def icon(self):
return QgsApplication.getThemeIcon("/providerGdal.svg")

def svgIconPath(self):
return QgsApplication.iconPath("providerGdal.svg")

def getCustomParametersDialog(self):
return GdalAlgorithmDialog(self)
Expand Down
Expand Up @@ -147,5 +147,5 @@ def createAlgsList(self):
OffsetCurve(), Ogr2OgrTableToPostGisList(), OgrSql(),
]

def getSupportedOutputRasterLayerExtensions(self):
def supportedOutputRasterLayerExtensions(self):
return GdalUtils.getSupportedRasterExtensions()
13 changes: 10 additions & 3 deletions python/plugins/processing/algs/gdal/GridAverage.py
Expand Up @@ -56,15 +56,22 @@ class GridAverage(GdalAlgorithm):

TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']

def getIcon(self):
def name(self):
return 'gridmovingaverage'

def displayName(self):
return self.tr('Grid (Moving average)')

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

def commandLineName(self):
return "gdal:gridaverage"

def group(self):
return self.tr('Raster analysis')

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Grid (Moving average)')
self.group, self.i18n_group = self.trAlgorithm('Raster analysis')
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_POINT]))
self.addParameter(ParameterTableField(self.Z_FIELD,
Expand Down
13 changes: 10 additions & 3 deletions python/plugins/processing/algs/gdal/GridDataMetrics.py
Expand Up @@ -61,15 +61,22 @@ class GridDataMetrics(GdalAlgorithm):
DATA_METRICS = ['Minimum', 'Maximum', 'Range', 'Count', 'Average distance',
'Average distance between points']

def getIcon(self):
def name(self):
return 'griddatametrics'

def displayName(self):
return self.tr('Grid (Data metrics)')

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

def commandLineName(self):
return "gdal:griddatametrics"

def group(self):
return self.tr('Raster analysis')

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Grid (Data metrics)')
self.group, self.i18n_group = self.trAlgorithm('Raster analysis')
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_POINT]))
self.addParameter(ParameterTableField(self.Z_FIELD,
Expand Down
14 changes: 9 additions & 5 deletions python/plugins/processing/algs/gdal/GridInvDist.py
Expand Up @@ -60,15 +60,19 @@ class GridInvDist(GdalAlgorithm):

TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']

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

def commandLineName(self):
return "gdal:gridinvdist"
def name(self):
return 'gridinvdist'

def displayName(self):
return self.tr('Grid (Inverse distance to a power)')

def group(self):
return self.tr('Raster analysis')

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Grid (Inverse distance to a power)')
self.group, self.i18n_group = self.trAlgorithm('Raster analysis')
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_POINT]))
self.addParameter(ParameterTableField(self.Z_FIELD,
Expand Down
14 changes: 9 additions & 5 deletions python/plugins/processing/algs/gdal/GridNearest.py
Expand Up @@ -56,15 +56,19 @@ class GridNearest(GdalAlgorithm):

TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']

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

def commandLineName(self):
return "gdal:gridnearestneighbor"
def name(self):
return 'gridnearestneighbor'

def displayName(self):
return self.tr('Grid (Nearest neighbor)')

def group(self):
return self.tr('Raster analysis')

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Grid (Nearest neighbor)')
self.group, self.i18n_group = self.trAlgorithm('Raster analysis')
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer'), [dataobjects.TYPE_VECTOR_POINT]))
self.addParameter(ParameterTableField(self.Z_FIELD,
Expand Down

0 comments on commit 51517fd

Please sign in to comment.