def __init__(self, position, action, folded): plus = QPicture() minus = QPicture() svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'plus.svg')) painter = QPainter(plus) svg.render(painter) svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'minus.svg')) painter = QPainter(minus) svg.render(painter) self.pictures = {True: plus, False: minus} self.folded = folded picture = self.pictures[self.folded] super(FoldButtonGraphicItem, self).__init__(picture, position, action)
def __init__(self, element, model, controls, scene=None): super(ModelerGraphicItem, self).__init__(None) self.controls = controls self.model = model self.scene = scene self.element = element if isinstance(element, QgsProcessingModelParameter): svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'input.svg')) self.picture = QPicture() painter = QPainter(self.picture) svg.render(painter) self.pixmap = None self.text = self.model.parameterDefinition( element.parameterName()).description() elif isinstance(element, QgsProcessingModelOutput): # Output name svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'output.svg')) self.picture = QPicture() painter = QPainter(self.picture) svg.render(painter) self.pixmap = None self.text = element.name() else: self.text = element.description() self.pixmap = element.algorithm().icon().pixmap(15, 15) self.arrows = [] self.setFlag(QGraphicsItem.ItemIsMovable, True) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) self.setZValue(1000) if not isinstance(element, QgsProcessingModelOutput) and controls: svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'edit.svg')) picture = QPicture() painter = QPainter(picture) svg.render(painter) pt = QPointF( ModelerGraphicItem.BOX_WIDTH / 2 - FlatButtonGraphicItem.WIDTH / 2, ModelerGraphicItem.BOX_HEIGHT / 2 - FlatButtonGraphicItem.HEIGHT / 2) self.editButton = FlatButtonGraphicItem(picture, pt, self.editElement) self.editButton.setParentItem(self) svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'delete.svg')) picture = QPicture() painter = QPainter(picture) svg.render(painter) pt = QPointF( ModelerGraphicItem.BOX_WIDTH / 2 - FlatButtonGraphicItem.WIDTH / 2, FlatButtonGraphicItem.HEIGHT / 2 - ModelerGraphicItem.BOX_HEIGHT / 2) self.deleteButton = FlatButtonGraphicItem(picture, pt, self.removeElement) self.deleteButton.setParentItem(self) if isinstance(element, QgsProcessingModelChildAlgorithm): alg = element.algorithm() if [ a for a in alg.parameterDefinitions() if not a.isDestination() ]: pt = self.getLinkPointForParameter(-1) pt = QPointF(0, pt.y()) if controls: self.inButton = FoldButtonGraphicItem( pt, self.foldInput, self.element.parametersCollapsed()) self.inButton.setParentItem(self) if alg.outputDefinitions(): pt = self.getLinkPointForOutput(-1) pt = QPointF(0, pt.y()) if controls: self.outButton = FoldButtonGraphicItem( pt, self.foldOutput, self.element.outputsCollapsed()) self.outButton.setParentItem(self)
def __init__(self, element, model, controls): super(ModelerGraphicItem, self).__init__(None) self.controls = controls self.model = model self.element = element if isinstance(element, ModelerParameter): svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'input.svg')) self.picture = QPicture() painter = QPainter(self.picture) svg.render(painter) self.pixmap = None self.text = element.param.description elif isinstance(element, ModelerOutput): # Output name svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'output.svg')) self.picture = QPicture() painter = QPainter(self.picture) svg.render(painter) self.pixmap = None self.text = element.description else: self.text = element.description self.pixmap = element.algorithm.getIcon().pixmap(15, 15) self.arrows = [] self.setFlag(QGraphicsItem.ItemIsMovable, True) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) self.setZValue(1000) if not isinstance(element, ModelerOutput) and controls: svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'edit.svg')) picture = QPicture() painter = QPainter(picture) svg.render(painter) pt = QPointF( ModelerGraphicItem.BOX_WIDTH / 2 - FlatButtonGraphicItem.WIDTH / 2, ModelerGraphicItem.BOX_HEIGHT / 2 - FlatButtonGraphicItem.HEIGHT / 2) self.editButton = FlatButtonGraphicItem(picture, pt, self.editElement) self.editButton.setParentItem(self) svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'delete.svg')) picture = QPicture() painter = QPainter(picture) svg.render(painter) pt = QPointF( ModelerGraphicItem.BOX_WIDTH / 2 - FlatButtonGraphicItem.WIDTH / 2, -ModelerGraphicItem.BOX_HEIGHT / 2 + FlatButtonGraphicItem.HEIGHT / 2) self.deleteButton = FlatButtonGraphicItem(picture, pt, self.removeElement) self.deleteButton.setParentItem(self) if isinstance(element, Algorithm): alg = element.algorithm if alg.parameters: pt = self.getLinkPointForParameter(-1) pt = QPointF(0, pt.y()) if controls: self.inButton = FoldButtonGraphicItem( pt, self.foldInput, self.element.paramsFolded) self.inButton.setParentItem(self) if alg.outputs: pt = self.getLinkPointForOutput(-1) pt = QPointF(0, pt.y()) if controls: self.outButton = FoldButtonGraphicItem( pt, self.foldOutput, self.element.outputsFolded) self.outButton.setParentItem(self)