Skip to content

Commit

Permalink
[processing] Fix executing models
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 1, 2017
1 parent dde48b5 commit ac84326
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions python/core/processing/qgsprocessingalgorithm.sip
Expand Up @@ -110,6 +110,8 @@ class QgsProcessingAlgorithm
:rtype: QgsProcessingProvider
%End

void setProvider( QgsProcessingProvider *provider );

private:
QgsProcessingAlgorithm( const QgsProcessingAlgorithm &other );
};
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -131,7 +131,11 @@ 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
2 changes: 2 additions & 0 deletions python/plugins/processing/gui/BatchAlgorithmDialog.py
Expand Up @@ -73,6 +73,8 @@ def accept(self):

for row in range(self.mainWidget.tblParameters.rowCount()):
alg = self.alg.getCopy()
# hack - remove when getCopy is removed
alg.setProvider(self.alg.provider())
col = 0
for param in alg.parameters:
if param.hidden:
Expand Down
9 changes: 9 additions & 0 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -242,7 +242,11 @@ 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 @@ -261,7 +265,12 @@ def executeAlgorithm(self):
'be run :-( </h3>\n{0}').format(message))
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.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0:
dlg = alg.getCustomParametersDialog()
if not dlg:
Expand Down
6 changes: 6 additions & 0 deletions python/plugins/processing/gui/menus.py
Expand Up @@ -202,7 +202,13 @@ def _executeAlgorithm(alg):
'be run :-( </h3>\n{0}').format(message))
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.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0:
dlg = alg.getCustomParametersDialog()
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/modeler/EditModelAction.py
Expand Up @@ -40,7 +40,10 @@ def isEnabled(self):
return isinstance(self.itemData, ModelerAlgorithm)

def execute(self):
dlg = ModelerDialog(self.itemData.getCopy())
alg = self.itemData.getCopy()
#hack - remove when getCopy is removed
alg.setProvider(self.itemData.provider())
dlg = ModelerDialog(alg)
dlg.update_model.connect(self.updateModel)
dlg.show()

Expand Down
4 changes: 4 additions & 0 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -282,7 +282,11 @@ 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.exec_()

Expand Down
5 changes: 3 additions & 2 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -118,13 +118,14 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsProcessingProvider *provider() const;

private:

/**
* 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 );

private:

QgsProcessingProvider *mProvider = nullptr;

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

0 comments on commit ac84326

Please sign in to comment.