Skip to content

Commit

Permalink
Remove processing algList
Browse files Browse the repository at this point in the history
All functionality has been moved to QgsProcessingRegistry
  • Loading branch information
nyalldawson committed Apr 7, 2017
1 parent 4970bb4 commit fb1cf1e
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 106 deletions.
1 change: 1 addition & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,7 @@ need to update their use of the progress argument to utilize the QgsProcessingFe
- 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}
Expand Down
13 changes: 11 additions & 2 deletions python/core/processing/qgsprocessingprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



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

public:

QgsProcessingProvider();
QgsProcessingProvider( QObject* parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsProcessingProvider.
%End
Expand Down Expand Up @@ -129,6 +129,15 @@ class QgsProcessingProvider
\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;
Expand Down
5 changes: 3 additions & 2 deletions python/core/processing/qgsprocessingregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ 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).
\see removeProvider()
Expand Down Expand Up @@ -73,7 +74,7 @@ class QgsProcessingRegistry : QObject
\see algorithmById()
%End

QgsProcessingAlgorithm * algorithmById( const QString& id ) const;
QgsProcessingAlgorithm *algorithmById( const QString &id ) const;
%Docstring
Finds an algorithm by its ID. If no matching algorithm is found, a nullptr
is returned.
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/ProcessingPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -185,7 +184,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():
Expand Down
27 changes: 5 additions & 22 deletions python/plugins/processing/core/Processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.gui.AlgorithmExecutor import execute
from processing.tools import dataobjects
from processing.core.alglist import algList

from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider # NOQA
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
Expand All @@ -67,7 +66,6 @@

class Processing(object):

# Same structure as algs in algList
actions = {}

# All the registered context menu actions for the toolbox
Expand Down Expand Up @@ -115,7 +113,9 @@ def activateProvider(providerOrName, activate=True):
provider_id = providerOrName.id() if isinstance(providerOrName, AlgorithmProvider) else providerOrName
name = 'ACTIVATE_' + provider_id.upper().replace(' ', '_')
ProcessingConfig.setSettingValue(name, activate)
algList.providerUpdated.emit(provider_id)
provider = QgsApplication.processingRegistry().providerById(provider_id)
if provider:
provider.refreshAlgorithms()

@staticmethod
def initialize():
Expand All @@ -128,7 +128,6 @@ def initialize():
ProcessingConfig.initialize()
ProcessingConfig.readSettings()
RenderingStyles.loadStyles()
Processing.updateAlgsList()

@staticmethod
def addScripts(folder):
Expand All @@ -142,7 +141,7 @@ def addScripts(folder):
script._icon = provider._icon
script.provider = provider
provider.externalAlgs.extend(scripts)
Processing.reloadProvider("qgis")
provider.refreshAlgorithms()

@staticmethod
def removeScripts(folder):
Expand All @@ -151,23 +150,7 @@ def removeScripts(folder):
path = os.path.dirname(alg.descriptionFile)
if path == folder:
provider.externalAlgs.remove(alg)
Processing.reloadProvider("qgis")

@staticmethod
def updateAlgsList():
"""Call this method when there has been any change that
requires the list of algorithms to be created again from
algorithm providers. Use reloadProvider() for a more fine-grained
update.
"""
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
for p in QgsApplication.processingRegistry().providers():
Processing.reloadProvider(p.id())
QApplication.restoreOverrideCursor()

@staticmethod
def reloadProvider(provider_id):
algList.reloadProvider(provider_id)
provider.refreshAlgorithms()


@staticmethod
Expand Down
44 changes: 0 additions & 44 deletions python/plugins/processing/core/alglist.py

This file was deleted.

12 changes: 9 additions & 3 deletions python/plugins/processing/gui/ConfigDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
QToolButton,
QHBoxLayout,
QComboBox,
QPushButton)
QPushButton,
QApplication)
from qgis.PyQt.QtGui import (QIcon,
QStandardItemModel,
QStandardItem)
QStandardItem,
QCursor)

from qgis.gui import (QgsDoubleSpinBox,
QgsSpinBox,
Expand Down Expand Up @@ -288,7 +290,11 @@ def accept(self):
return
setting.save(qsettings)

Processing.updateAlgsList()
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
for p in QgsApplication.processingRegistry().providers():
p.refreshAlgorithms()
QApplication.restoreOverrideCursor()

settingsWatcher.settingsChanged.emit()

def itemExpanded(self, idx):
Expand Down
7 changes: 4 additions & 3 deletions python/plugins/processing/gui/DeleteScriptAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@

from qgis.PyQt.QtWidgets import QMessageBox

from qgis.core import QgsApplication

from processing.gui.ContextAction import ContextAction

from processing.algs.r.RAlgorithm import RAlgorithm
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.core.alglist import algList


class DeleteScriptAction(ContextAction):
Expand Down Expand Up @@ -61,6 +62,6 @@ def execute(self):
if reply == QMessageBox.Yes:
os.remove(self.itemData.descriptionFile)
if self.scriptType == self.SCRIPT_PYTHON:
algList.reloadProvider('script')
QgsApplication.processingRegistry().providerById('script').refreshAlgorithms()
elif self.scriptType == self.SCRIPT_R:
algList.reloadProvider('r')
QgsApplication.processingRegistry().providerById('r').refreshAlgorithms()
5 changes: 2 additions & 3 deletions python/plugins/processing/gui/GetScriptsAndModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
QgsApplication)
from qgis.gui import QgsMessageBar

