Skip to content
Permalink
Browse files

[processing] improve default values handling in the enum modeler GUI

  • Loading branch information
alexbruy authored and nyalldawson committed May 8, 2018
1 parent e97212e commit 26a97a7da75086370e24128f457cb715a2818e65
@@ -55,12 +55,37 @@ def __init__(self, parent=None):

self.lstItems.setModel(QStandardItemModel())

self.lstItems.model().itemChanged.connect(self.onItemChanged)

def onItemChanged(self, item):
model = self.lstItems.model()
checkedItem = None
for i in range(model.rowCount()):
itm = model.item(i)
if itm.checkState() == Qt.Checked and itm.data() == Qt.Checked:
checkedItem = i
break

model.blockSignals(True)
if checkedItem is None:
item.setData(item.checkState())
else:
if self.chkAllowMultiple.isChecked():
item.setData(item.checkState())
else:
model.item(checkedItem).setCheckState(Qt.Unchecked)
model.item(checkedItem).setData(Qt.Unchecked)

item.setData(item.checkState())
model.blockSignals(False)

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

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

model.appendRow(item)

@@ -103,6 +128,7 @@ def setOptions(self, options):
item = QStandardItem(i)
item.setCheckable(True)
item.setDropEnabled(False)
item.setData(Qt.Unchecked)

model.appendRow(item)

@@ -113,6 +139,7 @@ def setDefault(self, indexes):
item = model.item(i)
if item:
item.setCheckState(Qt.Checked)
item.setData(Qt.Checked)

def setAllowMultiple(self, allowMultiple):
self.chkAllowMultiple.setChecked(allowMultiple)
@@ -280,9 +280,9 @@ def setupUi(self):
isinstance(self.param, QgsProcessingParameterEnum):
self.widget = EnumModelerWidget(self)
if self.param is not None:
self.widget.setAllowMultiple(bool(self.param.allowMultiple()))
self.widget.setOptions(self.param.options())
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 \
isinstance(self.param, QgsProcessingParameterMatrix):

0 comments on commit 26a97a7

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