Skip to content
Permalink
Browse files

[processing] correctly restore default values

  • Loading branch information
alexbruy authored and nyalldawson committed May 8, 2018
1 parent 0046b9f commit e97212e8b714df5ce8704da514e8764880e43b73
@@ -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)
@@ -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
@@ -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 \

0 comments on commit e97212e

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