Skip to content

Commit 08505b3

Browse files
committedNov 30, 2016
[processing] Allow restricting fields to date/time types
1 parent b0662f9 commit 08505b3

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed
 

‎python/plugins/processing/core/parameters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ class ParameterTableField(Parameter):
13391339

13401340
DATA_TYPE_NUMBER = 0
13411341
DATA_TYPE_STRING = 1
1342+
DATA_TYPE_DATETIME = 2
13421343
DATA_TYPE_ANY = -1
13431344

13441345
def __init__(self, name='', description='', parent=None, datatype=-1,
@@ -1376,6 +1377,8 @@ def dataType(self):
13761377
return 'numeric'
13771378
elif self.datatype == self.DATA_TYPE_STRING:
13781379
return 'string'
1380+
elif self.datatype == self.DATA_TYPE_DATETIME:
1381+
return 'datetime'
13791382
else:
13801383
return 'any'
13811384

@@ -1397,6 +1400,9 @@ def fromScriptCode(self, line):
13971400
elif definition.lower().strip().startswith('field string'):
13981401
parent = definition.strip()[len('field string') + 1:]
13991402
datatype = ParameterTableField.DATA_TYPE_STRING
1403+
elif definition.lower().strip().startswith('field datetime'):
1404+
parent = definition.strip()[len('field datetime') + 1:]
1405+
datatype = ParameterTableField.DATA_TYPE_DATETIME
14001406
else:
14011407
parent = definition.strip()[len('field') + 1:]
14021408
datatype = ParameterTableField.DATA_TYPE_ANY

‎python/plugins/processing/gui/wrappers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,8 @@ def createWidget(self):
10221022
widget.setFilters(QgsFieldProxyModel.Numeric)
10231023
elif self.param.datatype == ParameterTableField.DATA_TYPE_STRING:
10241024
widget.setFilters(QgsFieldProxyModel.String)
1025-
1025+
elif self.param.datatype == ParameterTableField.DATA_TYPE_DATETIME:
1026+
widget.setFilters(QgsFieldProxyModel.Date | QgsFieldProxyModel.Time)
10261027
return widget
10271028
else:
10281029
widget = QComboBox()
@@ -1067,6 +1068,8 @@ def getFields(self):
10671068
elif self.param.datatype == ParameterTableField.DATA_TYPE_NUMBER:
10681069
fieldTypes = [QVariant.Int, QVariant.Double, QVariant.LongLong,
10691070
QVariant.UInt, QVariant.ULongLong]
1071+
elif self.param.datatype == ParameterTableField.DATA_TYPE_DATETIME:
1072+
fieldTypes = [QVariant.Date, QVariant.Time, QVariant.DateTime]
10701073

10711074
fieldNames = set()
10721075
for field in self._layer.fields():

‎python/plugins/processing/modeler/ModelerParameterDefinitionDialog.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def setupUi(self):
140140
self.datatypeCombo.addItem(self.tr('Any'), -1)
141141
self.datatypeCombo.addItem(self.tr('Number'), 0)
142142
self.datatypeCombo.addItem(self.tr('String'), 1)
143+
self.datatypeCombo.addItem(self.tr('Date/time'), 2)
143144
self.verticalLayout.addWidget(self.datatypeCombo)
144145

145146
if self.param is not None and self.param.datatype is not None:

0 commit comments

Comments
 (0)
Please sign in to comment.