Skip to content

Commit

Permalink
[processing] move custom parameter definition inside corresponding
Browse files Browse the repository at this point in the history
algorithm
  • Loading branch information
alexbruy committed Nov 18, 2016
1 parent fc18fd9 commit f70a3b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 64 deletions.
36 changes: 34 additions & 2 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from __future__ import print_function
from builtins import str
from builtins import range

Expand All @@ -33,11 +34,10 @@
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterTable
from processing.core.parameters import Parameter
from processing.core.outputs import OutputVector
from processing.tools import dataobjects, vector

from .fieldsmapping import ParameterFieldsMapping


class FieldsMapper(GeoAlgorithm):

Expand All @@ -55,6 +55,38 @@ def defineCharacteristics(self):
self.addParameter(ParameterTable(self.INPUT_LAYER,
self.tr('Input layer'),
False))

class ParameterFieldsMapping(Parameter):

default_metadata = {
'widget_wrapper': 'processing.algs.qgis.ui.FieldsMappingPanel.FieldsMappingWidgetWrapper'
}

def __init__(self, name='', description='', parent=None):
Parameter.__init__(self, name, description)
self.parent = parent
self.value = []

def getValueAsCommandLineParameter(self):
return '"' + str(self.value) + '"'

def setValue(self, value):
if value is None:
return False
if isinstance(value, list):
self.value = value
return True
if isinstance(value, str):
try:
self.value = eval(value)
return True
except Exception as e:
# fix_print_with_import
print(str(e)) # display error in console
return False
return False


self.addParameter(ParameterFieldsMapping(self.FIELDS_MAPPING,
self.tr('Fields mapping'),
self.INPUT_LAYER))
Expand Down
62 changes: 0 additions & 62 deletions python/plugins/processing/algs/qgis/fieldsmapping.py

This file was deleted.

0 comments on commit f70a3b9

Please sign in to comment.