from processing.core.alglist import algList
from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.ToolboxAction import ToolboxAction
from processing.gui import Help2Html
Expand Down Expand Up @@ -77,7 +76,7 @@ def execute(self):
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.SCRIPTS)
dlg.exec_()
if dlg.updateProvider:
algList.reloadProvider('script')
QgsApplication.processingRegistry().providerById('script').refreshAlgorithms()


class GetRScriptsAction(ToolboxAction):
Expand Down Expand Up @@ -123,7 +122,7 @@ def execute(self):
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.MODELS)
dlg.exec_()
if dlg.updateProvider:
algList.reloadProvider('model')
QgsApplication.processingRegistry().providerById('model').refreshAlgorithms()


class GetScriptsAndModelsDialog(BASE, WIDGET):
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/gui/ProcessingToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from processing.gui.ConfigDialog import ConfigDialog
from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.AlgorithmExecutor import execute
from processing.core.alglist import algList

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
Expand Down Expand Up @@ -85,7 +84,6 @@ def openSettings(url):

QgsApplication.processingRegistry().providerRemoved.connect(self.removeProvider)
QgsApplication.processingRegistry().providerAdded.connect(self.addProvider)
algList.providerUpdated.connect(self.updateProvider)
settingsWatcher.settingsChanged.connect(self.fillTree)

def showDisabled(self):
Expand Down Expand Up @@ -165,8 +163,9 @@ def activateProvider(self, id):
QMessageBox.warning(self, "Activate provider",
"The provider has been activated, but it might need additional configuration.")

def updateProvider(self, provider_id):
item = self._providerItem(provider_id)
def updateProvider(self):
provider = self.sender()
item = self._providerItem(provider.id())
if item is not None:
item.refresh()
item.sortChildren(0, Qt.AscendingOrder)
Expand Down Expand Up @@ -329,6 +328,7 @@ def addProvider(self, provider_id):
if child.text(0) > providerItem.text(0):
break
self.algorithmTree.insertTopLevelItem(i, providerItem)
provider.algorithmsLoaded.connect(self.updateProvider)

def fillTreeUsingProviders(self):
self.algorithmTree.clear()
Expand Down
5 changes: 2 additions & 3 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from processing.algs.r.RUtils import RUtils
from processing.script.ScriptAlgorithm import ScriptAlgorithm
from processing.script.ScriptUtils import ScriptUtils
from processing.core.alglist import algList

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
Expand Down Expand Up @@ -178,9 +177,9 @@ def closeEvent(self, evt):
def updateProviders(self):
if self.update:
if self.algType == self.SCRIPT_PYTHON:
algList.reloadProvider('script')
QgsApplication.processingRegistry().providerById('script').refreshAlgorithms()
elif self.algType == self.SCRIPT_R:
algList.reloadProvider('r')
QgsApplication.processingRegistry().providerById('r').refreshAlgorithms()

def editHelp(self):
if self.alg is None:
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/modeler/AddModelFromFileAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
from processing.modeler.WrongModelException import WrongModelException
from processing.modeler.ModelerUtils import ModelerUtils
from processing.core.alglist import algList

pluginPath = os.path.split(os.path.dirname(__file__))[0]

Expand Down Expand Up @@ -75,4 +74,4 @@ def execute(self):
return
destFilename = os.path.join(ModelerUtils.modelsFolders()[0], os.path.basename(filename))
shutil.copyfile(filename, destFilename)
algList.reloadProvider('model')
QgsApplication.processingRegistry().providerById('model').refreshAlgorithms()
3 changes: 1 addition & 2 deletions python/plugins/processing/modeler/CreateNewModelAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from processing.gui.ToolboxAction import ToolboxAction
from processing.modeler.ModelerDialog import ModelerDialog
from processing.core.alglist import algList

pluginPath = os.path.split(os.path.dirname(__file__))[0]

Expand All @@ -51,4 +50,4 @@ def execute(self):
dlg.show()

def updateModel(self):
algList.reloadProvider('model')
QgsApplication.processingRegistry().providerById('model').refreshAlgorithms()
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/DeleteModelAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
__revision__ = '$Format:%H$'

import os
from qgis.core import QgsApplication
from qgis.PyQt.QtWidgets import QMessageBox
from processing.gui.ContextAction import ContextAction
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
from processing.core.alglist import algList


class DeleteModelAction(ContextAction):
Expand All @@ -49,4 +49,4 @@ def execute(self):
QMessageBox.No)
if reply == QMessageBox.Yes:
os.remove(self.itemData.descriptionFile)
algList.reloadProvider('model')
QgsApplication.processingRegistry().providerById('model').refreshAlgorithms()
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/EditModelAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

__revision__ = '$Format:%H$'

from qgis.core import QgsApplication
from processing.gui.ContextAction import ContextAction
from processing.modeler.ModelerAlgorithm import ModelerAlgorithm
from processing.modeler.ModelerDialog import ModelerDialog
from processing.core.alglist import algList


class EditModelAction(ContextAction):
Expand All @@ -45,4 +45,4 @@ def execute(self):
dlg.show()

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

0 comments on commit fb1cf1e

Please sign in to comment.