Skip to content
Permalink
Browse files

Move execution check to QgsProcessingAlgorithm

  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent 03e40f7 commit fac8ca4d4f547f9af678b31cb5e16597f69c5e4a
@@ -104,6 +104,15 @@ class QgsProcessingAlgorithm
:rtype: Flags
%End

virtual bool canExecute( QString *errorMessage /Out/ = 0 ) const;
%Docstring
Returns true if the algorithm can execute. Algorithm subclasses can return false
here to indicate that they are not able to execute, e.g. as a result of unmet
external dependencies. If specified, the ``errorMessage`` argument will be filled
with a localised error message describing why the algorithm cannot execute.
:rtype: bool
%End

QgsProcessingProvider *provider() const;
%Docstring
Returns the provider to which this algorithm belongs.
@@ -572,8 +572,9 @@ def exportRasterLayer(self, layer):
def getTempFilename(self):
return system.getTempFilename()

def checkBeforeOpeningParametersDialog(self):
return Grass7Utils.checkGrass7IsInstalled()
def canExecute(self):
message = Grass7Utils.checkGrass7IsInstalled()
return not message, message

def checkParameterValuesBeforeExecuting(self):
if self.module:
@@ -130,20 +130,6 @@ def getParameterDescriptions(self):
descs = {}
return descs

def checkBeforeOpeningParametersDialog(self):
"""If there is any check to perform before the parameters
dialog is opened, it should be done here.
This method returns an error message string if there is any
problem (for instance, an external app not configured yet),
or None if the parameters dialog can be opened.
Note that this check should also be done in the
processAlgorithm method, since algorithms can be called without
opening the parameters dialog.
"""
return None

def checkParameterValuesBeforeExecuting(self):
"""If there is any check to do before launching the execution
of the algorithm, it should be done here.
@@ -255,8 +255,8 @@ def executeAlgorithm(self):
if isinstance(item, TreeAlgorithmItem):
context = dataobjects.createContext()
alg = QgsApplication.processingRegistry().algorithmById(item.alg.id())
message = alg.checkBeforeOpeningParametersDialog()
if message:
ok, message = alg.canExecute()
if not ok:
dlg = MessageDialog()
dlg.setTitle(self.tr('Error executing algorithm'))
dlg.setMessage(
@@ -193,8 +193,8 @@ def removeAlgorithmEntry(alg, menuName, submenuName, actionText=None, delButton=


def _executeAlgorithm(alg):
message = alg.checkBeforeOpeningParametersDialog()
if message:
ok, message = alg.canExecute()
if not ok:
dlg = MessageDialog()
dlg.setTitle(Processing.tr('Missing dependency'))
dlg.setMessage(
@@ -525,11 +525,12 @@ def getAsCommand(self):
else:
return None

def checkBeforeOpeningParametersDialog(self):
def canExecute(self):
for alg in list(self.algs.values()):
algInstance = QgsApplication.processingRegistry().algorithmById(alg.consoleName)
if algInstance is None:
return self.tr("The model you are trying to run contains an algorithm that is not available: <i>{0}</i>").format(alg.consoleName)
return False, self.tr("The model you are trying to run contains an algorithm that is not available: <i>{0}</i>").format(alg.consoleName)
return True, None

def setModelerView(self, dialog):
self.modelerdialog = dialog
@@ -122,8 +122,8 @@ def defineCharacteristicsFromScript(self):
except:
pass

def checkBeforeOpeningParametersDialog(self):
return self.error
def canExecute(self):
return not self.error, self.error

def checkInputCRS(self):
if self.noCRSWarning:
@@ -49,6 +49,11 @@ QgsProcessingAlgorithm::Flags QgsProcessingAlgorithm::flags() const
return FlagSupportsBatch;
}

bool QgsProcessingAlgorithm::canExecute( QString * ) const
{
return true;
}

QgsProcessingProvider *QgsProcessingAlgorithm::provider() const
{
return mProvider;
@@ -117,6 +117,14 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
virtual Flags flags() const;

/**
* Returns true if the algorithm can execute. Algorithm subclasses can return false
* here to indicate that they are not able to execute, e.g. as a result of unmet
* external dependencies. If specified, the \a errorMessage argument will be filled
* with a localised error message describing why the algorithm cannot execute.
*/
virtual bool canExecute( QString *errorMessage SIP_OUT = nullptr ) const;

/**
* Returns the provider to which this algorithm belongs.
*/

0 comments on commit fac8ca4

Please sign in to comment.
You can’t perform that action at this time.