36
36
37
37
from qgis .core import QgsCoordinateReferenceSystem , QgsVectorLayer , QgsApplication
38
38
from qgis .PyQt .QtWidgets import QCheckBox , QComboBox , QLineEdit , QPlainTextEdit , QWidget , QHBoxLayout , QToolButton
39
- from qgis .gui import QgsFieldExpressionWidget , QgsExpressionLineEdit , QgsProjectionSelectionWidget , QgsGenericProjectionSelector
39
+ from qgis .gui import (QgsFieldExpressionWidget ,
40
+ QgsExpressionLineEdit ,
41
+ QgsProjectionSelectionWidget ,
42
+ QgsGenericProjectionSelector ,
43
+ QgsFieldComboBox ,
44
+ QgsFieldProxyModel )
40
45
from qgis .PyQt .QtCore import pyqtSignal , QObject , QVariant
41
46
42
47
from processing .gui .NumberInputPanel import NumberInputPanel
@@ -861,7 +866,13 @@ def createWidget(self):
861
866
if self .param .multiple :
862
867
return MultipleInputPanel (options = [])
863
868
else :
864
- widget = QComboBox ()
869
+ widget = QgsFieldComboBox ()
870
+ widget .setAllowEmptyFieldName (self .param .optional )
871
+ if self .param .datatype == ParameterTableField .DATA_TYPE_NUMBER :
872
+ widget .setFilters (QgsFieldProxyModel .Numeric )
873
+ elif self .param .datatype == ParameterTableField .DATA_TYPE_STRING :
874
+ widget .setFilters (QgsFieldProxyModel .String )
875
+
865
876
return widget
866
877
else :
867
878
widget = QComboBox ()
@@ -894,10 +905,8 @@ def refreshItems(self):
894
905
if self .param .multiple :
895
906
self .widget .updateForOptions (self .getFields ())
896
907
else :
897
- self .widget .clear ()
898
- if self .param .optional :
899
- self .widget .addItem (self .tr (self .NOT_SET ))
900
- self .widget .addItems (self .getFields ())
908
+ self .widget .setLayer (self ._layer )
909
+ self .widget .setCurrentIndex (0 )
901
910
902
911
def getFields (self ):
903
912
if self ._layer is None :
@@ -916,7 +925,7 @@ def getFields(self):
916
925
return sorted (list (fieldNames ), key = cmp_to_key (locale .strcoll ))
917
926
918
927
def setValue (self , value ):
919
- if self .dialogType == DIALOG_STANDARD :
928
+ if self .dialogType in ( DIALOG_STANDARD , DIALOG_BATCH ) :
920
929
if self .param .multiple :
921
930
options = self .widget .options
922
931
selected = []
@@ -925,7 +934,7 @@ def setValue(self, value):
925
934
selected .append (i )
926
935
self .widget .setSelectedItems (selected )
927
936
else :
928
- self .setComboValue (value )
937
+ self .widget . setField (value )
929
938
else :
930
939
self .setComboValue (value )
931
940
@@ -934,9 +943,10 @@ def value(self):
934
943
if self .param .multiple :
935
944
return [self .widget .options [i ] for i in self .widget .selectedoptions ]
936
945
else :
937
- if self .param .optional and self .widget .currentIndex () == 0 :
946
+ f = self .widget .field ()
947
+ if self .param .optional and not f :
938
948
return None
939
- return self . widget . currentText ()
949
+ return f
940
950
else :
941
951
def validator (v ):
942
952
return bool (v ) or self .param .optional
0 commit comments