Skip to content

Commit

Permalink
[processing] correctly restore default values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed May 11, 2018
1 parent 0046b9f commit e97212e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
41 changes: 7 additions & 34 deletions python/plugins/processing/gui/enummodelerwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,11 @@ 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()

item = QStandardItem('new item')
item.setCheckable(True)
item.setCheckState(Qt.Unchecked)
item.setDropEnabled(False)

model.appendRow(item)
Expand Down Expand Up @@ -122,24 +100,19 @@ def allowMultiple(self):
def setOptions(self, options):
model = self.lstItems.model()
for i in options:
item = QStandardItem()
item = QStandardItem(i)
item.setCheckable(True)
item.setCheckState(Qt.Unchecked)
item.setDropEnabled(False)

model.appendRow(item)

def setDefault(self, index):
def setDefault(self, indexes):
model = self.lstItems.model()
item = model.item(index, 0)
if item:
item.setCheckState(Qt.Checked)

for i in indexes:
item = model.item(i)
if item:
item.setCheckState(Qt.Checked)

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
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def setupUi(self):
self.widget = EnumModelerWidget(self)
if self.param is not None:
self.widget.setOptions(self.param.options())
self.widget.setDefault(int(self.param.defaultValue()))
self.widget.setDefault(self.param.defaultValue())
self.widget.setAllowMultiple(bool(self.param.allowMultiple()))
self.verticalLayout.addWidget(self.widget)
elif self.paramType == parameters.PARAMETER_MATRIX or \
Expand Down

0 comments on commit e97212e

Please sign in to comment.