Skip to content
Permalink
Browse files
Use QgsMapLayerComboBox in processing field calculator
  • Loading branch information
nyalldawson committed Apr 5, 2017
1 parent c2c9335 commit ee29fa66f9682bbe6d24c04b322e686f472e9824
Showing with 14 additions and 14 deletions.
  1. +7 −1 python/plugins/processing/algs/qgis/ui/DlgFieldsCalculator.ui
  2. +7 −13 python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py
@@ -148,7 +148,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbInputLayer">
<widget class="QgsMapLayerComboBox" name="cmbInputLayer">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -224,6 +224,12 @@
<header>qgis.gui</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsMapLayerComboBox</class>
<extends>QComboBox</extends>
<header>qgis.gui</header>
<container>0</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mOutputFieldNameLineEdit</tabstop>
@@ -37,7 +37,7 @@
QgsProcessingFeedback,
QgsSettings,
QgsProcessingUtils,
QgsProject)
QgsMapLayerProxyModel)
from qgis.gui import QgsEncodingFileDialog

from processing.core.ProcessingConfig import ProcessingConfig
@@ -77,7 +77,8 @@ def __init__(self, alg):
self.alg = alg
self.layer = None

self.cmbInputLayer.currentIndexChanged.connect(self.updateLayer)
self.cmbInputLayer.setFilters(QgsMapLayerProxyModel.VectorLayer)
self.cmbInputLayer.layerChanged.connect(self.updateLayer)
self.btnBrowse.clicked.connect(self.selectFile)
self.mNewFieldGroupBox.toggled.connect(self.toggleExistingGroup)
self.mUpdateExistingGroupBox.toggled.connect(self.toggleNewGroup)
@@ -101,17 +102,10 @@ def manageGui(self):
for t in self.alg.type_names:
self.mOutputFieldTypeComboBox.addItem(t)
self.mOutputFieldTypeComboBox.blockSignals(False)

self.cmbInputLayer.blockSignals(True)
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
for layer in layers:
self.cmbInputLayer.addItem(layer.name())
self.cmbInputLayer.blockSignals(False)

self.builder.loadRecent('fieldcalc')

self.initContext()
self.updateLayer()
self.updateLayer(self.cmbInputLayer.currentLayer())

def initContext(self):
exp_context = self.builder.expressionContext()
@@ -120,8 +114,8 @@ def initContext(self):
exp_context.setHighlightedVariables(["row_number"])
self.builder.setExpressionContext(exp_context)

def updateLayer(self):
self.layer = dataobjects.getObject(self.cmbInputLayer.currentText())
def updateLayer(self, layer):
self.layer = layer
self.builder.setLayer(self.layer)
self.builder.loadFieldNames()
self.populateFields()
@@ -202,7 +196,7 @@ def setParamValues(self):
else:
fieldName = self.mOutputFieldNameLineEdit.text()

layer = dataobjects.getObjectFromName(self.cmbInputLayer.currentText())
layer = self.cmbInputLayer.currentLayer()

self.alg.setParameterValue('INPUT_LAYER', layer)
self.alg.setParameterValue('FIELD_NAME', fieldName)

0 comments on commit ee29fa6

Please sign in to comment.