Skip to content
Permalink
Browse files
Move provider algorithm handling to QgsProcessingProvider
  • Loading branch information
nyalldawson committed Apr 7, 2017
1 parent 9c30a0e commit b3142a0bafe65f832f9dbd68a5c38852e17b9d7d
Showing with 403 additions and 204 deletions.
  1. +6 −0 python/core/processing/qgsprocessingalgorithm.sip
  2. +47 −0 python/core/processing/qgsprocessingprovider.sip
  3. +6 −9 python/plugins/processing/algs/exampleprovider/ExampleAlgorithmProvider.py
  4. +20 −24 python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
  5. +0 −1 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  6. +10 −8 python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
  7. +1 −1 python/plugins/processing/algs/grass7/ext/r_texture.py
  8. +73 −74 python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
  9. +0 −1 python/plugins/processing/algs/r/RAlgorithm.py
  10. +7 −5 python/plugins/processing/algs/r/RAlgorithmProvider.py
  11. +0 −1 python/plugins/processing/algs/saga/SagaAlgorithm.py
  12. +6 −8 python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
  13. +2 −15 python/plugins/processing/core/AlgorithmProvider.py
  14. +1 −4 python/plugins/processing/core/GeoAlgorithm.py
  15. +7 −7 python/plugins/processing/core/Processing.py
  16. +3 −3 python/plugins/processing/core/alglist.py
  17. +7 −7 python/plugins/processing/core/outputs.py
  18. +2 −2 python/plugins/processing/gui/ConfigDialog.py
  19. +3 −3 python/plugins/processing/gui/OutputSelectionPanel.py
  20. +0 −2 python/plugins/processing/gui/ScriptEditorDialog.py
  21. +1 −1 python/plugins/processing/gui/menus.py
  22. +0 −1 python/plugins/processing/modeler/ModelerAlgorithm.py
  23. +5 −6 python/plugins/processing/modeler/ModelerAlgorithmProvider.py
  24. +0 −6 python/plugins/processing/modeler/ModelerDialog.py
  25. +0 −1 python/plugins/processing/preconfigured/PreconfiguredAlgorithm.py
  26. +2 −3 python/plugins/processing/preconfigured/PreconfiguredAlgorithmProvider.py
  27. +0 −1 python/plugins/processing/script/ScriptAlgorithm.py
  28. +11 −6 python/plugins/processing/script/ScriptAlgorithmProvider.py
  29. +2 −2 python/plugins/processing/tools/help.py
  30. +1 −1 python/plugins/processing/tools/translation.py
  31. +10 −0 src/core/processing/qgsprocessingalgorithm.cpp
  32. +20 −0 src/core/processing/qgsprocessingalgorithm.h
  33. +40 −0 src/core/processing/qgsprocessingprovider.cpp
  34. +52 −1 src/core/processing/qgsprocessingprovider.h
  35. +58 −0 tests/src/core/testqgsprocessing.cpp
@@ -9,6 +9,7 @@




class QgsProcessingAlgorithm
{
%Docstring
@@ -85,6 +86,11 @@ class QgsProcessingAlgorithm
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
%End

QgsProcessingProvider *provider() const;
%Docstring
Returns the provider to which this algorithm belongs.
%End

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

@@ -95,6 +95,53 @@ class QgsProcessingProvider
\see supportedOutputVectorLayerExtensions()
%End

virtual bool load();
%Docstring
Loads the provider. This will be called when the plugin is being loaded, and any general
setup actions should occur in an overridden version of this method.
Subclasses should not load any algorithms in their load() implementations, as that must
occur within the loadAlgorithms() method.
\returns true if provider could be successfully loaded
\see unload()
%End

virtual void unload();
%Docstring
Unloads the provider. Any tear-down steps required by the provider should be implemented here.
\see load()
%End

void refreshAlgorithms();
%Docstring
Refreshes the algorithms available from the provider, causing it to re-populate with all associated algorithms.
%End

QList< QgsProcessingAlgorithm * > algorithms() const;
%Docstring
Returns a list of algorithms supplied by this provider.
\see algorithm()
%End

QgsProcessingAlgorithm *algorithm( const QString &name ) const;
%Docstring
Returns the matching algorithm by name, or a nullptr if no matching
algorithm is contained by this provider.
\see algorithms()
%End

protected:

virtual void loadAlgorithms() = 0;
%Docstring
Loads all algorithms belonging to this provider. Subclasses should implement this, calling
addAlgorithm() to register all their associated algorithms.
%End

bool addAlgorithm( QgsProcessingAlgorithm *algorithm /Transfer/ );
%Docstring
Adds an algorithm to the provider. Ownership of the algorithm is transferred to the provider.
%End

private:
QgsProcessingProvider( const QgsProcessingProvider &other );
};
@@ -40,23 +40,19 @@ def __init__(self):
# Deactivate provider by default
self.activate = False

# Load algorithms
self.alglist = [ExampleAlgorithm()]
for alg in self.alglist:
alg.provider = self

