Skip to content
Permalink
Browse files

[processing] don't allow multiple enum items to be selected if

allowMultiple is not set
  • Loading branch information
alexbruy authored and nyalldawson committed May 7, 2018
1 parent 39456ba commit 3ec2dfa611c22b4a5e999f41fa674a472051fb2f
Showing with 27 additions and 0 deletions.
  1. +27 −0 python/plugins/processing/gui/enummodelerwidget.py
@@ -54,6 +54,27 @@ def __init__(self, parent=None):

self.lstItems.setModel(QStandardItemModel())

self.lstItems.clicked.connect(self.handleCheckbox)

def handleCheckbox(self, index):
model = self.lstItems.model()
clickedItem = model.itemFromIndex(index)

prevIndex = None
for i in range(model.rowCount()):
if model.item(i).checkState() == Qt.Checked:
prevIndex = i
break

if prevIndex is None:
clickedItem.setCheckState(Qt.Checked)
else:
if self.chkAllowMultiple.isChecked():
clickedItem.setCheckState(Qt.Checked)
else:
model.item(prevIndex).setCheckState(Qt.Unchecked)
clickedItem.setCheckState(Qt.Checked)

def addItem(self):
model = self.lstItems.model()

@@ -113,3 +134,9 @@ def setDefault(self, index):

def setAllowMultiple(self, allowMultiple):
self.chkAllowMultiple.setChecked(allowMultiple)

model = self.lstItems.model()
for i in range(model.rowCount()):
if model.item(i).checkState() == Qt.Checked:
model.item(i).setCheckState(Qt.Unchecked)
break

0 comments on commit 3ec2dfa

Please sign in to comment.
You can’t perform that action at this time.