Skip to content

Commit

Permalink
[processing] Show warnings in model designer message bar if algorithm
Browse files Browse the repository at this point in the history
definition is incomplete/invalid after editing a child algorithm
  • Loading branch information
nyalldawson committed Apr 14, 2020
1 parent 0abc386 commit 2dc07ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -317,10 +317,17 @@ def addAlgorithm(self, alg_id, pos=None):
output_offset_y += 1.5 * alg.modelOutput(out).size().height()

self.beginUndoCommand(self.tr('Add Algorithm'))
self.model().addChildAlgorithm(alg)
id = self.model().addChildAlgorithm(alg)
self.repaintModel()
self.endUndoCommand()

res, errors = self.model().validateChildAlgorithm(id)
if not res:
self.view().scene().showWarning(self.tr('Algorithm “{}” is invalid').format(alg.description()), self.tr('Algorithm is Invalid'), self.tr(
"<p>The “{}” algorithm is invalid, because:</p><ul><li>{}</li></ul>").format(alg.description(), '</li><li>'.join(errors)), level=Qgis.Warning)
else:
self.view().scene().messageBar().clearWidgets()

def getPositionForAlgorithmItem(self):
MARGIN = 20
BOX_WIDTH = 200
Expand Down
10 changes: 9 additions & 1 deletion python/plugins/processing/modeler/ModelerGraphicItem.py
Expand Up @@ -22,7 +22,8 @@
__copyright__ = '(C) 2012, Victor Olaya'

from qgis.core import (QgsProcessingParameterDefinition,
QgsProject)
QgsProject,
Qgis)
from qgis.gui import (
QgsProcessingParameterDefinitionDialog,
QgsProcessingParameterWidgetContext,
Expand Down Expand Up @@ -143,6 +144,13 @@ def edit(self, edit_comment=False):
self.requestModelRepaint.emit()
self.changed.emit()

res, errors = self.model().validateChildAlgorithm(alg.childId())
if not res:
self.scene().showWarning(self.tr('Algorithm “{}” is invalid').format(alg.description()), self.tr('Algorithm is Invalid'), self.tr(
"<p>The “{}” algorithm is invalid, because:</p><ul><li>{}</li></ul>").format(alg.description(), '</li><li>'.join(errors)), level=Qgis.Warning)
else:
self.scene().messageBar().clearWidgets()

def editComponent(self):
self.edit()

Expand Down

0 comments on commit 2dc07ee

Please sign in to comment.