本文整理汇总了Python中qgis.gui.QgsProcessingToolboxTreeView.selectedAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:Python QgsProcessingToolboxTreeView.selectedAlgorithm方法的具体用法?Python QgsProcessingToolboxTreeView.selectedAlgorithm怎么用?Python QgsProcessingToolboxTreeView.selectedAlgorithm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.gui.QgsProcessingToolboxTreeView
的用法示例。
在下文中一共展示了QgsProcessingToolboxTreeView.selectedAlgorithm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ModelerDialog
# 需要导入模块: from qgis.gui import QgsProcessingToolboxTreeView [as 别名]
# 或者: from qgis.gui.QgsProcessingToolboxTreeView import selectedAlgorithm [as 别名]
#.........这里部分代码省略.........
'See the log for more information.'))
def repaintModel(self, controls=True):
self.scene = ModelerScene(self, dialog=self)
self.scene.setSceneRect(QRectF(0, 0, self.CANVAS_SIZE,
self.CANVAS_SIZE))
self.scene.paintModel(self.model, controls)
self.view.setScene(self.scene)
def addInput(self):
item = self.inputsTree.currentItem()
param = item.data(0, Qt.UserRole)
self.addInputOfType(param)
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 getPositionForParameterItem(self):
MARGIN = 20
BOX_WIDTH = 200
BOX_HEIGHT = 80
if len(self.model.parameterComponents()) > 0:
maxX = max([i.position().x() for i in list(self.model.parameterComponents().values())])
newX = min(MARGIN + BOX_WIDTH + maxX, self.CANVAS_SIZE - BOX_WIDTH)
else:
newX = MARGIN + BOX_WIDTH / 2
return QPointF(newX, MARGIN + BOX_HEIGHT / 2)
def fillInputsTree(self):
icon = QIcon(os.path.join(pluginPath, 'images', 'input.svg'))
parametersItem = QTreeWidgetItem()
parametersItem.setText(0, self.tr('Parameters'))
sortedParams = sorted(QgsApplication.instance().processingRegistry().parameterTypes(), key=lambda pt: pt.name())
for param in sortedParams:
if param.flags() & QgsProcessingParameterType.ExposeToModeler:
paramItem = QTreeWidgetItem()
paramItem.setText(0, param.name())
paramItem.setData(0, Qt.UserRole, param.id())
paramItem.setIcon(0, icon)
paramItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled)
paramItem.setToolTip(0, param.description())
parametersItem.addChild(paramItem)
self.inputsTree.addTopLevelItem(parametersItem)
parametersItem.setExpanded(True)
def addAlgorithm(self):
algorithm = self.algorithmTree.selectedAlgorithm()
if algorithm is not None:
alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm.id())
self._addAlgorithm(alg)
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 getPositionForAlgorithmItem(self):
MARGIN = 20
BOX_WIDTH = 200
BOX_HEIGHT = 80
if self.model.childAlgorithms():
maxX = max([alg.position().x() for alg in list(self.model.childAlgorithms().values())])
maxY = max([alg.position().y() for alg in list(self.model.childAlgorithms().values())])
newX = min(MARGIN + BOX_WIDTH + maxX, self.CANVAS_SIZE - BOX_WIDTH)
newY = min(MARGIN + BOX_HEIGHT + maxY, self.CANVAS_SIZE -
BOX_HEIGHT)
else:
newX = MARGIN + BOX_WIDTH / 2
newY = MARGIN * 2 + BOX_HEIGHT + BOX_HEIGHT / 2
return QPointF(newX, newY)
def export_as_script_algorithm(self):
dlg = ScriptEditorDialog(None)
dlg.editor.setText('\n'.join(self.model.asPythonCode(QgsProcessing.PythonQgsProcessingAlgorithmSubclass, 4)))
dlg.show()