Exemplo n.º 1
0
    def addAlgorithm(self, alg_id, pos=None):
        alg = QgsApplication.processingRegistry().createAlgorithmById(alg_id)
        if not alg:
            return

        dlg = ModelerParametersDialog(alg, self.model())
        if dlg.exec_():
            alg = dlg.createAlgorithm()
            if pos is None or not pos:
                alg.setPosition(self.getPositionForAlgorithmItem())
            else:
                alg.setPosition(pos)

            alg.comment().setPosition(alg.position() + QPointF(
                alg.size().width(),
                -1.5 * alg.size().height()))

            output_offset_x = alg.size().width()
            output_offset_y = 1.5 * alg.size().height()
            for out in alg.modelOutputs():
                alg.modelOutput(out).setPosition(alg.position() + QPointF(output_offset_x, output_offset_y))
                output_offset_y += 1.5 * alg.modelOutput(out).size().height()

            self.beginUndoCommand(self.tr('Add Algorithm'))
            self.model().addChildAlgorithm(alg)
            self.repaintModel()
            self.endUndoCommand()
Exemplo n.º 2
0
    def edit(self, edit_comment=False):
        elemAlg = self.component().algorithm()
        dlg = ModelerParametersDialog(elemAlg, self.model(),
                                      self.component().childId(),
                                      self.component().configuration())
        dlg.setComments(self.component().comment().description())
        dlg.setCommentColor(self.component().comment().color())
        if edit_comment:
            dlg.switchToCommentTab()
        if dlg.exec_():
            alg = dlg.createAlgorithm()
            alg.setChildId(self.component().childId())
            alg.copyNonDefinitionPropertiesFromModel(self.model())
            self.aboutToChange.emit(
                self.tr('Edit {}').format(alg.description()))
            self.model().setChildAlgorithm(alg)
            self.requestModelRepaint.emit()
            self.changed.emit()

            res, errors = self.model().validateChildAlgorithm(alg.childId())
            if not res:
                self.scene().showWarning(
                    QCoreApplication.translate(
                        'ModelerGraphicItem',
                        'Algorithm “{}” is invalid').format(alg.description()),
                    self.tr('Algorithm is Invalid'),
                    QCoreApplication.translate(
                        'ModelerGraphicItem',
                        "<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()
Exemplo n.º 3
0
 def _addAlgorithm(self, alg, pos=None):
     dlg = ModelerParametersDialog(alg, self.model)
     if dlg.exec_():
         alg = dlg.createAlgorithm()
         if pos is None:
             alg.setPosition(self.getPositionForAlgorithmItem())
         else:
             alg.setPosition(pos)
         from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
         for i, out in enumerate(alg.modelOutputs()):
             alg.modelOutput(out).setPosition(alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
                                                                       ModelerGraphicItem.BOX_HEIGHT))
         self.model.addChildAlgorithm(alg)
         self.repaintModel()
         self.hasChanged = True
Exemplo n.º 4
0
 def _addAlgorithm(self, alg, pos=None):
     dlg = ModelerParametersDialog(alg, self.model)
     if dlg.exec_():
         alg = dlg.createAlgorithm()
         if pos is None:
             alg.setPosition(self.getPositionForAlgorithmItem())
         else:
             alg.setPosition(pos)
         from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
         for i, out in enumerate(alg.modelOutputs()):
             alg.modelOutput(out).setPosition(alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
                                                                       ModelerGraphicItem.BOX_HEIGHT))
         self.model.addChildAlgorithm(alg)
         self.repaintModel()
         self.hasChanged = True
Exemplo n.º 5
0
 def edit(self, edit_comment=False):
     elemAlg = self.component().algorithm()
     dlg = ModelerParametersDialog(elemAlg, self.model(),
                                   self.component().childId(),
                                   self.component().configuration())
     dlg.setComments(self.component().comment().description())
     if edit_comment:
         dlg.switchToCommentTab()
     if dlg.exec_():
         alg = dlg.createAlgorithm()
         alg.setChildId(self.component().childId())
         alg.copyNonDefinitionPropertiesFromModel(self.model())
         self.model().setChildAlgorithm(alg)
         self.requestModelRepaint.emit()
         self.changed.emit()
Exemplo n.º 6
0
    def addAlgorithm(self, alg_id, pos=None):
        alg = QgsApplication.processingRegistry().createAlgorithmById(alg_id)
        if not alg:
            return

        dlg = ModelerParametersDialog(alg, self.model())
        if dlg.exec_():
            alg = dlg.createAlgorithm()
            if pos is None or not pos:
                alg.setPosition(self.getPositionForAlgorithmItem())
            else:
                alg.setPosition(pos)

            alg.comment().setPosition(alg.position() +
                                      QPointF(alg.size().width(), -1.5 *
                                              alg.size().height()))

            output_offset_x = alg.size().width()
            output_offset_y = 1.5 * alg.size().height()
            for out in alg.modelOutputs():
                alg.modelOutput(out).setPosition(
                    alg.position() + QPointF(output_offset_x, output_offset_y))
                output_offset_y += 1.5 * alg.modelOutput(out).size().height()

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

            res, errors = self.model().validateChildAlgorithm(id)
            if not res:
                self.view().scene().showWarning(
                    QCoreApplication.translate(
                        'ModelerDialog',
                        'Algorithm “{}” is invalid').format(alg.description()),
                    self.tr('Algorithm is Invalid'),
                    QCoreApplication.translate(
                        'ModelerDialog',
                        "<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()