Skip to content
Permalink
Browse files

Create FieldMappingWrapper

  • Loading branch information
arnaud-morvan authored and volaya committed Oct 5, 2016
1 parent affc8f7 commit a38c13d523c8aa7fc70fb0970a73af18fe8fa216
@@ -37,8 +37,6 @@
from processing.tools import dataobjects, vector

from .fieldsmapping import ParameterFieldsMapping
from .ui.FieldsMapperDialogs import (FieldsMapperParametersDialog,
FieldsMapperModelerParametersDialog)


class FieldsMapper(GeoAlgorithm):
@@ -151,9 +149,3 @@ def processAlgorithm(self, progress):
raise GeoAlgorithmExecutionException(
self.tr('An error occurred while evaluating the calculation'
' string:\n') + error)

def getCustomParametersDialog(self):
return FieldsMapperParametersDialog(self)

def getCustomModelerParametersDialog(self, modelAlg, algName=None):
return FieldsMapperModelerParametersDialog(self, modelAlg, algName)
@@ -33,6 +33,10 @@

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

This file was deleted.

@@ -31,13 +31,14 @@
from collections import OrderedDict

from qgis.PyQt import uic
from qgis.PyQt.QtGui import QBrush, QIcon
from qgis.PyQt.QtGui import QBrush, QIcon, QSpacerItem
from qgis.PyQt.QtWidgets import QComboBox, QHeaderView, QLineEdit, QMessageBox, QSpinBox, QStyledItemDelegate
from qgis.PyQt.QtCore import QItemSelectionModel, QAbstractTableModel, QModelIndex, QVariant, Qt, pyqtSlot

from qgis.core import QgsExpression, QgsExpressionContextUtils, QgsApplication
from qgis.core import QgsExpression, QgsExpressionContextUtils, QgsApplication, QgsFeature
from qgis.gui import QgsFieldExpressionWidget

from processing.gui.wrappers import WidgetWrapper, DIALOG_STANDARD, DIALOG_MODELER
from processing.tools import dataobjects

pluginPath = os.path.dirname(__file__)
@@ -93,7 +94,7 @@ def testExpression(self, row):
if self._layer is None:
return
context = QgsExpressionContextUtils.createFeatureBasedContext(QgsFeature(), self._layer.fields())
for feature in dp.getFeatures():
for feature in self._layer.getFeatures():
context.setFeature(feature)
expression.evaluate(context)
if expression.hasEvalError():
@@ -473,3 +474,35 @@ def on_loadLayerFieldsButton_clicked(self, checked=False):
if layer is None:
return
self.model.loadLayerFields(layer)


class FieldsMappingWidgetWrapper(WidgetWrapper):

def createWidget(self):
return FieldsMappingPanel()

def postInitialize(self, wrappers):
for wrapper in wrappers:
if wrapper.param.name == self.param.parent:
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
break
layers = dataobjects.getTables()
if len(layers) > 0:
# as first item in combobox is already selected
self.widget.setLayer(layers[0])

# remove exiting spacers to get FieldsMappingPanel fully expanded
if self.dialogType in (DIALOG_STANDARD, DIALOG_MODELER):
layout = self.widget.parent().layout()
spacer = layout.itemAt(layout.count() - 1)
if isinstance(spacer, QSpacerItem):
layout.removeItem(spacer)

def parentLayerChanged(self):
self.widget.setLayer(self.sender().value())

def setValue(self, value):
self.widget.setValue(value)

def value(self):
return self.widget.value()

0 comments on commit a38c13d

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