mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[processing] allow selection parameters with option populated from data source
This commit is contained in:
parent
8c8a123194
commit
a58085bf4e
@ -17,6 +17,7 @@
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from processing.tools.vector import resolveFieldIndex, features
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'August 2012'
|
||||
@ -536,10 +537,21 @@ class ParameterRaster(ParameterDataObject):
|
||||
|
||||
class ParameterSelection(Parameter):
|
||||
|
||||
def __init__(self, name='', description='', options=[], default=0):
|
||||
def __init__(self, name='', description='', options=[], default=0, isSource = False):
|
||||
Parameter.__init__(self, name, description)
|
||||
self.options = options
|
||||
if isinstance(self.options, basestring):
|
||||
if isSource:
|
||||
self.options = []
|
||||
layer = QgsVectorLayer(options[0], "layer", "ogr")
|
||||
if layer.isValid():
|
||||
try:
|
||||
index = resolveFieldIndex(layer, options[1])
|
||||
feats = features(layer)
|
||||
for feature in feats:
|
||||
self.options.append(unicode(feature.attributes()[index]))
|
||||
except ValueError:
|
||||
pass
|
||||
elif isinstance(self.options, basestring):
|
||||
self.options = self.options.split(";")
|
||||
self.value = None
|
||||
self.default = int(default)
|
||||
|
@ -169,6 +169,9 @@ class ScriptAlgorithm(GeoAlgorithm):
|
||||
param = ParameterMultipleInput(tokens[0], desc,
|
||||
ParameterMultipleInput.TYPE_VECTOR_ANY)
|
||||
param.optional = False
|
||||
elif tokens[1].lower().strip().startswith('selectionfromfile'):
|
||||
options = tokens[1].strip()[len('selectionfromfile '):].split(';')
|
||||
param = ParameterSelection(tokens[0], desc, options, isSource=True)
|
||||
elif tokens[1].lower().strip().startswith('selection'):
|
||||
options = tokens[1].strip()[len('selection '):].split(';')
|
||||
param = ParameterSelection(tokens[0], desc, options)
|
||||
|
Loading…
x
Reference in New Issue
Block a user