I try to develop my plugin. The problem is that when the layer is selected in upper comboBox (QgsMapsLayerComboBox), in lower two boxes (Latitude, Longitude: usual ComboBoxes) shall appear fields correspoding with selected layers.
The problem is, that when I switch the layer in upper field, I can only choose the fields which are from the other layer...
On this picture, the fields "ID", "LONGITUDE", "LATITUDE" belongs to previously selected layer "coordinates" visible on 1st photo.
Here's my code of def_run of my plugin:
def run(self):
self.dlg.layerCombo2.clear()
self.dlg.layerCombo3.clear()
layers = self.iface.legendInterface().layers()
layer_list = []
for layer in layers:
layer_list.append(layer.name())
self.dlg.layerCombo1.addItems(layer_list)
self.dlg.layerCombo1.setFilters(QgsMapLayerProxyModel.PointLayer)
def field_select():
self.dlg.layerCombo2.clear()
self.dlg.layerCombo3.clear()
selectedLayerIndex = self.dlg.layerCombo1.currentIndex()
selectedLayer = layers[selectedLayerIndex]
fields = [field.name() for field in selectedLayer.pendingFields()]
self.dlg.layerCombo2.addItems(fields)
self.dlg.layerCombo3.addItems(fields)
# This connects the function to the layer combobox when changed
self.dlg.layerCombo1.currentIndexChanged.connect(field_select)
self.dlg.show()
`