mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] allow multiple values in ParameterSelection
This commit is contained in:
parent
8ce93b102c
commit
36abbc427c
@ -1052,8 +1052,9 @@ class ParameterSelection(Parameter):
|
||||
|
||||
|
||||
def __init__(self, name='', description='', options=[], default=None, isSource=False,
|
||||
optional=False):
|
||||
multiple=False, optional=False):
|
||||
Parameter.__init__(self, name, description, default, optional)
|
||||
self.multiple = multiple
|
||||
isSource = parseBool(isSource)
|
||||
self.options = options
|
||||
if isSource:
|
||||
@ -1077,19 +1078,34 @@ class ParameterSelection(Parameter):
|
||||
self.default = 0
|
||||
self.value = self.default
|
||||
|
||||
def setValue(self, n):
|
||||
if n is None:
|
||||
def setValue(self, value):
|
||||
if value is None:
|
||||
if not self.optional:
|
||||
return False
|
||||
self.value = 0
|
||||
return True
|
||||
|
||||
try:
|
||||
n = int(n)
|
||||
self.value = n
|
||||
if isinstance(value, list):
|
||||
if not self.multiple:
|
||||
return False
|
||||
values = []
|
||||
for v in value:
|
||||
try:
|
||||
n = int(v)
|
||||
values.append(n)
|
||||
except:
|
||||
return False
|
||||
if not self.optional and len(values) == 0:
|
||||
return False
|
||||
self.value = values
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
n = int(value)
|
||||
self.value = n
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def fromScriptCode(self, line):
|
||||
@ -1101,6 +1117,13 @@ class ParameterSelection(Parameter):
|
||||
elif definition.lower().strip().startswith('selection'):
|
||||
options = definition.strip()[len('selection '):].split(';')
|
||||
return ParameterSelection(name, descName, options, optional=isOptional)
|
||||
elif definition.lower().strip().startswith('multipleselectionfromfile'):
|
||||
options = definition.strip()[len('multipleselectionfromfile '):].split(';')
|
||||
return ParameterSelection(name, descName, options, isSource=True,
|
||||
multiple=True, optional=isOptional)
|
||||
elif definition.lower().strip().startswith('multipleselection'):
|
||||
options = definition.strip()[len('multipleselection '):].split(';')
|
||||
return ParameterSelection(name, descName, options, multiple=True, optional=isOptional)
|
||||
|
||||
|
||||
class ParameterEvaluationException(Exception):
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
BooleanWidget.py
|
||||
wrappers.py
|
||||
---------------------
|
||||
Date : May 2016
|
||||
Copyright : (C) 2016 by Arnaud Morvan, Victor Olaya
|
||||
@ -519,17 +519,26 @@ class RasterWidgetWrapper(WidgetWrapper):
|
||||
class SelectionWidgetWrapper(WidgetWrapper):
|
||||
|
||||
def createWidget(self):
|
||||
widget = QComboBox()
|
||||
widget.addItems(self.param.options)
|
||||
if self.param.default:
|
||||
widget.setCurrentIndex(self.param.default)
|
||||
return widget
|
||||
if self.param.multiple:
|
||||
return MultipleInputPanel(options=self.param.options)
|
||||
else:
|
||||
widget = QComboBox()
|
||||
widget.addItems(self.param.options)
|
||||
if self.param.default:
|
||||
widget.setCurrentIndex(self.param.default)
|
||||
return widget
|
||||
|
||||
def setValue(self, value):
|
||||
self.widget.setCurrentIndex(int(value))
|
||||
if self.param.multiple:
|
||||
self.widget.setSelectedItems(value)
|
||||
else:
|
||||
self.widget.setCurrentIndex(int(value))
|
||||
|
||||
def value(self):
|
||||
return self.widget.currentIndex()
|
||||
if self.param.multiple:
|
||||
return self.widget.selectedoptions
|
||||
else:
|
||||
return self.widget.currentIndex()
|
||||
|
||||
|
||||
class VectorWidgetWrapper(WidgetWrapper):
|
||||
@ -794,7 +803,7 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
||||
elif self.dialogType == DIALOG_BATCH:
|
||||
return self.widget.text()
|
||||
else:
|
||||
text = self.widget.text()
|
||||
text = self.widget.text()
|
||||
if not bool(text) and not self.param.optional:
|
||||
raise InvalidParameterValue()
|
||||
return text
|
||||
@ -810,7 +819,7 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
||||
return bool(v) or self.param.optional
|
||||
return self.comboValue(validator)
|
||||
|
||||
def anotherParameterWidgetHasChanged(self,wrapper):
|
||||
def anotherParameterWidgetHasChanged(self, wrapper):
|
||||
if wrapper.param.name == self.param.parent:
|
||||
layer = wrapper.value()
|
||||
if layer is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user