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 a7092ca commit dbf6169
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions python/plugins/processing/algs/qgis/Eliminate.py
Expand Up @@ -25,8 +25,9 @@

__revision__ = '$Format:%H$'

from PyQt4.QtCore import QLocale, QDate
from PyQt4.QtCore import QLocale, QDate, QVariant
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.ProcessingLog import ProcessingLog
Expand All @@ -53,6 +54,9 @@ class Eliminate(GeoAlgorithm):
MODE_SMALLEST_AREA = 1
MODE_BOUNDARY = 2

def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'eliminate.png'))

This comment has been minimized.

Copy link
@pgathogo

pgathogo Oct 24, 2016

Hi,
QIcon is throwing a stack trace, I think you need to include QtGui module.

Regards
Paul

This comment has been minimized.

Copy link
@gacarrillor

gacarrillor Nov 4, 2016

Author Member

@pgathogo, this was my original commit (6df926d) I never added such getIcon method. It was wrongly included when "cherry picking" my commit.

Regards


def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Eliminate sliver polygons')
self.group, self.i18n_group = self.trAlgorithm('Vector geometry tools')
Expand Down Expand Up @@ -91,6 +95,7 @@ def processAlgorithm(self, progress):
boundary = self.getParameterValue(self.MODE) == self.MODE_BOUNDARY
smallestArea = self.getParameterValue(self.MODE) == self.MODE_SMALLEST_AREA
keepSelection = self.getParameterValue(self.KEEPSELECTION)
processLayer = vector.duplicateInMemory(inLayer)

This comment has been minimized.

Copy link
@bstroebl

bstroebl Oct 26, 2016

what's this line about to do? processLayer is not referred to further down in the script. If it is needed anyways you should import vector. Currently this script throws a runtime error.

This comment has been minimized.

Copy link
@gacarrillor

gacarrillor Nov 4, 2016

Author Member

@bstroebl, this was my original commit (6df926d) I never added such duplicateInMemory method. It was wrongly included when "cherry picking" my commit.

Regards


if not keepSelection:
# Make a selection with the values provided
Expand All @@ -102,26 +107,26 @@ def processAlgorithm(self, progress):
selectType = inLayer.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:
# 10: string, boolean
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 @@ -146,7 +151,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 @@ -162,14 +167,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 dbf6169

Please sign in to comment.