Skip to content
Permalink
Browse files

[processing] Allow restricting fields to date/time types

  • Loading branch information
nyalldawson committed Nov 30, 2016
1 parent b0662f9 commit 08505b388a6683d2b8fb415e705f8287b6ec6867
@@ -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 @@ def dataType(self):
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 @@ def fromScriptCode(self, line):
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 @@ def createWidget(self):
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 @@ def getFields(self):
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 @@ def setupUi(self):
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:

0 comments on commit 08505b3

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