コード例 #1
0
ファイル: ModelerDialog.py プロジェクト: stev-0/QGIS
    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()
コード例 #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()
コード例 #3
0
ファイル: ModelerDialog.py プロジェクト: FrancisGauthier/QGIS
 def _addAlgorithm(self, alg, pos=None):
     dlg = alg.getCustomModelerParametersDialog(self.alg)
     if not dlg:
         dlg = ModelerParametersDialog(alg, self.alg)
     dlg.exec_()
     if dlg.alg is not None:
         if pos is None:
             dlg.alg.pos = self.getPositionForAlgorithmItem()
         else:
             dlg.alg.pos = pos
         if isinstance(dlg.alg.pos, QPoint):
             dlg.alg.pos = QPointF(pos)
         from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
         for i, out in enumerate(dlg.alg.outputs):
             dlg.alg.outputs[out].pos = dlg.alg.pos + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5)
                                                              * ModelerGraphicItem.BOX_HEIGHT)
         self.alg.addAlgorithm(dlg.alg)
         self.repaintModel()
         self.hasChanged = True
コード例 #4
0
ファイル: ModelerDialog.py プロジェクト: zgustaf/QGIS
 def _addAlgorithm(self, alg, pos=None):
     dlg = alg.getCustomModelerParametersDialog(self.alg)
     if not dlg:
         dlg = ModelerParametersDialog(alg, self.alg)
     dlg.exec_()
     if dlg.alg is not None:
         if pos is None:
             dlg.alg.pos = self.getPositionForAlgorithmItem()
         else:
             dlg.alg.pos = pos
         if isinstance(dlg.alg.pos, QPoint):
             dlg.alg.pos = QPointF(pos)
         from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
         for i, out in enumerate(dlg.alg.outputs):
             dlg.alg.outputs[out].pos = dlg.alg.pos + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
                                                              ModelerGraphicItem.BOX_HEIGHT)
         self.alg.addAlgorithm(dlg.alg)
         self.repaintModel()
         self.hasChanged = True
コード例 #5
0
ファイル: ModelerDialog.py プロジェクト: exlimit/QGIS
 def _addAlgorithm(self, alg, pos=None):
     dlg = None
     try:
         dlg = alg.getCustomModelerParametersDialog(self.model)
     except:
         pass
     if not dlg:
         dlg = ModelerParametersDialog(alg, self.model)
     dlg.exec_()
     if dlg.alg is not None:
         if pos is None:
             dlg.alg.setPosition(self.getPositionForAlgorithmItem())
         else:
             dlg.alg.setPosition(pos)
         from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
         for i, out in enumerate(dlg.alg.modelOutputs()):
             dlg.alg.modelOutput(out).setPosition(dlg.alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
                                                                               ModelerGraphicItem.BOX_HEIGHT))
         self.model.addChildAlgorithm(dlg.alg)
         self.repaintModel()
         self.hasChanged = True
コード例 #6
0
ファイル: ModelerDialog.py プロジェクト: zylimit/QGIS
 def _addAlgorithm(self, alg, pos=None):
     dlg = None
     try:
         dlg = alg.getCustomModelerParametersDialog(self.model)
     except:
         pass
     if not dlg:
         dlg = ModelerParametersDialog(alg, self.model)
     dlg.exec_()
     if dlg.alg is not None:
         if pos is None:
             dlg.alg.setPosition(self.getPositionForAlgorithmItem())
         else:
             dlg.alg.setPosition(pos)
         from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
         for i, out in enumerate(dlg.alg.modelOutputs()):
             dlg.alg.modelOutput(out).setPosition(dlg.alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
                                                                               ModelerGraphicItem.BOX_HEIGHT))
         self.model.addChildAlgorithm(dlg.alg)
         self.repaintModel()
         self.hasChanged = True
コード例 #7
0
ファイル: ModelerDialog.py プロジェクト: dwsilk/QGIS
 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
コード例 #8
0
ファイル: ModelerDialog.py プロジェクト: pangyemeng/QGIS
 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
コード例 #9
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()
コード例 #10
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()