def addInputOfType(self, paramType, pos=None): if paramType in ModelerParameterDefinitionDialog.paramTypes: dlg = ModelerParameterDefinitionDialog(self.alg, paramType) dlg.exec_() if dlg.param is not None: if pos is None: pos = self.getPositionForParameterItem() if isinstance(pos, QPoint): pos = QPointF(pos) self.alg.addParameter(ModelerParameter(dlg.param, pos)) self.repaintModel() #self.view.ensureVisible(self.scene.getLastParameterItem()) self.hasChanged = True
def addInputOfType(self, paramType, pos=None): dlg = ModelerParameterDefinitionDialog(self.model, paramType) dlg.exec_() if dlg.param is not None: if pos is None: pos = self.getPositionForParameterItem() if isinstance(pos, QPoint): pos = QPointF(pos) component = QgsProcessingModelParameter(dlg.param.name()) component.setDescription(dlg.param.name()) component.setPosition(pos) self.model.addModelParameter(dlg.param, component) self.repaintModel() # self.view.ensureVisible(self.scene.getLastParameterItem()) self.hasChanged = True
def addInputOfType(self, paramType, pos=None): new_param = None if ModelerParameterDefinitionDialog.use_legacy_dialog( paramType=paramType): dlg = ModelerParameterDefinitionDialog(self.model, paramType) if dlg.exec_(): new_param = dlg.param 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) if dlg.exec_(): new_param = dlg.createParameter() self.autogenerate_parameter_name(new_param) if new_param is not None: if pos is None: pos = self.getPositionForParameterItem() if isinstance(pos, QPoint): pos = QPointF(pos) component = QgsProcessingModelParameter(new_param.name()) component.setDescription(new_param.name()) component.setPosition(pos) self.model.addModelParameter(new_param, component) self.repaintModel() # self.view.ensureVisible(self.scene.getLastParameterItem()) self.hasChanged = True
def editElement(self): if isinstance(self.element, QgsProcessingModelParameter): dlg = ModelerParameterDefinitionDialog(self.model, param=self.model.parameterDefinition(self.element.parameterName())) if dlg.exec_() and dlg.param is not None: self.model.removeModelParameter(self.element.parameterName()) self.element.setParameterName(dlg.param.name()) self.element.setDescription(dlg.param.name()) self.model.addModelParameter(dlg.param, self.element) self.text = dlg.param.description() self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelChildAlgorithm): elemAlg = self.element.algorithm() dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId(), self.element.configuration()) if dlg.exec_(): alg = dlg.createAlgorithm() alg.setChildId(self.element.childId()) self.updateAlgorithm(alg) self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelOutput): child_alg = self.model.childAlgorithm(self.element.childId()) param_name = '{}:{}'.format(self.element.childId(), self.element.name()) dlg = ModelerParameterDefinitionDialog(self.model, param=self.model.parameterDefinition(param_name)) if dlg.exec_() and dlg.param is not None: model_output = child_alg.modelOutput(self.element.name()) model_output.setDescription(dlg.param.description()) model_output.setDefaultValue(dlg.param.defaultValue()) model_output.setMandatory(not (dlg.param.flags() & QgsProcessingParameterDefinition.FlagOptional)) self.model.updateDestinationParameters()
def editElement(self): if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter): dlg = ModelerParameterDefinitionDialog( self.model, param=self.model.parameterDefinition( self.element.parameterName())) dlg.exec_() if dlg.param is not None: self.model.removeModelParameter(self.element.parameterName()) self.element.setParameterName(dlg.param.name()) self.element.setDescription(dlg.param.name()) self.model.addModelParameter(dlg.param, self.element) self.text = dlg.param.description() self.update() elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm): dlg = None try: dlg = self.element.algorithm( ).getCustomModelerParametersDialog(self.model, self.element.childId()) except: pass if not dlg: dlg = ModelerParametersDialog(self.element.algorithm(), self.model, self.element.childId()) dlg.exec_() if dlg.alg is not None: dlg.alg.setChildId(self.element.childId()) self.updateAlgorithm(dlg.alg) self.scene.dialog.repaintModel()
def editElement(self): if isinstance(self.element, QgsProcessingModelParameter): dlg = ModelerParameterDefinitionDialog(self.model, param=self.model.parameterDefinition(self.element.parameterName())) if dlg.exec_() and dlg.param is not None: self.model.removeModelParameter(self.element.parameterName()) self.element.setParameterName(dlg.param.name()) self.element.setDescription(dlg.param.name()) self.model.addModelParameter(dlg.param, self.element) self.text = dlg.param.description() self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelChildAlgorithm): elemAlg = self.element.algorithm() dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId(), self.element.configuration()) if dlg.exec_(): alg = dlg.createAlgorithm() alg.setChildId(self.element.childId()) self.updateAlgorithm(alg) self.scene.dialog.repaintModel()
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()) 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 editElement(self): if isinstance(self.element, QgsProcessingModelParameter): dlg = ModelerParameterDefinitionDialog(self.model, param=self.model.parameterDefinition(self.element.parameterName())) dlg.exec_() if dlg.param is not None: self.model.removeModelParameter(self.element.parameterName()) self.element.setParameterName(dlg.param.name()) self.element.setDescription(dlg.param.name()) self.model.addModelParameter(dlg.param, self.element) self.text = dlg.param.description() self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelChildAlgorithm): dlg = None try: dlg = self.element.algorithm().getCustomModelerParametersDialog(self.model, self.element.childId()) except: pass if not dlg: dlg = ModelerParametersDialog(self.element.algorithm(), self.model, self.element.childId()) dlg.exec_() if dlg.alg is not None: dlg.alg.setChildId(self.element.childId()) self.updateAlgorithm(dlg.alg) self.scene.dialog.repaintModel()
def editElement(self): if isinstance(self.element, QgsProcessingModelParameter): dlg = ModelerParameterDefinitionDialog( self.model, param=self.model.parameterDefinition( self.element.parameterName())) if dlg.exec_() and dlg.param is not None: self.model.removeModelParameter(self.element.parameterName()) self.element.setParameterName(dlg.param.name()) self.element.setDescription(dlg.param.name()) self.model.addModelParameter(dlg.param, self.element) self.text = dlg.param.description() self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelChildAlgorithm): dlg = None elemAlg = self.element.algorithm() if hasattr(elemAlg, 'getCustomModelerParametersDialog'): dlg = elemAlg.getCustomModelerParametersDialog( self.model, self.element.childId()) if not dlg: dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId()) if dlg.exec_(): alg = dlg.createAlgorithm() alg.setChildId(self.element.childId()) self.updateAlgorithm(alg) self.scene.dialog.repaintModel()
def fillInputsTree(self): icon = QIcon(os.path.join(pluginPath, 'images', 'input.svg')) parametersItem = QTreeWidgetItem() parametersItem.setText(0, self.tr('Parameters')) for paramType in sorted(ModelerParameterDefinitionDialog.paramTypes): paramItem = QTreeWidgetItem() paramItem.setText(0, paramType) paramItem.setIcon(0, icon) paramItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) paramItem.setToolTip(0, ModelerParameterDefinitionDialog.inputTooltip(paramType)) parametersItem.addChild(paramItem) self.inputsTree.addTopLevelItem(parametersItem) parametersItem.setExpanded(True)
def editElement(self): if isinstance(self.element, QgsProcessingModelParameter): dlg = ModelerParameterDefinitionDialog( self.model, param=self.model.parameterDefinition( self.element.parameterName())) if dlg.exec_() and dlg.param is not None: self.model.removeModelParameter(self.element.parameterName()) self.element.setParameterName(dlg.param.name()) self.element.setDescription(dlg.param.name()) self.model.addModelParameter(dlg.param, self.element) self.text = dlg.param.description() self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelChildAlgorithm): elemAlg = self.element.algorithm() dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId(), self.element.configuration()) if dlg.exec_(): alg = dlg.createAlgorithm() alg.setChildId(self.element.childId()) self.updateAlgorithm(alg) self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelOutput): child_alg = self.model.childAlgorithm(self.element.childId()) param_name = '{}:{}'.format(self.element.childId(), self.element.name()) dlg = ModelerParameterDefinitionDialog( self.model, param=self.model.parameterDefinition(param_name)) if dlg.exec_() and dlg.param is not None: model_output = child_alg.modelOutput(self.element.name()) model_output.setDescription(dlg.param.description()) model_output.setDefaultValue(dlg.param.defaultValue()) model_output.setMandatory(not ( dlg.param.flags() & QgsProcessingParameterDefinition.FlagOptional)) self.model.updateDestinationParameters()
def edit(self, edit_comment=False): child_alg = self.model().childAlgorithm(self.component().childId()) param_name = '{}:{}'.format(self.component().childId(), self.component().name()) dlg = ModelerParameterDefinitionDialog( self.model(), param=self.model().parameterDefinition(param_name)) dlg.setComments(self.component().comment().description()) if edit_comment: dlg.switchToCommentTab() if dlg.exec_(): model_output = child_alg.modelOutput(self.component().name()) model_output.setDescription(dlg.param.description()) model_output.setDefaultValue(dlg.param.defaultValue()) model_output.setMandatory(not ( dlg.param.flags() & QgsProcessingParameterDefinition.FlagOptional)) model_output.comment().setDescription(dlg.comments()) self.model().updateDestinationParameters() self.requestModelRepaint.emit() self.changed.emit()
def editElement(self): if isinstance(self.element, ModelerParameter): dlg = ModelerParameterDefinitionDialog(self.model, param=self.element.param) dlg.exec_() if dlg.param is not None: self.model.updateParameter(dlg.param) self.element.param = dlg.param self.text = dlg.param.description self.update() elif isinstance(self.element, Algorithm): dlg = self.element.algorithm.getCustomModelerParametersDialog(self.model, self.element.modeler_name) if not dlg: dlg = ModelerParametersDialog(self.element.algorithm, self.model, self.element.modeler_name) dlg.exec_() if dlg.alg is not None: dlg.alg.modeler_name = self.element.modeler_name self.model.updateAlgorithm(dlg.alg) self.model.updateModelerView()
def editElement(self): self.model.setPositions(self.scene().getParameterPositions(), self.scene().getAlgorithmPositions(), self.scene().getOutputPositions()) if isinstance(self.element, Parameter): dlg = ModelerParameterDefinitionDialog(self.model, param = self.element) dlg.exec_() if dlg.param != None: self.model.updateParameter(self.elementIndex, dlg.param) self.element = dlg.param self.text = self.element.description self.update() elif isinstance(self.element, GeoAlgorithm): dlg = self.element.getCustomModelerParametersDialog(self.model, self.elementIndex) if not dlg: dlg = ModelerParametersDialog(self.element, self.model, self.elementIndex) dlg.exec_() if dlg.params != None: self.model.updateAlgorithm(self.elementIndex, dlg.params, dlg.values, dlg.outputs, dlg.dependencies)
def editElement(self): if isinstance(self.element, ModelerParameter): dlg = ModelerParameterDefinitionDialog(self.model, param=self.element.param) dlg.exec_() if dlg.param is not None: self.model.updateParameter(dlg.param) self.element.param = dlg.param self.text = dlg.param.description self.update() elif isinstance(self.element, Algorithm): dlg = self.element.algorithm.getCustomModelerParametersDialog(self.model, self.element.name) if not dlg: dlg = ModelerParametersDialog(self.element.algorithm, self.model, self.element.name) dlg.exec_() if dlg.alg is not None: dlg.alg.name = self.element.name self.model.updateAlgorithm(dlg.alg) self.model.updateModelerView()
def editElement(self): self.model.setPositions(self.scene().getParameterPositions(), self.scene().getAlgorithmPositions(), self.scene().getOutputPositions()) if isinstance(self.element, Parameter): dlg = ModelerParameterDefinitionDialog(self.model, param=self.element) dlg.exec_() if dlg.param != None: self.model.updateParameter(self.elementIndex, dlg.param) self.element = dlg.param self.text = self.element.description self.update() elif isinstance(self.element, GeoAlgorithm): dlg = self.element.getCustomModelerParametersDialog( self.model, self.elementIndex) if not dlg: dlg = ModelerParametersDialog(self.element, self.model, self.elementIndex) dlg.exec_() if dlg.params != None: self.model.updateAlgorithm(self.elementIndex, dlg.params, dlg.values, dlg.outputs, dlg.dependencies)
def edit(self, edit_comment=False): child_alg = self.model().childAlgorithm(self.component().childId()) dlg = ModelerParameterDefinitionDialog( self.model(), param=self.model().modelParameterFromChildIdAndOutputName( self.component().childId(), self.component().name())) dlg.setComments(self.component().comment().description()) dlg.setCommentColor(self.component().comment().color()) if edit_comment: dlg.switchToCommentTab() if dlg.exec_(): model_outputs = child_alg.modelOutputs() model_output = QgsProcessingModelOutput( model_outputs[self.component().name()]) del model_outputs[self.component().name()] model_output.setName(dlg.param.description()) model_output.setDescription(dlg.param.description()) model_output.setDefaultValue(dlg.param.defaultValue()) model_output.setMandatory(not ( dlg.param.flags() & QgsProcessingParameterDefinition.FlagOptional)) model_output.comment().setDescription(dlg.comments()) model_output.comment().setColor(dlg.commentColor()) model_outputs[model_output.name()] = model_output child_alg.setModelOutputs(model_outputs) self.aboutToChange.emit( self.tr('Edit {}').format(model_output.description())) self.model().updateDestinationParameters() self.requestModelRepaint.emit() self.changed.emit()
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) 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 setupUi(self): if self.paramType == GPFModelerParameterDefinitionDialog.PARAMETER_BANDS or \ isinstance(self.param, ParameterBands): self.setWindowTitle(self.tr('Parameter definition')) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(40) self.verticalLayout.setMargin(20) self.horizontalLayoutName = QHBoxLayout(self) self.horizontalLayoutName.setSpacing(2) self.horizontalLayoutName.setMargin(0) self.label = QLabel(self.tr('Parameter name')) self.horizontalLayoutName.addWidget(self.label) self.nameTextBox = QLineEdit() self.horizontalLayoutName.addWidget(self.nameTextBox) self.verticalLayout.addLayout(self.horizontalLayoutName) self.horizontalLayoutRequired = QHBoxLayout(self) self.horizontalLayoutRequired.setSpacing(2) self.horizontalLayoutRequired.setMargin(0) self.horizontalLayoutParent = QHBoxLayout(self) self.horizontalLayoutParent.setSpacing(2) self.horizontalLayoutParent.setMargin(0) self.horizontalLayoutDefault = QHBoxLayout(self) self.horizontalLayoutDefault.setSpacing(2) self.horizontalLayoutDefault.setMargin(0) self.horizontalLayoutDatatype = QHBoxLayout(self) self.horizontalLayoutDatatype.setSpacing(2) self.horizontalLayoutDatatype.setMargin(0) if isinstance(self.param, Parameter): self.nameTextBox.setText(self.param.description) self.horizontalLayoutDefault.addWidget(QLabel(self.tr('Default band'))) self.defaultTextBox = QLineEdit() if self.param is not None: self.defaultTextBox.setText(self.param.default) self.horizontalLayoutDefault.addWidget(self.defaultTextBox) self.verticalLayout.addLayout(self.horizontalLayoutDefault) self.horizontalLayoutDefault.addWidget(QLabel(self.tr('Raster layer'))) self.parentCombo = QComboBox() idx = 0 for param in self.alg.inputs.values(): if isinstance(param.param, (ParameterRaster)): self.parentCombo.addItem(param.param.description, param.param.name) if self.param is not None: if self.param.bandSourceRaster == param.param.name: self.parentCombo.setCurrentIndex(idx) idx += 1 self.horizontalLayoutDefault.addWidget(self.parentCombo) self.verticalLayout.addLayout(self.horizontalLayoutDefault) self.horizontalLayoutRequired.addWidget(QLabel(self.tr('Required'))) self.yesNoCombo = QComboBox() self.yesNoCombo.addItem(self.tr('Yes')) self.yesNoCombo.addItem(self.tr('No')) self.horizontalLayoutRequired.addWidget(self.yesNoCombo) if self.param is not None: self.yesNoCombo.setCurrentIndex( 1 if self.param.optional else 0) self.verticalLayout.addLayout(self.horizontalLayoutRequired) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.setObjectName('buttonBox') self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.verticalLayout.addWidget(self.buttonBox) self.setLayout(self.verticalLayout) else: ModelerParameterDefinitionDialog.setupUi(self)
def editElement(self): if isinstance(self.element, QgsProcessingModelParameter): existing_param = self.model.parameterDefinition( self.element.parameterName()) new_param = None if ModelerParameterDefinitionDialog.use_legacy_dialog( param=existing_param): # boo, old api dlg = ModelerParameterDefinitionDialog(self.model, param=existing_param) if dlg.exec_(): new_param = dlg.param 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) if dlg.exec_(): new_param = dlg.createParameter(existing_param.name()) if new_param is not None: self.model.removeModelParameter(self.element.parameterName()) self.element.setParameterName(new_param.name()) self.element.setDescription(new_param.name()) self.model.addModelParameter(new_param, self.element) self.text = new_param.description() self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelChildAlgorithm): elemAlg = self.element.algorithm() dlg = ModelerParametersDialog(elemAlg, self.model, self.element.childId(), self.element.configuration()) if dlg.exec_(): alg = dlg.createAlgorithm() alg.setChildId(self.element.childId()) self.updateAlgorithm(alg) self.scene.dialog.repaintModel() elif isinstance(self.element, QgsProcessingModelOutput): child_alg = self.model.childAlgorithm(self.element.childId()) param_name = '{}:{}'.format(self.element.childId(), self.element.name()) dlg = ModelerParameterDefinitionDialog( self.model, param=self.model.parameterDefinition(param_name)) if dlg.exec_() and dlg.param is not None: model_output = child_alg.modelOutput(self.element.name()) model_output.setDescription(dlg.param.description()) model_output.setDefaultValue(dlg.param.defaultValue()) model_output.setMandatory(not ( dlg.param.flags() & QgsProcessingParameterDefinition.FlagOptional)) self.model.updateDestinationParameters()
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()