24 changes: 19 additions & 5 deletions python/plugins/processing/algs/ftools/MeanCoords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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),
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/gui/AlgorithmExecutionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/gui/ProcessingToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self):
self.fillTree()

def textChanged(self):
text = self.searchBox.text().strip(' ')
text = self.searchBox.text().strip(' ').lower()
self._filterItem(self.algorithmTree.invisibleRootItem(), text)
if text:
self.algorithmTree.expandAll()
Expand All @@ -92,8 +92,8 @@ def _filterItem(self, item, text):
show = showChild or show
item.setHidden(not show)
return show
elif isinstance(item, TreeAlgorithmItem):
hide = bool(text) and (text not in item.text(0))
elif isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
hide = bool(text) and (text not in item.text(0).lower())
item.setHidden(hide)
return not hide
else:
Expand Down