Skip to content
Permalink
Browse files

fixed #6076

Improved parametertablefield with datatype options

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@304 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf
volayaf committed Jul 21, 2012
1 parent 8175f51 commit aa3d766b88639c518121936733b21859e0b14fab
Showing with 38 additions and 17 deletions.
  1. +5 −6 src/sextante/ftools/Clip.py
  2. +21 −8 src/sextante/gui/ParametersPanel.py
  3. +12 −3 src/sextante/parameters/ParameterTableField.py
@@ -6,7 +6,6 @@
from qgis.core import *
from sextante.parameters.ParameterVector import ParameterVector
from sextante.core.QGisLayers import QGisLayers
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.outputs.OutputVector import OutputVector
from sextante.ftools import ftools_utils
from sextante.core.SextanteLog import SextanteLog
@@ -33,10 +32,10 @@ def processAlgorithm(self, progress):
vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Clip.INPUT2))
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = self.vlayerA.dataProvider()
vproviderA = vlayerA.dataProvider()
allAttrsA = vproviderA.attributeIndexes()
vproviderA.select( allAttrsA )
vproviderB = self.vlayerB.dataProvider()
vproviderB = vlayerB.dataProvider()
allAttrsB = vproviderB.attributeIndexes()
vproviderB.select( allAttrsB )
# check for crs compatibility
@@ -59,10 +58,10 @@ def processAlgorithm(self, progress):
# there is selection in input layer
if useSelection:
nFeat = vlayerA.selectedFeatureCount()
selectionA = self.vlayerA.selectedFeatures()
selectionA = vlayerA.selectedFeatures()
# we have selection in overlay layer
if useSelection2:
selectionB = self.vlayerB.selectedFeaturesIds()
selectionB = vlayerB.selectedFeaturesIds()
for inFeatA in selectionA:
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
@@ -156,7 +155,7 @@ def processAlgorithm(self, progress):
nFeat = vproviderA.featureCount()
# we have selection in overlay layer
if useSelection2:
selectionB = self.vlayerB.selectedFeaturesIds()
selectionB = vlayerB.selectedFeaturesIds()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
@@ -1,4 +1,5 @@
import os
import locale
from PyQt4 import QtCore, QtGui
from sextante.gui.OutputSelectionPanel import OutputSelectionPanel
from sextante.core.QGisLayers import QGisLayers
@@ -219,9 +220,7 @@ def getWidgetFromParameter(self, param):
else:
layers = QGisLayers.getTables()
if len(layers)>0:
fields = self.getFields(layers[0])
for i in fields:
item.addItem(fields[i].name())
item.addItems(self.getFields(layers[0], param.datatype))
elif isinstance(param, ParameterSelection):
item = QtGui.QComboBox()
item.addItems(param.options)
@@ -266,12 +265,26 @@ def updateDependentFields(self):
for child in children:
widget = self.valueItems[child]
widget.clear()
fields = self.getFields(layer)
for i in fields:
widget.addItem(fields[i].name())
widget.addItems(self.getFields(layer, self.alg.getParameterFromName(child).datatype))

def getFields(self, layer):
return layer.dataProvider().fields()
def getFields(self, layer, datatype):
fieldTypes = []
if datatype == ParameterTableField.DATA_TYPE_STRING:
fieldTypes = [QVariant.String]
elif datatype == ParameterTableField.DATA_TYPE_NUMBER:
fieldTypes = [QVariant.Int, QVariant.Double]

fieldNames = []
fieldMap = layer.pendingFields()
if len(fieldTypes) == 0:
for idx, field in fieldMap.iteritems():
if not field.name() in fieldNames:
fieldNames.append( unicode( field.name() ) )
else:
for idx, field in fieldMap.iteritems():
if field.type() in fieldTypes and not field.name() in fieldNames:
fieldNames.append( unicode( field.name() ) )
return sorted( fieldNames, cmp=locale.strcoll )

def somethingDependsOnThisParameter(self, parent):
for param in self.alg.parameters:
@@ -2,10 +2,15 @@

class ParameterTableField(Parameter):

def __init__(self, name="", description="", parent=None):
DATA_TYPE_NUMBER = 0
DATA_TYPE_STRING = 1
DATA_TYPE_ANY = -1

def __init__(self, name="", description="", parent=None, datatype=-1):
Parameter.__init__(self, name, description)
self.parent = parent
self.value = None
self.datatype = datatype

def getValueAsCommandLineParameter(self):
return "\"" + str(self.value) + "\""
@@ -15,11 +20,15 @@ def getAsScriptCode(self):

def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
"|" + str(self.parent)
"|" + str(self.parent) + "|" + str(self.datatype)


def deserialize(self, s):
tokens = s.split("|")
return ParameterTableField(tokens[0], tokens[1], tokens[2])
if len(tokens) == 4:
return ParameterTableField(tokens[0], tokens[1], tokens[2], int(tokens[3]))
else:
return ParameterTableField(tokens[0], tokens[1], tokens[2])

def __str__(self):
return self.name + " <" + self.__module__.split(".")[-1] +" from " + self.value + ">"

0 comments on commit aa3d766

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