Skip to content

Commit

Permalink
[processing] improve default values handling in the enum modeler GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed May 11, 2018
1 parent e97212e commit 26a97a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions python/plugins/processing/gui/enummodelerwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

model.appendRow(item)

Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 26a97a7

Please sign in to comment.