Using QVariant.Type enum instead of numbers for readability.

(cherry picked from commit 6df926dfe6e3e8f7ac330fbb9206dc69492da6ed)
This commit is contained in:
Germán Carrillo 2016-10-20 07:43:00 -05:00 committed by Alexander Bruy
parent 4730d25012
commit 62a9436178

View File

@ -30,7 +30,7 @@ __revision__ = '$Format:%H$'
import os
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtCore import QLocale, QDate
from qgis.PyQt.QtCore import QLocale, QDate, QVariant
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry
@ -115,26 +115,26 @@ class Eliminate(GeoAlgorithm):
selectType = processLayer.fields()[selectindex].type()
selectionError = False
if selectType == 2 or selectType == 4:
if selectType == QVariant.Int or selectType == QVariant.LongLong:
try:
y = int(comparisonvalue)
except ValueError:
selectionError = True
msg = self.tr('Cannot convert "%s" to integer' % str(comparisonvalue))
elif selectType == 6:
elif selectType == QVariant.Double:
try:
y = float(comparisonvalue)
except ValueError:
selectionError = True
msg = self.tr('Cannot convert "%s" to float' % str(comparisonvalue))
elif selectType == 10:
elif selectType == QVariant.String:
# 10: string, boolean
try:
y = str(comparisonvalue)
except ValueError:
selectionError = True
msg = self.tr('Cannot convert "%s" to unicode' % str(comparisonvalue))
elif selectType == 14:
elif selectType == QVariant.Date:
# date
dateAndFormat = comparisonvalue.split(' ')
@ -159,7 +159,7 @@ class Eliminate(GeoAlgorithm):
msg += self.tr('Enter the date and the date format, e.g. "07.26.2011" "MM.dd.yyyy".')
if (comparison == 'begins with' or comparison == 'contains') \
and selectType != 10:
and selectType != QVariant.String:
selectionError = True
msg = self.tr('"%s" can only be used with string fields' % comparison)
@ -175,14 +175,14 @@ class Eliminate(GeoAlgorithm):
if aValue is None:
continue
if selectType == 2 or selectType == 4:
if selectType == QVariant.Int or selectType == QVariant.LongLong:
x = int(aValue)
elif selectType == 6:
elif selectType == QVariant.Double:
x = float(aValue)
elif selectType == 10:
elif selectType == QVariant.String:
# 10: string, boolean
x = str(aValue)
elif selectType == 14:
elif selectType == QVariant.Date:
# date
x = aValue # should be date