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
(cherry picked from commit 6df926d)
  • Loading branch information
gacarrillor authored and alexbruy committed Oct 20, 2016
1 parent 4730d25 commit 62a9436
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 @@ -30,7 +30,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 @@ -115,26 +115,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' % 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(' ')

Expand All @@ -159,7 +159,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 @@ -175,14 +175,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 = str(aValue)
elif selectType == 14:
elif selectType == QVariant.Date:
# date
x = aValue # should be date

Expand Down

0 comments on commit 62a9436

Please sign in to comment.