Skip to content
Permalink
Browse files

Draw links between dependent parameters in graphical modeler

Fix #12907
  • Loading branch information
nyalldawson committed Jul 3, 2017
1 parent f4d703b commit f9f98593e04a815edfe1f80c16f6b54890950bda
@@ -70,11 +70,23 @@ def __init__(self, startItem, startIndex, endItem, endIndex,
Qt.RoundCap, Qt.RoundJoin))
self.setZValue(0)

def setPenStyle(self, style):
pen = self.pen()
pen.setStyle(style)
self.setPen(pen)
self.update()

def updatePath(self):
self.endPoints = []
controlPoints = []
endPt = self.endItem.getLinkPointForParameter(self.endIndex)
startPt = self.startItem.getLinkPointForOutput(self.startIndex)
if isinstance(self.startItem.element, QgsProcessingModelAlgorithm.ModelParameter):
startPt = self.startItem.getLinkPointForParameter(self.startIndex)
else:
startPt = self.startItem.getLinkPointForOutput(self.startIndex)
if isinstance(self.endItem.element, QgsProcessingModelAlgorithm.ModelParameter):
endPt = self.endItem.getLinkPointForParameter(self.startIndex)

if isinstance(self.startItem.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
if self.startIndex != -1:
controlPoints.append(self.startItem.pos() + startPt)
@@ -199,7 +199,7 @@ def editElement(self):
self.element.setDescription(dlg.param.name())
self.model.addModelParameter(dlg.param, self.element)
self.text = dlg.param.description()
self.update()
self.scene.dialog.repaintModel()
elif isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm):
dlg = None
try:
@@ -336,6 +336,9 @@ def getLinkPointForParameter(self, paramIndex):
if isinstance(self.element, QgsProcessingModelAlgorithm.ChildAlgorithm) and self.element.parametersCollapsed():
paramIndex = -1
offsetX = 17
if isinstance(self.element, QgsProcessingModelAlgorithm.ModelParameter):
paramIndex = -1
offsetX = 0
font = QFont('Verdana', 8)
font.setPixelSize(12)
fm = QFontMetricsF(font)
@@ -94,6 +94,22 @@ def paintModel(self, model, controls=True):
item.setPos(inp.position().x(), inp.position().y())
self.paramItems[inp.parameterName()] = item

# Input dependency arrows
for input_name in list(model.parameterComponents().keys()):
idx = 0
parameter_def = model.parameterDefinition(input_name)
if hasattr(parameter_def, 'parentLayerParameter') and parameter_def.parentLayerParameter():
parent_name = parameter_def.parentLayerParameter()
if input_name in self.paramItems and parent_name in self.paramItems:
input_item = self.paramItems[input_name]
parent_item = self.paramItems[parent_name]
arrow = ModelerArrowItem(parent_item, -1, input_item, -1)
input_item.addArrow(arrow)
parent_item.addArrow(arrow)
arrow.setPenStyle(Qt.DotLine)
arrow.updatePath()
self.addItem(arrow)

# We add the algs
for alg in list(model.childAlgorithms().values()):
item = ModelerGraphicItem(alg, model, controls, scene=self)
@@ -104,6 +120,7 @@ def paintModel(self, model, controls=True):
self.algItems[alg.childId()] = item

# And then the arrows

for alg in list(model.childAlgorithms().values()):
idx = 0
for parameter in alg.algorithm().parameterDefinitions():

0 comments on commit f9f9859

Please sign in to comment.
You can’t perform that action at this time.