Skip to content
Permalink
Browse files
[processing] fixed display ad handling of optional table fields in pa…
…rameters panel
  • Loading branch information
volaya committed Mar 26, 2014
1 parent cbeb528 commit eb360e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
@@ -50,10 +50,12 @@ def defineCharacteristics(self):
[ParameterVector.VECTOR_TYPE_ANY]))
self.addParameter(ParameterTableField(self.WEIGHT, 'Weight field',
MeanCoords.POINTS,
ParameterTableField.DATA_TYPE_NUMBER))
ParameterTableField.DATA_TYPE_NUMBER,
optional = True))
self.addParameter(ParameterTableField(self.UID, 'Unique ID field',
MeanCoords.POINTS,
ParameterTableField.DATA_TYPE_NUMBER))
ParameterTableField.DATA_TYPE_NUMBER,
optional = True))

self.addOutput(OutputVector(MeanCoords.OUTPUT, 'Result'))

@@ -63,8 +65,17 @@ def processAlgorithm(self, progress):
weightField = self.getParameterValue(self.WEIGHT)
uniqueField = self.getParameterValue(self.UID)

weightIndex = layer.fieldNameIndex(weightField)
uniqueIndex = layer.fieldNameIndex(uniqueField)
print weightField, uniqueField

if weightField is None:
weightIndex = -1
else:
weightIndex = layer.fieldNameIndex(weightField)

if uniqueField is None:
uniqueIndex = -1
else:
uniqueIndex = layer.fieldNameIndex(uniqueField)

fieldList = [QgsField('MEAN_X', QVariant.Double, '', 24, 15),
QgsField('MEAN_Y', QVariant.Double, '', 24, 15),
@@ -82,7 +93,10 @@ def processAlgorithm(self, progress):
for feat in features:
current += 1
progress.setPercentage(current * total)
clazz = str(feat.attributes()[uniqueIndex]).strip()
if uniqueIndex == -1:
clazz = "Single class"
else:
clazz = str(feat.attributes()[uniqueIndex]).strip()
if weightIndex == -1:
weight = 1.00
else:
@@ -190,6 +190,8 @@ def setParamValue(self, param, widget):
elif isinstance(param, ParameterRange):
return param.setValue(widget.getValue())
if isinstance(param, ParameterTableField):
if param.optional and widget.currentIndex() == 0:
return param.setValue(None)
return param.setValue(widget.currentText())
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
@@ -268,6 +268,8 @@ def getWidgetFromParameter(self, param):
else:
layers = dataobjects.getTables()
if len(layers) > 0:
if param.optional:
item.addItem("[not set]")
item.addItems(self.getFields(layers[0], param.datatype))
elif isinstance(param, ParameterSelection):
item = QtGui.QComboBox()

0 comments on commit eb360e0

Please sign in to comment.