Skip to content
Permalink
Browse files
Merge pull request #4328 from nyalldawson/proc_c7
Porting processing to c++, part 2 (followup to #4311)
  • Loading branch information
nyalldawson committed Apr 7, 2017
2 parents 9c30a0e + 837ee29 commit 2adccb929572773cb527b7888ad14e154fc9b1da
Showing with 1,057 additions and 737 deletions.
  1. +3 −2 doc/api_break.dox
  2. +18 −0 python/core/processing/qgsprocessingalgorithm.sip
  3. +65 −2 python/core/processing/qgsprocessingprovider.sip
  4. +17 −1 python/core/processing/qgsprocessingregistry.sip
  5. +3 −2 python/plugins/processing/ProcessingPlugin.py
  6. +24 −22 python/plugins/processing/algs/exampleprovider/ExampleAlgorithmProvider.py
  7. +3 −2 python/plugins/processing/algs/exampleprovider/ProcessingExampleProviderPlugin.py
  8. +41 −28 python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
  9. +1 −4 python/plugins/processing/algs/gdal/GridAverage.py
  10. +0 −3 python/plugins/processing/algs/gdal/GridDataMetrics.py
  11. +2 −7 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  12. +32 −12 python/plugins/processing/algs/grass7/Grass7AlgorithmProvider.py
  13. +9 −1 python/plugins/processing/algs/grass7/Grass7Utils.py
  14. +1 −1 python/plugins/processing/algs/grass7/ext/r_texture.py
  15. +78 −77 python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
  16. +1 −3 python/plugins/processing/algs/r/RAlgorithm.py
  17. +35 −8 python/plugins/processing/algs/r/RAlgorithmProvider.py
  18. +3 −18 python/plugins/processing/algs/saga/SagaAlgorithm.py
  19. +27 −10 python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
  20. +0 −94 python/plugins/processing/core/AlgorithmProvider.py
  21. +3 −9 python/plugins/processing/core/GeoAlgorithm.py
  22. +47 −105 python/plugins/processing/core/Processing.py
  23. +0 −64 python/plugins/processing/core/alglist.py
  24. +7 −7 python/plugins/processing/core/outputs.py
  25. +4 −5 python/plugins/processing/gui/CommanderWindow.py
  26. +19 −14 python/plugins/processing/gui/ConfigDialog.py
  27. +4 −3 python/plugins/processing/gui/DeleteScriptAction.py
  28. +2 −2 python/plugins/processing/gui/EditRenderingStylesDialog.py
  29. +2 −3 python/plugins/processing/gui/GetScriptsAndModels.py
  30. +3 −3 python/plugins/processing/gui/OutputSelectionPanel.py
  31. +1 −1 python/plugins/processing/gui/Postprocessing.py
  32. +61 −59 python/plugins/processing/gui/ProcessingToolbox.py
  33. +54 −0 python/plugins/processing/gui/ProviderActions.py
  34. +2 −5 python/plugins/processing/gui/ScriptEditorDialog.py
  35. +2 −1 python/plugins/processing/gui/TestTools.py
  36. +22 −25 python/plugins/processing/gui/menus.py
  37. +1 −2 python/plugins/processing/modeler/AddModelFromFileAction.py
  38. +1 −2 python/plugins/processing/modeler/CreateNewModelAction.py
  39. +2 −2 python/plugins/processing/modeler/DeleteModelAction.py
  40. +2 −2 python/plugins/processing/modeler/EditModelAction.py
  41. +3 −11 python/plugins/processing/modeler/ModelerAlgorithm.py
  42. +21 −8 python/plugins/processing/modeler/ModelerAlgorithmProvider.py
  43. +7 −18 python/plugins/processing/modeler/ModelerDialog.py
  44. +1 −1 python/plugins/processing/modeler/ModelerParametersDialog.py
  45. +0 −1 python/plugins/processing/modeler/ModelerUtils.py
  46. +2 −2 python/plugins/processing/preconfigured/DeletePreconfiguredAlgorithmAction.py
  47. +5 −6 python/plugins/processing/preconfigured/PreconfiguredAlgorithm.py
  48. +2 −2 python/plugins/processing/preconfigured/PreconfiguredAlgorithmDialog.py
  49. +15 −3 python/plugins/processing/preconfigured/PreconfiguredAlgorithmProvider.py
  50. +1 −1 python/plugins/processing/preconfigured/PreconfiguredUtils.py
  51. +1 −2 python/plugins/processing/script/AddScriptFromFileAction.py
  52. +1 −2 python/plugins/processing/script/ScriptAlgorithm.py
  53. +28 −15 python/plugins/processing/script/ScriptAlgorithmProvider.py
  54. +1 −1 python/plugins/processing/script/ScriptSelector.py
  55. +0 −1 python/plugins/processing/script/ScriptUtils.py
  56. +5 −2 python/plugins/processing/tests/AlgorithmsTestBase.py
  57. +2 −1 python/plugins/processing/tests/GdalAlgorithmsTest.py
  58. +2 −0 python/plugins/processing/tests/Grass7AlgorithmsImageryTest.py
  59. +2 −0 python/plugins/processing/tests/Grass7AlgorithmsRasterTest.py
  60. +2 −0 python/plugins/processing/tests/QgisAlgorithmsTest.py
  61. +2 −0 python/plugins/processing/tests/ScriptAlgorithmsTest.py
  62. +2 −0 python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
  63. +8 −37 python/plugins/processing/tools/general.py
  64. +6 −5 python/plugins/processing/tools/help.py
  65. +3 −2 python/plugins/processing/tools/translation.py
  66. +1 −1 src/core/CMakeLists.txt
  67. +19 −0 src/core/processing/qgsprocessingalgorithm.cpp
  68. +37 −0 src/core/processing/qgsprocessingalgorithm.h
  69. +42 −0 src/core/processing/qgsprocessingprovider.cpp
  70. +71 −3 src/core/processing/qgsprocessingprovider.h
  71. +29 −0 src/core/processing/qgsprocessingregistry.cpp
  72. +17 −1 src/core/processing/qgsprocessingregistry.h
  73. +117 −0 tests/src/core/testqgsprocessing.cpp
@@ -2163,13 +2163,14 @@ 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().
getName() should be replaced with id(), getDescription() with name(), and getIcon with icon(). AlgorithmProvider was removed.
- Algorithm's processAlgorithm method now passes a QgsProcessingFeedback object instead of the loosely defined progress parameter. Algorithms will
need to update their use of the progress argument to utilize the QgsProcessingFeedback API.
- Similarly, Python processing scripts no longer have access to a progress variable for reporting their progress. Instead they have a feedback
object of type QgsProcessingFeedback, and will need to adapt their use of progress reporting to the QgsProcessingFeedback API.
- SilentProgress was removed. Use the base QgsProcessingFeedback class instead.

- algList was removed. Use QgsApplication.processingRegistry() instead.
- Processing.algs was removed. QgsApplication.processingRegistry().algorithms() instead.

Triangulation {#qgis_api_break_3_0_Triangulation}
-------------
@@ -9,6 +9,7 @@




class QgsProcessingAlgorithm
{
%Docstring
@@ -37,6 +38,8 @@ class QgsProcessingAlgorithm

virtual ~QgsProcessingAlgorithm();

// QgsProcessingAlgorithm &operator=( const QgsProcessingAlgorithm &other ) = delete;

virtual QString name() const = 0;
%Docstring
Returns the algorithm name, used for identifying the algorithm. This string
@@ -48,6 +51,14 @@ class QgsProcessingAlgorithm
\see tags()
%End

QString id() const;
%Docstring
Returns the unique ID for the algorithm, which is a combination of the algorithm
provider's ID and the algorithms unique name (e.g. "qgis:mergelayers" ).
\see name()
\see provider()
%End

virtual QString displayName() const = 0;
%Docstring
Returns the translated algorithm name, which should be used for any user-visible display
@@ -85,6 +96,13 @@ 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

private:
QgsProcessingAlgorithm( const QgsProcessingAlgorithm &other );
};
QFlags<QgsProcessingAlgorithm::Flag> operator|(QgsProcessingAlgorithm::Flag f1, QFlags<QgsProcessingAlgorithm::Flag> f2);

@@ -9,7 +9,7 @@



class QgsProcessingProvider
class QgsProcessingProvider : QObject
{
%Docstring
Abstract base class for processing providers. An algorithm provider is a set of
@@ -24,7 +24,7 @@ class QgsProcessingProvider

public:

QgsProcessingProvider();
QgsProcessingProvider( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsProcessingProvider.
%End
@@ -64,6 +64,12 @@ class QgsProcessingProvider
%Docstring
Returns true if the provider can be activated, or false if it cannot be activated (e.g. due to
missing external dependencies).
\see isActive()
%End

virtual bool isActive() const;
%Docstring
Returns true if the provider is active and able to run algorithms.
%End

virtual QStringList supportedOutputRasterLayerExtensions() const;
@@ -95,6 +101,63 @@ 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 individually load any algorithms in their load() implementations, as that must
occur within the loadAlgorithms() method. Instead, subclasses should call refreshAlgorithms()
from any overloaded load() method to trigger an initial load of the provider's algorithms.
\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< const QgsProcessingAlgorithm * > algorithms() const;
%Docstring
Returns a list of algorithms supplied by this provider.
\see algorithm()
%End

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

signals:

void algorithmsLoaded();
%Docstring
Emitted when the provider has loaded (or refreshed) its list of available
algorithms.
\see refreshAlgorithms()
%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 );
};
@@ -42,9 +42,12 @@ class QgsProcessingRegistry : QObject

bool addProvider( QgsProcessingProvider *provider /Transfer/ );
%Docstring
Add a processing provider to the registry. Ownership of the provider is transferred to the registry.
Add a processing provider to the registry. Ownership of the provider is transferred to the registry,
and the provider's parent will be set to the registry.
Returns false if the provider could not be added (eg if a provider with a duplicate ID already exists
in the registry).
Adding a provider to the registry automatically triggers the providers QgsProcessingProvider.load()
method to populate the provider with algorithms.
\see removeProvider()
%End

@@ -67,6 +70,19 @@ class QgsProcessingRegistry : QObject
Returns a matching provider by provider ID.
%End

QList< const QgsProcessingAlgorithm *> algorithms() const;
%Docstring
Returns a list of all available algorithms from registered providers.
\see algorithmById()
%End

const QgsProcessingAlgorithm *algorithmById( const QString &id ) const;
%Docstring
Finds an algorithm by its ID. If no matching algorithm is found, a None
is returned.
\see algorithms()
%End

signals:

void providerAdded( const QString &id );
@@ -46,7 +46,6 @@
from processing.modeler.ModelerDialog import ModelerDialog
from processing.tools.system import tempFolder
from processing.gui.menus import removeMenus, initializeMenus, createMenus
from processing.core.alglist import algList
from processing.core.ProcessingResults import resultsList

cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
@@ -164,6 +163,7 @@ def unload(self):
self.iface.unregisterOptionsWidgetFactory(self.options_factory)

removeMenus()
Processing.deinitialize()

def openCommander(self):
if self.commander is None:
@@ -185,7 +185,8 @@ def openModeler(self):
dlg.show()

def updateModel(self):
algList.reloadProvider('model')
model_provider = QgsApplication.processingRegistry().providerById('model')
model_provider.refreshAlgorithms()

def openResults(self):
if self.resultsDock.isVisible():
@@ -25,66 +25,67 @@

__revision__ = '$Format:%H$'

from processing.core.AlgorithmProvider import AlgorithmProvider
from qgis.core import QgsProcessingProvider
from processing.core.ProcessingConfig import Setting, ProcessingConfig
from exampleprovider.ExampleAlgorithm import ExampleAlgorithm


class ExampleAlgorithmProvider(AlgorithmProvider):
class ExampleAlgorithmProvider(QgsProcessingProvider):

MY_DUMMY_SETTING = 'MY_DUMMY_SETTING'

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

# 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)
ProcessingConfig.settingIcons[self.name()] = self.icon()
# Deactivate provider by default
ProcessingConfig.addSetting(Setting(self.name(), 'ACTIVATE_EXAMPLE',
'Activate', False))
ProcessingConfig.addSetting(Setting('Example algorithms',
ExampleAlgorithmProvider.MY_DUMMY_SETTING,
'Example setting', 'Default value'))
ProcessingConfig.readSettings()
self.refreshAlgorithms()
return True

def unload(self):
"""Setting should be removed here, so they do not appear anymore
when the plugin is unloaded.
"""
AlgorithmProvider.unload(self)
ProcessingConfig.removeSetting('ACTIVATE_EXAMPLE')
ProcessingConfig.removeSetting(
ExampleAlgorithmProvider.MY_DUMMY_SETTING)

def isActive(self):
"""Return True if the provider is activated and ready to run algorithms"""
return ProcessingConfig.getSetting('ACTIVATE_EXAMPLE')

def setActive(self, active):
ProcessingConfig.setSettingValue('ACTIVATE_EXAMPLE', active)

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'
return 'example'

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

def icon(self):
"""We return the default icon.
"""
return AlgorithmProvider.icon(self)
return QgsProcessingProvider.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 +99,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)
@@ -30,6 +30,7 @@
import sys
import inspect

from qgis.core import QgsApplication
from processing.core.Processing import Processing
from exampleprovider.ExampleAlgorithmProvider import ExampleAlgorithmProvider

@@ -45,7 +46,7 @@ def __init__(self):
self.provider = ExampleAlgorithmProvider()

def initGui(self):
Processing.addProvider(self.provider)
QgsApplication.processingRegistry().addProvider(self.provider)

def unload(self):
Processing.removeProvider(self.provider)
QgsApplication.processingRegistry().removeProvider(self.provider)
Loading

0 comments on commit 2adccb9

Please sign in to comment.