Skip to content

Commit

Permalink
[processing] Remove all remaining algorithm copies
Browse files Browse the repository at this point in the history
Algorithms are no longer copied - just a single const instance
of each algorithm is used
  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent 8b4bf88 commit 03e40f7
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 94 deletions.
2 changes: 0 additions & 2 deletions python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -110,8 +110,6 @@ class QgsProcessingAlgorithm
:rtype: QgsProcessingProvider
%End

void setProvider( QgsProcessingProvider *provider );

QgsProcessingParameterDefinitions parameterDefinitions() const;
%Docstring
Returns an ordered list of parameter definitions utilized by the algorithm.
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/algs/gdal/GdalAlgorithm.py
Expand Up @@ -92,12 +92,11 @@ def shortHelp(self):
'''.format(self.commandName(), url))

def commandName(self):
alg = self.getCopy()
for output in alg.outputs:
for output in self.outputs:
output.setValue("dummy")
for param in alg.parameters:
for param in self.parameters:
param.setValue("1")
name = alg.getConsoleCommands()[0]
name = self.getConsoleCommands()[0]
if name.endswith(".py"):
name = name[:-3]
return name
3 changes: 0 additions & 3 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -97,9 +97,6 @@ def __init__(self, descriptionfile):
except ImportError:
self.module = None

def getCopy(self):
return self

def name(self):
return self._name

Expand Down
3 changes: 0 additions & 3 deletions python/plugins/processing/algs/saga/SagaAlgorithm.py
Expand Up @@ -78,9 +78,6 @@ def __init__(self, descriptionfile):
self._display_name = ''
self._group = ''

def getCopy(self):
return self

def icon(self):
if self._icon is None:
self._icon = QIcon(os.path.join(pluginPath, 'images', 'saga.png'))
Expand Down
9 changes: 0 additions & 9 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -74,15 +74,6 @@ def __init__(self):

self.defineCharacteristics()

def getCopy(self):
"""Returns a new instance of this algorithm, ready to be used
for being executed.
"""
newone = self
newone.parameters = copy.deepcopy(self.parameters)
newone.outputs = copy.deepcopy(self.outputs)
return newone

# methods to overwrite when creating a custom geoalgorithm

def _formatHelp(self, text):
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -130,11 +130,6 @@ def runAlgorithm(algOrName, onFinish, *args, **kwargs):
QgsMessageLog.logMessage(Processing.tr('Error: Algorithm {0} not found\n').format(algOrName),
Processing.tr("Processing"))
return
# hack - remove when getCopy is removed
provider = alg.provider()
alg = alg.getCopy()
#hack pt2
alg.setProvider(provider)

if len(args) == 1 and isinstance(args[0], dict):
# Set params by name and try to run the alg even if not all parameter values are provided,
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/processing/gui/BatchAlgorithmDialog.py
Expand Up @@ -72,9 +72,7 @@ def accept(self):
self.canceled = False

for row in range(self.mainWidget.tblParameters.rowCount()):
alg = self.alg.getCopy()
# hack - remove when getCopy is removed
alg.setProvider(self.alg.provider())
alg = self.alg
col = 0
for param in alg.parameters:
if param.hidden:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -182,7 +182,7 @@ def save(self):
algParams = {}
algOutputs = {}
col = 0
alg = self.alg.getCopy()
alg = self.alg
for param in alg.parameters:
if param.hidden:
continue
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/EditRenderingStylesDialog.py
Expand Up @@ -48,7 +48,7 @@ def __init__(self, alg):
super(EditRenderingStylesDialog, self).__init__(None)
self.setupUi(self)

self.alg = alg.getCopy()
self.alg = alg

self.tblStyles.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.setWindowTitle(self.alg.displayName())
Expand Down
10 changes: 0 additions & 10 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -246,11 +246,6 @@ def executeAlgorithmAsBatchProcess(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = QgsApplication.processingRegistry().algorithmById(item.alg.id())
#hack - remove when getCopy is removed
provider = alg.provider()
alg = alg.getCopy()
#hack pt 2
alg.setProvider(provider)
dlg = BatchAlgorithmDialog(alg)
dlg.show()
dlg.exec_()
Expand All @@ -270,11 +265,6 @@ def executeAlgorithm(self):
dlg.exec_()
return

# temporary hack - TODO remove this getCopy when parameters are moved from algorithm
provider = alg.provider()
alg = alg.getCopy()
alg.setProvider(provider)

if (alg.countVisibleParameters() + alg.getVisibleOutputsCount()) > 0:
dlg = alg.getCustomParametersDialog()
if not dlg:
Expand Down
6 changes: 0 additions & 6 deletions python/plugins/processing/gui/menus.py
Expand Up @@ -203,12 +203,6 @@ def _executeAlgorithm(alg):
dlg.exec_()
return

# hack - remove when getCopy is removed
provider = alg.provider()
alg = alg.getCopy()
#hack pt 2
alg.setProvider(provider)

context = dataobjects.createContext()
if (alg.countVisibleParameters() + alg.getVisibleOutputsCount()) > 0:
dlg = alg.getCustomParametersDialog()
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/processing/modeler/EditModelAction.py
Expand Up @@ -40,9 +40,7 @@ def isEnabled(self):
return isinstance(self.itemData, ModelerAlgorithm)

def execute(self):
alg = self.itemData.getCopy()
#hack - remove when getCopy is removed
alg.setProvider(self.itemData.provider())
alg = self.itemData
dlg = ModelerDialog(alg)
dlg.update_model.connect(self.updateModel)
dlg.show()
Expand Down
15 changes: 0 additions & 15 deletions python/plugins/processing/modeler/ModelerAlgorithm.py
Expand Up @@ -225,21 +225,6 @@ class ModelerAlgorithm(GeoAlgorithm):

CANVAS_SIZE = 4000

def getCopy(self):
newone = ModelerAlgorithm()

newone.algs = {}
for algname, alg in self.algs.items():
newone.algs[algname] = Algorithm()
newone.algs[algname].__dict__.update(copy.deepcopy(alg.todict()))
newone.inputs = copy.deepcopy(self.inputs)
newone.defineCharacteristics()
newone._name = self._name
newone._group = self._group
newone.descriptionFile = self.descriptionFile
newone.helpContent = copy.deepcopy(self.helpContent)
return newone

def __init__(self):
self._name = self.tr('Model', 'ModelerAlgorithm')
# The dialog where this model is being edited
Expand Down
13 changes: 4 additions & 9 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -112,7 +112,7 @@ def _dropEvent(event):
else:
alg = QgsApplication.processingRegistry().algorithmById(text)
if alg is not None:
self._addAlgorithm(alg.getCopy(), event.pos())
self._addAlgorithm(alg, event.pos())
event.accept()
else:
event.ignore()
Expand Down Expand Up @@ -269,7 +269,7 @@ def closeEvent(self, evt):
evt.accept()

def editHelp(self):
alg = self.alg.getCopy()
alg = self.alg
dlg = HelpEditionDialog(alg)
dlg.exec_()
if dlg.descriptions:
Expand All @@ -281,12 +281,7 @@ def runModel(self):
self.bar.pushMessage("", "Model doesn't contain any algorithm and/or parameter and can't be executed", level=QgsMessageBar.WARNING, duration=5)
return

# hack - remove when above getCopy is removed
provider = self.alg.provider()
alg = self.alg.getCopy()
# hack pt 2
alg.setProvider(provider)
dlg = AlgorithmDialog(alg)
dlg = AlgorithmDialog(self.alg)
dlg.exec_()

def save(self):
Expand Down Expand Up @@ -554,7 +549,7 @@ def addAlgorithm(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = QgsApplication.processingRegistry().algorithmById(item.alg.id())
self._addAlgorithm(alg.getCopy())
self._addAlgorithm(alg)

def _addAlgorithm(self, alg, pos=None):
dlg = alg.getCustomModelerParametersDialog(self.alg)
Expand Down
Expand Up @@ -42,6 +42,6 @@ def isEnabled(self):
not isinstance(self.itemData, PreconfiguredAlgorithm))

def execute(self):
alg = self.itemData.getCopy() # make copy so we do not taint the original one in the dialog
alg = self.itemData
dlg = PreconfiguredAlgorithmDialog(alg, self.toolbox)
dlg.exec_()
Expand Up @@ -55,19 +55,12 @@ def name(self):
def flags(self):
return QgsProcessingAlgorithm.FlagHideFromModeler

def getCopy(self):
newone = self
newone.outputs = []
newone._name = self._name
newone._group = self._group
return newone

def defineCharacteristics(self):
self._name = self.description["name"]
self._group = self.description["group"]

def execute(self, context=None, feedback=None, model=None):
self.alg = QgsApplication.processingRegistry().algorithmById(self.description["algname"]).getCopy()
self.alg = QgsApplication.processingRegistry().algorithmById(self.description["algname"])
for name, value in list(self.description["parameters"].items()):
self.alg.setParameterValue(name, value)
for name, value in list(self.description["outputs"].items()):
Expand Down
4 changes: 0 additions & 4 deletions python/plugins/processing/script/ScriptAlgorithm.py
Expand Up @@ -72,10 +72,6 @@ def __init__(self, descriptionFile, script=None):
if descriptionFile is not None:
self.defineCharacteristicsFromFile()

def getCopy(self):
newone = self
return newone

def icon(self):
return self._icon

Expand Down
1 change: 0 additions & 1 deletion python/plugins/processing/tools/general.py
Expand Up @@ -63,7 +63,6 @@ def algorithmHelp(id):
"""
alg = QgsApplication.processingRegistry().algorithmById(id)
if alg is not None:
alg = alg.getCopy()
print(str(alg))
algorithmOptions(id)
else:
Expand Down
11 changes: 5 additions & 6 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -122,12 +122,6 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsProcessingProvider *provider() const;

/**
* Associates this algorithm with its provider. No transfer of ownership is involved.
*/
//TEMPORARY - remove when algorithms are no longer copied in python code
void setProvider( QgsProcessingProvider *provider );

/**
* Returns an ordered list of parameter definitions utilized by the algorithm.
* \see addParameter()
Expand Down Expand Up @@ -282,6 +276,11 @@ class CORE_EXPORT QgsProcessingAlgorithm
QgsProcessingProvider *mProvider = nullptr;
QgsProcessingParameterDefinitions mParameters;

/**
* Associates this algorithm with its provider. No transfer of ownership is involved.
*/
void setProvider( QgsProcessingProvider *provider );

// friend class to access setProvider() - we do not want this public!
friend class QgsProcessingProvider;
friend class TestQgsProcessing;
Expand Down

0 comments on commit 03e40f7

Please sign in to comment.