Skip to content

Commit

Permalink
Create FieldMappingWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan authored and volaya committed Oct 5, 2016
1 parent affc8f7 commit a38c13d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 154 deletions.
8 changes: 0 additions & 8 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
from processing.tools import dataobjects, vector

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


class FieldsMapper(GeoAlgorithm):
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions python/plugins/processing/algs/qgis/fieldsmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
143 changes: 0 additions & 143 deletions python/plugins/processing/algs/qgis/ui/FieldsMapperDialogs.py

This file was deleted.

39 changes: 36 additions & 3 deletions python/plugins/processing/algs/qgis/ui/FieldsMappingPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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.