Skip to content

Commit

Permalink
Draw links between dependent parameters in graphical modeler
Browse files Browse the repository at this point in the history
Fix #12907
  • Loading branch information
nyalldawson committed Jul 3, 2017
1 parent f4d703b commit f9f9859
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
14 changes: 13 additions & 1 deletion python/plugins/processing/modeler/ModelerArrowItem.py
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/modeler/ModelerGraphicItem.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions python/plugins/processing/modeler/ModelerScene.py
Expand Up @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit f9f9859

Please sign in to comment.