Skip to content

Commit

Permalink
[processing] add matrix and enum parameters to wrappers and handle them
Browse files Browse the repository at this point in the history
in the modeler dialogs
  • Loading branch information
alexbruy authored and nyalldawson committed May 11, 2018
1 parent 038da11 commit 1ba34dc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 33 deletions.
85 changes: 53 additions & 32 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -64,6 +64,7 @@
QgsProcessingParameterFeatureSource,
QgsProcessingParameterMapLayer,
QgsProcessingParameterBand,
QgsProcessingParameterMatrix,
QgsProcessingParameterDistance,
QgsProcessingFeatureSourceDefinition,
QgsProcessingOutputRasterLayer,
Expand Down Expand Up @@ -556,19 +557,26 @@ def value(self):
class FixedTableWidgetWrapper(WidgetWrapper):

def createWidget(self):
return FixedTablePanel(self.param)
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
return FixedTablePanel(self.param)
else:
self.combobox = QComboBox()
values = self.dialog.getAvailableValuesOfType(QgsProcessingParameterMatrix)
for v in values:
self.combobox.addItem(self.dialog.resolveValueDescription(v), v)
return self.combobox

def setValue(self, value):
self.widget.setValue(value)
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
self.widget.setValue(value)
else:
self.setComboValue(value, combobox=self.combobox)

def value(self):
if self.dialogType == DIALOG_MODELER:
table = self.widget.table
if not bool(table) and not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
raise InvalidParameterValue()
return ParameterFixedTable.tableToString(table)
else:
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
return self.widget.table
else:
return self.comboValue(combobox=self.combobox)


class MultipleLayerWidgetWrapper(WidgetWrapper):
Expand Down Expand Up @@ -959,40 +967,53 @@ def selectFile(self):
class EnumWidgetWrapper(WidgetWrapper):

def createWidget(self, useCheckBoxes=False, columns=1):
self._useCheckBoxes = useCheckBoxes
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
return CheckboxesPanel(options=self.param.options(),
multiple=self.param.allowMultiple(),
columns=columns)
if self.param.allowMultiple():
return MultipleInputPanel(options=self.param.options())
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
self._useCheckBoxes = useCheckBoxes
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
return CheckboxesPanel(options=self.param.options(),
multiple=self.param.allowMultiple(),
columns=columns)
if self.param.allowMultiple():
return MultipleInputPanel(options=self.param.options())
else:
widget = QComboBox()
for i, option in enumerate(self.param.options()):
widget.addItem(option, i)
if self.param.defaultValue():
widget.setCurrentIndex(widget.findData(self.param.defaultValue()))
return widget
else:
widget = QComboBox()
for i, option in enumerate(self.param.options()):
widget.addItem(option, i)
if self.param.defaultValue():
widget.setCurrentIndex(widget.findData(self.param.defaultValue()))
return widget
self.combobox = QComboBox()
values = self.dialog.getAvailableValuesOfType(QgsProcessingParameterEnum)
for v in values:
self.combobox.addItem(self.dialog.resolveValueDescription(v), v)
return self.combobox

def setValue(self, value):
if value is None or value == NULL:
return

if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
self.widget.setValue(value)
return
if self.param.allowMultiple():
self.widget.setSelectedItems(value)
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
self.widget.setValue(value)
return
if self.param.allowMultiple():
self.widget.setSelectedItems(value)
else:
self.widget.setCurrentIndex(self.widget.findData(value))
else:
self.widget.setCurrentIndex(self.widget.findData(value))
self.setComboValue(value, combobox=self.combobox)

def value(self):
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
return self.widget.value()
if self.param.allowMultiple():
return self.widget.selectedoptions
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
return self.widget.value()
if self.param.allowMultiple():
return self.widget.selectedoptions
else:
return self.widget.currentData()
else:
return self.widget.currentData()
return self.comboValue(combobox=self.combo)


class FeatureSourceWidgetWrapper(WidgetWrapper):
Expand Down
Expand Up @@ -419,9 +419,12 @@ def accept(self):
elif (self.paramType == parameters.PARAMETER_CRS or
isinstance(self.param, QgsProcessingParameterCrs)):
self.param = QgsProcessingParameterCrs(name, description, self.selector.crs().authid())
if (self.paramType == parameters.PARAMETER_ENUM or
elif (self.paramType == parameters.PARAMETER_ENUM or
isinstance(self.param, QgsProcessingParameterEnum)):
self.param = QgsProcessingParameterEnum(name, description, self.widget.options(), self.widget.allowMultiple(), self.widget.defaultOption())
elif (self.paramType == parameters.PARAMETER_MATRIX or
isinstance(self.param, QgsProcessingParameterMatrix)):
self.param = QgsProcessingParameterMatrix(name, description, hasFixedNumberRows=self.widget.fixedRows(), headers=self.widget.headers(), defaultValue=self.widget.value())
else:
if self.paramType:
typeId = self.paramType
Expand Down

0 comments on commit 1ba34dc

Please sign in to comment.