def initializeSettings(self):
def load(self):
"""In this method we add settings needed to configure our
provider.
Do not forget to call the parent method, since it takes care
or automatically adding a setting for activating or
deactivating the algorithms in the provider.
"""
AlgorithmProvider.initializeSettings(self)
AlgorithmProvider.load(self)
ProcessingConfig.addSetting(Setting('Example algorithms',
ExampleAlgorithmProvider.MY_DUMMY_SETTING,
'Example setting', 'Default value'))
return True

def unload(self):
"""Setting should be removed here, so they do not appear anymore
@@ -84,7 +80,7 @@ def icon(self):
"""
return AlgorithmProvider.icon(self)

def _loadAlgorithms(self):
def loadAlgorithms(self):
"""Here we fill the list of algorithms in self.algs.
This method is called whenever the list of algorithms should
@@ -98,4 +94,5 @@ def _loadAlgorithms(self):
even if the list does not change, since the self.algs list is
cleared before calling this method.
"""
self.algs = self.alglist
for alg in [ExampleAlgorithm()]:
self.addAlgorithm(alg)
@@ -98,15 +98,15 @@ class GdalAlgorithmProvider(AlgorithmProvider):

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

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
def load(self):
AlgorithmProvider.load(self)
ProcessingConfig.addSetting(Setting(
self.name(),
GdalUtils.GDAL_HELP_PATH,
self.tr('Location of GDAL docs'),
GdalUtils.gdalHelpPath()))
return True

def unload(self):
AlgorithmProvider.unload(self)
@@ -125,27 +125,23 @@ def icon(self):
def svgIconPath(self):
return QgsApplication.iconPath("providerGdal.svg")

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs

def createAlgsList(self):
# First we populate the list of algorithms with those created
# extending GeoAlgorithm directly (those that execute GDAL
# using the console)
self.preloadedAlgs = [nearblack(), information(), warp(), translate(),
rgb2pct(), pct2rgb(), merge(), buildvrt(), polygonize(), gdaladdo(),
ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
ColorRelief(), GridInvDist(), GridAverage(), GridNearest(),
GridDataMetrics(), gdaltindex(), gdalcalc(), rasterize_over(),
retile(), gdal2tiles(), AssignProjection(),
# ----- OGR tools -----
OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(),
Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(),
Ogr2OgrBuffer(), Ogr2OgrDissolve(), OneSideBuffer(),
OffsetCurve(), Ogr2OgrTableToPostGisList(), OgrSql(),
]
def loadAlgorithms(self):
algs = [nearblack(), information(), warp(), translate(),
rgb2pct(), pct2rgb(), merge(), buildvrt(), polygonize(), gdaladdo(),
ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(),
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
ColorRelief(), GridInvDist(), GridAverage(), GridNearest(),
GridDataMetrics(), gdaltindex(), gdalcalc(), rasterize_over(),
retile(), gdal2tiles(), AssignProjection(),
# ----- OGR tools -----
OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(),
Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(),
Ogr2OgrBuffer(), Ogr2OgrDissolve(), OneSideBuffer(),
OffsetCurve(), Ogr2OgrTableToPostGisList(), OgrSql(),
]
for a in algs:
self.addAlgorithm(a)

def supportedOutputRasterLayerExtensions(self):
return GdalUtils.getSupportedRasterExtensions()
@@ -98,7 +98,6 @@ def __init__(self, descriptionfile):

def getCopy(self):
newone = Grass7Algorithm(self.descriptionFile)
newone.provider = self.provider
return newone

def name(self):
@@ -44,10 +44,9 @@ class Grass7AlgorithmProvider(AlgorithmProvider):

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

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
def load(self):
AlgorithmProvider.load(self)
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting(
self.name(),
@@ -66,6 +65,7 @@ def initializeSettings(self):
Grass7Utils.GRASS_HELP_PATH,
self.tr('Location of GRASS docs'),
Grass7Utils.grassHelpPath()))
return True

def unload(self):
AlgorithmProvider.unload(self)
@@ -76,14 +76,14 @@ def unload(self):
ProcessingConfig.removeSetting(Grass7Utils.GRASS_HELP_PATH)

def createAlgsList(self):
self.preloadedAlgs = []
algs = []
folder = Grass7Utils.grassDescriptionPath()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
try:
alg = Grass7Algorithm(os.path.join(folder, descriptionFile))
if alg.name().strip() != '':
self.preloadedAlgs.append(alg)
algs.append(alg)
else:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
@@ -92,10 +92,12 @@ def createAlgsList(self):
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
self.tr('Could not open GRASS GIS 7 algorithm: {0}\n{1}').format(descriptionFile, str(e)))
self.preloadedAlgs.append(nviz7())
algs.append(nviz7())
return algs

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs
def loadAlgorithms(self):
for a in self.createAlgsList():
self.addAlgorithm(a)

def name(self):
version = Grass7Utils.installedVersion()
@@ -53,7 +53,7 @@ def processOutputs(alg):
else:
angles = ['']

ext = alg.provider.supportedOutputRasterLayerExtensions()[0]
ext = alg.provider().getSupportedOutputRasterLayerExtensions()[0]
for method in methodList:
out = alg.getOutputValue(u'output')
for angle in angles:
Loading

0 comments on commit b3142a0

Please sign in to comment.