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()
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()
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
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
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
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()
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()