Feature request #19088

Toggle Selected Layers

Added by al piszcz over 6 years ago.

Status:Open
Priority:Normal
Assignee:-
Category:Actions
Pull Request or Patch supplied:No Resolution:
Easy fix?:Yes Copied to github as #:26918

Description

Provide a context menu from the layers panel to toggle selected layers, if checked, uncheck, if unchecked, check.

Here is a python console example:


from PyQt5.QtCore import pyqtSignal, QObject
from PyQt5.QtWidgets import QAction

class DisableEnable(QObject):
    trigger = pyqtSignal()
    def connect_and_emit_trigger(self):
        self.trigger.connect(self.handle_trigger)
        self.trigger.emit()
    def handle_trigger(self):
        print("trigger signal received")
        layers = [lyr for lyr in iface.layerTreeView().selectedLayers()]
        for lyr in layers:
            print(lyr.name())
            node=QgsProject.instance().layerTreeRoot().findLayer(lyr.id())
            if node.isVisible():
                node.setItemVisibilityChecked(False)
            else:
                node.setItemVisibilityChecked(True)
oDE=DisableEnable()
action = QAction(QIcon(), 'Toggle', iface.mainWindow())
action.setStatusTip('Toggle Selected Layer')
action.triggered.connect(oDE.handle_trigger)
action.setCheckable(True)
action.setText('Toggle\nSelected')
iface.addToolBarIcon(action)

Also available in: Atom PDF