I'm developing a plugin into QGIS 2.18. I need to catch if the user deletes a group layer. I tried the signal layerWillBeRemoved from QgsMapLayerRegistry class but it sends only layers not group layer.
What should I do?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
You need check this signals onWillRemoveChildren and onRemovedChildren, check the Api documentation
This is a sample code for removed signals nodes:
root = QgsProject.instance().layerTreeRoot() def onWillRemoveChildren(node, indexFrom, indexTo): print "Will Remove Node : ",node, indexFrom, indexTo def onRemovedChildren(node, indexFrom, indexTo): print "Remove Node : ", node, indexFrom, indexTo root.willRemoveChildren.connect(onWillRemoveChildren) root.removedChildren.connect(onRemovedChildren) mygroup = root.findGroup("test_group") root.removeChildNode(mygroup)
You can expand this function for show a custom message,check if the index is a specific group or something like that.