Skip to content
Permalink
Browse files

Using QVariant.Type enum instead of numbers for readability.

(cherry picked from commit 6df926d)
  • Loading branch information
gacarrillor authored and alexbruy committed Oct 20, 2016
1 parent e64a96f commit 2c6ebf1d93da513dff1ac660dcf7460f3e0e53cf
Showing with 10 additions and 10 deletions.
  1. +10 −10 python/plugins/processing/algs/qgis/Eliminate.py
@@ -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

@@ -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(' ')

@@ -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)

@@ -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

0 comments on commit 2c6ebf1

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