Skip to content

Commit f70a3b9

Browse files
committedNov 18, 2016
[processing] move custom parameter definition inside corresponding
algorithm
1 parent fc18fd9 commit f70a3b9

File tree

2 files changed

+34
-64
lines changed

2 files changed

+34
-64
lines changed
 

‎python/plugins/processing/algs/qgis/FieldsMapper.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* *
1717
***************************************************************************
1818
"""
19+
from __future__ import print_function
1920
from builtins import str
2021
from builtins import range
2122

@@ -33,11 +34,10 @@
3334
from processing.core.GeoAlgorithm import GeoAlgorithm
3435
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3536
from processing.core.parameters import ParameterTable
37+
from processing.core.parameters import Parameter
3638
from processing.core.outputs import OutputVector
3739
from processing.tools import dataobjects, vector
3840

39-
from .fieldsmapping import ParameterFieldsMapping
40-
4141

4242
class FieldsMapper(GeoAlgorithm):
4343

@@ -55,6 +55,38 @@ def defineCharacteristics(self):
5555
self.addParameter(ParameterTable(self.INPUT_LAYER,
5656
self.tr('Input layer'),
5757
False))
58+
59+
class ParameterFieldsMapping(Parameter):
60+
61+
default_metadata = {
62+
'widget_wrapper': 'processing.algs.qgis.ui.FieldsMappingPanel.FieldsMappingWidgetWrapper'
63+
}
64+
65+
def __init__(self, name='', description='', parent=None):
66+
Parameter.__init__(self, name, description)
67+
self.parent = parent
68+
self.value = []
69+
70+
def getValueAsCommandLineParameter(self):
71+
return '"' + str(self.value) + '"'
72+
73+
def setValue(self, value):
74+
if value is None:
75+
return False
76+
if isinstance(value, list):
77+
self.value = value
78+
return True
79+
if isinstance(value, str):
80+
try:
81+
self.value = eval(value)
82+
return True
83+
except Exception as e:
84+
# fix_print_with_import
85+
print(str(e)) # display error in console
86+
return False
87+
return False
88+
89+
5890
self.addParameter(ParameterFieldsMapping(self.FIELDS_MAPPING,
5991
self.tr('Fields mapping'),
6092
self.INPUT_LAYER))

‎python/plugins/processing/algs/qgis/fieldsmapping.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.