Ejemplo n.º 1
0
    def runModel(self):
        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', {}))
            self.setLastRunChildAlgorithmInputs(dlg.results().get('CHILD_INPUTS', {}))

        dlg = AlgorithmDialog(self.model().create(), parent=self)
        dlg.setParameters(self.model().designerParameterValues())
        dlg.algorithmFinished.connect(on_finished)
        dlg.exec_()

        if dlg.wasExecuted():
            self.model().setDesignerParameterValues(dlg.createProcessingParameters(include_default=False))
Ejemplo n.º 2
0
    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

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

        dlg = AlgorithmDialog(self.model().create(), parent=self)
        dlg.setParameters(self.model().designerParameterValues())
        dlg.algorithmFinished.connect(on_finished)
        dlg.exec_()

        if dlg.wasExecuted():
            self.model().setDesignerParameterValues(dlg.createProcessingParameters())