Navigation Menu

Skip to content

Commit

Permalink
Use QgsMapLayerComboBox in processing field calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 5, 2017
1 parent c2c9335 commit ee29fa6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
20 changes: 7 additions & 13 deletions python/plugins/processing/algs/qgis/ui/FieldsCalculatorDialog.py
Expand Up @@ -37,7 +37,7 @@
QgsProcessingFeedback,
QgsSettings,
QgsProcessingUtils,
QgsProject)
QgsMapLayerProxyModel)
from qgis.gui import QgsEncodingFileDialog

from processing.core.ProcessingConfig import ProcessingConfig
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee29fa6

Please sign in to comment.