def edit(self, edit_comment=False): existing_param = self.model().parameterDefinition( self.component().parameterName()) comment = self.component().comment().description() comment_color = self.component().comment().color() new_param = None if ModelerParameterDefinitionDialog.use_legacy_dialog( param=existing_param): # boo, old api dlg = ModelerParameterDefinitionDialog(self.model(), param=existing_param) dlg.setComments(comment) dlg.setCommentColor(comment_color) if edit_comment: dlg.switchToCommentTab() if dlg.exec_(): new_param = dlg.param comment = dlg.comments() comment_color = dlg.commentColor() else: # yay, use new API! context = createContext() widget_context = self.create_widget_context() dlg = QgsProcessingParameterDefinitionDialog( type=existing_param.type(), context=context, widgetContext=widget_context, definition=existing_param, algorithm=self.model()) dlg.setComments(comment) dlg.setCommentColor(comment_color) dlg.registerProcessingContextGenerator(self.context_generator) if edit_comment: dlg.switchToCommentTab() if dlg.exec_(): new_param = dlg.createParameter(existing_param.name()) comment = dlg.comments() comment_color = dlg.commentColor() if new_param is not None: self.aboutToChange.emit( self.tr('Edit {}').format(new_param.description())) self.model().removeModelParameter(self.component().parameterName()) self.component().setParameterName(new_param.name()) self.component().setDescription(new_param.name()) self.component().comment().setDescription(comment) self.component().comment().setColor(comment_color) self.model().addModelParameter(new_param, self.component()) self.setLabel(new_param.description()) self.requestModelRepaint.emit() self.changed.emit()
def addInput(self, paramType, pos=None): if paramType not in [ param.id() for param in QgsApplication.instance(). processingRegistry().parameterTypes() ]: return new_param = None comment = None if ModelerParameterDefinitionDialog.use_legacy_dialog( paramType=paramType): dlg = ModelerParameterDefinitionDialog(self.model(), paramType) if dlg.exec_(): new_param = dlg.param comment = dlg.comments() else: # yay, use new API! context = createContext() widget_context = self.create_widget_context() dlg = QgsProcessingParameterDefinitionDialog( type=paramType, context=context, widgetContext=widget_context, algorithm=self.model()) dlg.registerProcessingContextGenerator(self.context_generator) if dlg.exec_(): new_param = dlg.createParameter() self.autogenerate_parameter_name(new_param) comment = dlg.comments() if new_param is not None: if pos is None or not pos: pos = self.getPositionForParameterItem() if isinstance(pos, QPoint): pos = QPointF(pos) component = QgsProcessingModelParameter(new_param.name()) component.setDescription(new_param.name()) component.setPosition(pos) component.comment().setDescription(comment) component.comment().setPosition(component.position() + QPointF( component.size().width(), -1.5 * component.size().height())) self.beginUndoCommand(self.tr('Add Model Input')) self.model().addModelParameter(new_param, component) self.repaintModel() # self.view().ensureVisible(self.scene.getLastParameterItem()) self.endUndoCommand()
def edit(self, edit_comment=False): existing_param = self.model().parameterDefinition( self.component().parameterName()) old_name = existing_param.name() old_description = existing_param.description() comment = self.component().comment().description() comment_color = self.component().comment().color() new_param = None if ModelerParameterDefinitionDialog.use_legacy_dialog( param=existing_param): # boo, old api dlg = ModelerParameterDefinitionDialog(self.model(), param=existing_param) dlg.setComments(comment) dlg.setCommentColor(comment_color) if edit_comment: dlg.switchToCommentTab() if dlg.exec_(): new_param = dlg.param comment = dlg.comments() comment_color = dlg.commentColor() else: # yay, use new API! context = createContext() widget_context = self.create_widget_context() dlg = QgsProcessingParameterDefinitionDialog( type=existing_param.type(), context=context, widgetContext=widget_context, definition=existing_param, algorithm=self.model()) dlg.setComments(comment) dlg.setCommentColor(comment_color) dlg.registerProcessingContextGenerator(self.context_generator) if edit_comment: dlg.switchToCommentTab() if dlg.exec_(): new_param = dlg.createParameter(existing_param.name()) comment = dlg.comments() comment_color = dlg.commentColor() safeName = QgsProcessingModelAlgorithm.safeName( new_param.description()) new_param.setName(safeName.lower()) if new_param is not None: self.aboutToChange.emit( self.tr('Edit {}').format(new_param.description())) self.model().removeModelParameter(self.component().parameterName()) if new_param.description() != old_description: # only update name if user has changed the description -- we don't force this, as it may cause # unwanted name updates which could potentially break the model's API name = new_param.name() base_name = name i = 2 while self.model().parameterDefinition(name): name = base_name + str(i) i += 1 new_param.setName(name) self.model().changeParameterName(old_name, new_param.name()) self.component().setParameterName(new_param.name()) self.component().setDescription(new_param.name()) self.component().comment().setDescription(comment) self.component().comment().setColor(comment_color) self.model().addModelParameter(new_param, self.component()) self.setLabel(new_param.description()) self.requestModelRepaint.emit() self.changed.emit()