mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[processing] Allow restricting fields to date/time types
This commit is contained in:
parent
b0662f908a
commit
08505b388a
@ -1339,6 +1339,7 @@ class ParameterTableField(Parameter):
|
||||
|
||||
DATA_TYPE_NUMBER = 0
|
||||
DATA_TYPE_STRING = 1
|
||||
DATA_TYPE_DATETIME = 2
|
||||
DATA_TYPE_ANY = -1
|
||||
|
||||
def __init__(self, name='', description='', parent=None, datatype=-1,
|
||||
@ -1376,6 +1377,8 @@ class ParameterTableField(Parameter):
|
||||
return 'numeric'
|
||||
elif self.datatype == self.DATA_TYPE_STRING:
|
||||
return 'string'
|
||||
elif self.datatype == self.DATA_TYPE_DATETIME:
|
||||
return 'datetime'
|
||||
else:
|
||||
return 'any'
|
||||
|
||||
@ -1397,6 +1400,9 @@ class ParameterTableField(Parameter):
|
||||
elif definition.lower().strip().startswith('field string'):
|
||||
parent = definition.strip()[len('field string') + 1:]
|
||||
datatype = ParameterTableField.DATA_TYPE_STRING
|
||||
elif definition.lower().strip().startswith('field datetime'):
|
||||
parent = definition.strip()[len('field datetime') + 1:]
|
||||
datatype = ParameterTableField.DATA_TYPE_DATETIME
|
||||
else:
|
||||
parent = definition.strip()[len('field') + 1:]
|
||||
datatype = ParameterTableField.DATA_TYPE_ANY
|
||||
|
@ -1022,7 +1022,8 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
||||
widget.setFilters(QgsFieldProxyModel.Numeric)
|
||||
elif self.param.datatype == ParameterTableField.DATA_TYPE_STRING:
|
||||
widget.setFilters(QgsFieldProxyModel.String)
|
||||
|
||||
elif self.param.datatype == ParameterTableField.DATA_TYPE_DATETIME:
|
||||
widget.setFilters(QgsFieldProxyModel.Date | QgsFieldProxyModel.Time)
|
||||
return widget
|
||||
else:
|
||||
widget = QComboBox()
|
||||
@ -1067,6 +1068,8 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
||||
elif self.param.datatype == ParameterTableField.DATA_TYPE_NUMBER:
|
||||
fieldTypes = [QVariant.Int, QVariant.Double, QVariant.LongLong,
|
||||
QVariant.UInt, QVariant.ULongLong]
|
||||
elif self.param.datatype == ParameterTableField.DATA_TYPE_DATETIME:
|
||||
fieldTypes = [QVariant.Date, QVariant.Time, QVariant.DateTime]
|
||||
|
||||
fieldNames = set()
|
||||
for field in self._layer.fields():
|
||||
|
@ -140,6 +140,7 @@ class ModelerParameterDefinitionDialog(QDialog):
|
||||
self.datatypeCombo.addItem(self.tr('Any'), -1)
|
||||
self.datatypeCombo.addItem(self.tr('Number'), 0)
|
||||
self.datatypeCombo.addItem(self.tr('String'), 1)
|
||||
self.datatypeCombo.addItem(self.tr('Date/time'), 2)
|
||||
self.verticalLayout.addWidget(self.datatypeCombo)
|
||||
|
||||
if self.param is not None and self.param.datatype is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user