Skip to content
Permalink
Browse files

Processing - Adapt RefactorFields to work on tables as well as vector…

… layers
  • Loading branch information
arnaud-morvan committed Apr 28, 2016
1 parent afbe914 commit 7847f971d490e57a5ebb58367d26b29245a65251
@@ -30,7 +30,7 @@
from qgis.utils import iface
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTable
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector

@@ -52,13 +52,15 @@ def __init__(self):
def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Refactor fields')
self.group, self.i18n_group = self.trAlgorithm('Vector table tools')
self.addParameter(ParameterVector(self.INPUT_LAYER,
self.tr('Input layer'),
[ParameterVector.VECTOR_TYPE_ANY], False))
self.addParameter(ParameterTable(self.INPUT_LAYER,
self.tr('Input layer'),
False))
self.addParameter(ParameterFieldsMapping(self.FIELDS_MAPPING,
self.tr('Fields mapping'), self.INPUT_LAYER))
self.tr('Fields mapping'),
self.INPUT_LAYER))
self.addOutput(OutputVector(self.OUTPUT_LAYER,
self.tr('Refactored')))
self.tr('Refactored'),
base_input=self.INPUT_LAYER))

def processAlgorithm(self, progress):
layer = self.getParameterValue(self.INPUT_LAYER)
@@ -120,7 +122,9 @@ def processAlgorithm(self, progress):
for current, inFeat in enumerate(features):
rownum = current + 1

outFeat.setGeometry(inFeat.geometry())
geometry = inFeat.geometry()
if geometry is not None:
outFeat.setGeometry(geometry)

attrs = []
for i in xrange(0, len(mapping)):
@@ -56,7 +56,8 @@ def getWidgetFromParameter(self, param):
else:
items = []
self.dependentItems[param.parent] = items
items.append(param.name)
items.append(param)

parent = self.alg.getParameterFromName(param.parent)
if isinstance(parent, ParameterVector):
layers = dataobjects.getVectorLayers(parent.shapetype)
@@ -76,16 +77,17 @@ def updateDependentFields(self):
layer = sender.itemData(sender.currentIndex())
children = self.dependentItems[sender.name]
for child in children:
widget = self.valueItems[child]
widget = self.valueItems[child.name]
if isinstance(widget, FieldsMappingPanel):
widget.setLayer(layer)
ParametersPanel.updateDependentFields(self)

def somethingDependsOnThisParameter(self, parent):
for param in self.alg.parameters:
if isinstance(param, ParameterFieldsMapping):
if param.parent == parent.name:
return True
return False
return ParametersPanel.somethingDependsOnThisParameter(self, parent)


class FieldsMapperParametersDialog(AlgorithmDialog):
@@ -463,7 +463,7 @@ def on_model_rowsInserted(self, parent, start, end):
self.model.index(end, self.model.columnCount() - 1))

def updateLayerCombo(self):
layers = dataobjects.getVectorLayers()
layers = dataobjects.getTables()
layers.sort(key=lambda lay: lay.name())
for layer in layers:
self.layerCombo.addItem(layer.name(), layer)

0 comments on commit 7847f97

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