Skip to content

Commit

Permalink
Add context menu with Select All/Clear Selection to checkboxes panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 15, 2017
1 parent 5ee3239 commit 95ab232
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion python/plugins/processing/gui/CheckboxesPanel.py
Expand Up @@ -26,7 +26,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import (
QCheckBox,
QRadioButton,
Expand All @@ -35,7 +35,10 @@
QSizePolicy,
QSpacerItem,
QWidget,
QMenu,
QAction
)
from qgis.PyQt.QtGui import QCursor


class CheckboxesPanel(QWidget):
Expand Down Expand Up @@ -70,6 +73,28 @@ def __init__(self, options, multiple, columns=2, parent=None):
0, columns)
self.setLayout(layout)

if multiple:
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.showPopupMenu)

def showPopupMenu(self):
popup_menu = QMenu()
select_all_action = QAction(self.tr('Select All'), popup_menu)
select_all_action.triggered.connect(self.selectAll)
clear_all_action = QAction(self.tr('Clear Selection'), popup_menu)
clear_all_action.triggered.connect(self.deselectAll)
popup_menu.addAction(select_all_action)
popup_menu.addAction(clear_all_action)
popup_menu.exec_(QCursor.pos())

def selectAll(self):
for (v, button) in self._buttons:
button.setChecked(True)

def deselectAll(self):
for (v, button) in self._buttons:
button.setChecked(False)

def value(self):
if self._multiple:
value = []
Expand Down

0 comments on commit 95ab232

Please sign in to comment.