Skip to content

Commit

Permalink
Using QVariant.Type enum instead of numbers for readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor authored and alexbruy committed Oct 20, 2016
1 parent be25a29 commit 6df926d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions python/plugins/processing/algs/qgis/Eliminate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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

Expand Down Expand Up @@ -113,26 +113,26 @@ def processAlgorithm(self, progress):
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' % unicode(comparisonvalue))
elif selectType == 6:
elif selectType == QVariant.Double:
try:
y = float(comparisonvalue)
except ValueError:
selectionError = True
msg = self.tr('Cannot convert "%s" to float' % unicode(comparisonvalue))
elif selectType == 10:
elif selectType == QVariant.String:
# 10: string, boolean
try:
y = unicode(comparisonvalue)
except ValueError:
selectionError = True
msg = self.tr('Cannot convert "%s" to unicode' % unicode(comparisonvalue))
elif selectType == 14:
elif selectType == QVariant.Date:
# date
dateAndFormat = comparisonvalue.split(' ')

Expand All @@ -157,7 +157,7 @@ def processAlgorithm(self, progress):
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)

Expand All @@ -173,14 +173,14 @@ def processAlgorithm(self, progress):
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 = unicode(aValue)
elif selectType == 14:
elif selectType == QVariant.Date:
# date
x = aValue # should be date

Expand Down

0 comments on commit 6df926d

Please sign in to comment.