mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] move custom parameter definition inside corresponding
algorithm
This commit is contained in:
parent
fc18fd98cc
commit
f70a3b9e1d
@ -16,6 +16,7 @@
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
|
||||
@ -33,11 +34,10 @@ from qgis.utils import iface
|
||||
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):
|
||||
|
||||
@ -55,6 +55,38 @@ class FieldsMapper(GeoAlgorithm):
|
||||
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))
|
||||
|
@ -1,62 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
FieldsMapper.py
|
||||
---------------------
|
||||
Date : October 2014
|
||||
Copyright : (C) 2014 by Arnaud Morvan
|
||||
Email : arnaud dot morvan at camptocamp dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from builtins import str
|
||||
|
||||
__author__ = 'Arnaud Morvan'
|
||||
__date__ = 'October 2014'
|
||||
__copyright__ = '(C) 2014, Arnaud Morvan'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
|
||||
from processing.core.parameters import Parameter
|
||||
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user