Skip to content
Permalink
Browse files

[processing] fixed disappearing lines in modeler

Moved the updating of paths of arrows/lines in the modeler out of the
paint method, fixing various rendering problems.
  • Loading branch information
HenningJagd committed May 22, 2015
1 parent 2f9b926 commit 4e6394e213434de3605a8c00405cace05c748531
@@ -47,7 +47,7 @@
"""

from PyQt4.QtCore import Qt, QPointF
from PyQt4.QtGui import QGraphicsPathItem, QPen, QGraphicsItem, QPainterPath, QPolygonF
from PyQt4.QtGui import QGraphicsPathItem, QPen, QGraphicsItem, QPainterPath, QPolygonF, QPainter
from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
from processing.modeler.ModelerAlgorithm import Algorithm

@@ -61,56 +61,62 @@ def __init__(self, startItem, startIndex, endItem, endIndex,
self.startIndex = startIndex
self.startItem = startItem
self.endItem = endItem
self.endPoints = []
self.setFlag(QGraphicsItem.ItemIsSelectable, False)
self.myColor = Qt.gray
self.setPen(QPen(self.myColor, 1, Qt.SolidLine,
Qt.RoundCap, Qt.RoundJoin))
self.setZValue(0)

def paint(self, painter, option, widget=None):
myPen = self.pen()
myPen.setColor(self.myColor)
painter.setPen(myPen)
painter.setBrush(self.myColor)

def updatePath(self):
self.endPoints = []
controlPoints = []
endPt = self.endItem.getLinkPointForParameter(self.endIndex)
startPt = self.startItem.getLinkPointForOutput(self.startIndex)
if isinstance(self.startItem.element, Algorithm):
if self.startIndex != -1:
controlPoints.append(self.startItem.pos() + startPt)
controlPoints.append(self.startItem.pos() + startPt
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt
- QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
- QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt)
pt = QPointF(self.startItem.pos() + startPt
+ QPointF(-3, -3))
painter.drawEllipse(pt.x(), pt.y(), 6, 6)
self.endPoints.append(pt)
pt = QPointF(self.endItem.pos() + endPt +
QPointF(-3, -3))
painter.drawEllipse(pt.x(), pt.y(), 6, 6)
self.endPoints.append(pt)
else:
# Case where there is a dependency on an algorithm not
# on an output
controlPoints.append(self.startItem.pos() + startPt)
controlPoints.append(self.startItem.pos() + startPt
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt
- QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
- QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt)
else:
controlPoints.append(self.startItem.pos())
controlPoints.append(self.startItem.pos()
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt
- QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
- QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt)
pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3))
painter.drawEllipse(pt.x(), pt.y(), 6, 6)

self.endPoints.append(pt)
path = QPainterPath()
path.moveTo(controlPoints[0])
path.cubicTo(*controlPoints[1:])
painter.strokePath(path, painter.pen())
self.setPath(path)

def paint(self, painter, option, widget=None):
myPen = self.pen()
myPen.setColor(self.myColor)
painter.setPen(myPen)
painter.setBrush(self.myColor)
painter.setRenderHint(QPainter.Antialiasing)

for point in self.endPoints:
painter.drawEllipse(point.x(), point.y(), 6, 6)
painter.strokePath(self.shape(), painter.pen())
@@ -302,7 +302,7 @@ def getLinkPointForOutput(self, outputIndex):
def itemChange(self, change, value):
if change == QGraphicsItem.ItemPositionHasChanged:
for arrow in self.arrows:
arrow.updatePosition()
arrow.updatePath()
self.element.pos = self.pos()

return value
@@ -105,11 +105,17 @@ def paintModel(self, model):
sourceItems = self.getItemsFromParamValue(value)
for sourceItem, sourceIdx in sourceItems:
arrow = ModelerArrowItem(sourceItem, sourceIdx, self.algItems[alg.name], idx)
sourceItem.addArrow(arrow)
self.algItems[alg.name].addArrow(arrow)
arrow.updatePath()
self.addItem(arrow)
idx += 1
for depend in alg.dependencies:
arrow = ModelerArrowItem(self.algItems[depend], -1,
self.algItems[alg.name], -1)
self.algItems[depend].addArrow(arrow)
self.algItems[alg.name].addArrow(arrow)
arrow.updatePath()
self.addItem(arrow)

# And finally the outputs
@@ -132,6 +138,9 @@ def paintModel(self, model):
outputItems[key] = item
arrow = ModelerArrowItem(self.algItems[alg.name], idx, item,
-1)
self.algItems[alg.name].addArrow(arrow)
item.addArrow(arrow)
arrow.updatePath()
self.addItem(arrow)
idx += 1
else:

0 comments on commit 4e6394e

Please sign in to comment.