Skip to content
Permalink
Browse files

[processing] Use standard field combo box for field choices

  • Loading branch information
nyalldawson committed Nov 14, 2016
1 parent 85c8c97 commit d3f5314bf5d4d358cd9952da4d651dbf1824b9f6
Showing with 20 additions and 10 deletions.
  1. +20 −10 python/plugins/processing/gui/wrappers.py
@@ -36,7 +36,12 @@

from qgis.core import QgsCoordinateReferenceSystem, QgsVectorLayer, QgsApplication
from qgis.PyQt.QtWidgets import QCheckBox, QComboBox, QLineEdit, QPlainTextEdit, QWidget, QHBoxLayout, QToolButton
from qgis.gui import QgsFieldExpressionWidget, QgsExpressionLineEdit, QgsProjectionSelectionWidget, QgsGenericProjectionSelector
from qgis.gui import (QgsFieldExpressionWidget,
QgsExpressionLineEdit,
QgsProjectionSelectionWidget,
QgsGenericProjectionSelector,
QgsFieldComboBox,
QgsFieldProxyModel)
from qgis.PyQt.QtCore import pyqtSignal, QObject, QVariant

from processing.gui.NumberInputPanel import NumberInputPanel
@@ -861,7 +866,13 @@ def createWidget(self):
if self.param.multiple:
return MultipleInputPanel(options=[])
else:
widget = QComboBox()
widget = QgsFieldComboBox()
widget.setAllowEmptyFieldName(self.param.optional)
if self.param.datatype == ParameterTableField.DATA_TYPE_NUMBER:
widget.setFilters(QgsFieldProxyModel.Numeric)
elif self.param.datatype == ParameterTableField.DATA_TYPE_STRING:
widget.setFilters(QgsFieldProxyModel.String)

return widget
else:
widget = QComboBox()
@@ -894,10 +905,8 @@ def refreshItems(self):
if self.param.multiple:
self.widget.updateForOptions(self.getFields())
else:
self.widget.clear()
if self.param.optional:
self.widget.addItem(self.tr(self.NOT_SET))
self.widget.addItems(self.getFields())
self.widget.setLayer(self._layer)
self.widget.setCurrentIndex(0)

def getFields(self):
if self._layer is None:
@@ -916,7 +925,7 @@ def getFields(self):
return sorted(list(fieldNames), key=cmp_to_key(locale.strcoll))

def setValue(self, value):
if self.dialogType == DIALOG_STANDARD:
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
if self.param.multiple:
options = self.widget.options
selected = []
@@ -925,7 +934,7 @@ def setValue(self, value):
selected.append(i)
self.widget.setSelectedItems(selected)
else:
self.setComboValue(value)
self.widget.setField(value)
else:
self.setComboValue(value)

@@ -934,9 +943,10 @@ def value(self):
if self.param.multiple:
return [self.widget.options[i] for i in self.widget.selectedoptions]
else:
if self.param.optional and self.widget.currentIndex() == 0:
f = self.widget.field()
if self.param.optional and not f:
return None
return self.widget.currentText()
return f
else:
def validator(v):
return bool(v) or self.param.optional

0 comments on commit d3f5314

Please sign in to comment.
You can’t perform that action at this time.