Skip to content

Commit

Permalink
[processing] don't allow multiple enum items to be selected if
Browse files Browse the repository at this point in the history
allowMultiple is not set
  • Loading branch information
alexbruy authored and nyalldawson committed May 11, 2018
1 parent 39456ba commit 3ec2dfa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions python/plugins/processing/gui/enummodelerwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.