Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[elevation Profile] Correcly add a layer generated by a processing #59850

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions python/plugins/processing/gui/Postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def handleAlgorithmResults(
# output layer already exists in the destination project
owned_map_layer = context.temporaryLayerStore().takeMapLayer(layer)
if owned_map_layer:
details.project.addMapLayer(owned_map_layer, False)
# If the layer is part of a group, do not add it to the legend
add_to_legend = results_group is None
details.project.addMapLayer(owned_map_layer, add_to_legend)

# we don't add the layer to the tree yet -- that's done
# later, after we've sorted all added layers
Expand Down Expand Up @@ -282,6 +284,12 @@ def handleAlgorithmResults(
if group is not None:
group.insertChildNode(0, layer_node)
else:
# a new node has already been created by the `addMapLayer` call
# move the cloned node to the correct location and the remove
# the first one
root_node = context.project().layerTreeRoot()
previous_layer_node = root_node.findLayer(layer_node.layerId())
previous_layer_group: Optional[QgsLayerTreeGroup] = None
# no destination group for this layer, so should be placed
# above the current layer
if isinstance(current_selected_node, QgsLayerTreeLayer):
Expand All @@ -290,10 +298,17 @@ def handleAlgorithmResults(
current_selected_node
)
current_node_group.insertChildNode(current_node_index, layer_node)
previous_layer_group = current_node_group
elif isinstance(current_selected_node, QgsLayerTreeGroup):
current_selected_node.insertChildNode(0, layer_node)
previous_layer_group = current_selected_node
elif context.project():
context.project().layerTreeRoot().insertChildNode(0, layer_node)
root_node.insertChildNode(0, layer_node)
previous_layer_group = root_node

# remove the previous node added by the `addMapLayer` call
if previous_layer_group and previous_layer_node:
previous_layer_group.removeChildNode(previous_layer_node)

if not have_set_active_layer and iface is not None:
iface.setActiveLayer(layer_node.layer())
Expand Down
Loading