Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Validate models before running from designer, showing a summary of is…
…sues
  • Loading branch information
nyalldawson committed Apr 14, 2020
1 parent b9a9989 commit acc6844
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -23,6 +23,7 @@

import sys
import os
import re

from qgis.PyQt.QtCore import (
QCoreApplication,
Expand Down Expand Up @@ -114,11 +115,23 @@ def editHelp(self):
self.endUndoCommand()

def runModel(self):
if len(self.model().childAlgorithms()) == 0:
self.messageBar().pushMessage("", self.tr(
"Model doesn't contain any algorithm and/or parameter and can't be executed"), level=Qgis.Warning,
duration=5)
return
valid, errors = self.model().validate()
if not valid:
message_box = QMessageBox()
message_box.setWindowTitle(self.tr('Model is Invalid'))
message_box.setIcon(QMessageBox.Warning)
message_box.setText(self.tr('This model is not valid and contains one or more issues. Are you sure you want to run it in this state?'))
message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel)
message_box.setDefaultButton(QMessageBox.Cancel)

error_string = ''
for e in errors:
e = re.sub(r'<[^>]*>', '', e)
error_string += '• {}\n'.format(e)

message_box.setDetailedText(error_string)
if message_box.exec_() == QMessageBox.Cancel:
return

def on_finished(successful, results):
self.setLastRunChildAlgorithmResults(dlg.results().get('CHILD_RESULTS', {}))
Expand Down

0 comments on commit acc6844

Please sign in to comment.