1

Is there a signal that I can listen for changes to any QgsVectorLayers rather than having a listener for each layer? I have a scenario where layer A and B must be committed together which I have a validation logic within the method.

When I make changes to QgsVectorLayer and save the layer, I can listen for such event via signals like QgsVectorLayer.beforeCommitChanges(..).

When I make changes to multiple QgsVectorLayers, I receive multiple beforeCommitChanges signal for each affected layer. Instead, I want a way to derive single signal which contain all affected layers.

enter image description here enter image description here

1

You can listen on the action when clicking on the button. You need to choose "No" or "Yes" to see the output. PS: not sure it perfectly fit what you need but it may help.

action = iface.mainWindow().findChildren(QAction, 'mActionSaveAllEdits')[0]

def listLayers(bool):
    root = QgsProject.instance().layerTreeRoot()
    layerNodes = []
    # Not recursive here. You may need to add the behavior if layers nested
    for child in root.children():
        if isinstance(child, QgsLayerTreeLayer):
            layerNodes.append(child)
    if QgsLayerTreeUtils.layersModified(layerNodes):
        print([layerNode.layer().name() for layerNode in layerNodes if layerNode.layer().isModified()])

# action.triggered.disconnect(listLayers)
action.triggered.connect(listLayers)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.