def polygonLayersToCombo(self): """Populate the combo with all polygon layers loaded in QGIS.""" myRegistry = QgsMapLayerRegistry.instance() myLayers = myRegistry.mapLayers().values() myFoundFlag = False for myLayer in myLayers: myName = myLayer.name() mySource = str(myLayer.id()) #check if layer is a vector polygon layer if isPolygonLayer(myLayer) or isPointLayer(myLayer): myFoundFlag = True addComboItemInOrder(self.cboPolygonLayers, myName, mySource) if myFoundFlag: self.cboPolygonLayers.setCurrentIndex(0)
def on_cboPolygonLayers_currentIndexChanged(self, theIndex=None): """Automatic slot executed when the layer is changed to update fields. Args: theIndex: int - passed by the signal that triggers this slot. Returns: None. Raises: no exceptions explicitly raised.""" myLayerId = self.cboPolygonLayers.itemData(theIndex, QtCore.Qt.UserRole).toString() myLayer = QgsMapLayerRegistry.instance().mapLayer(myLayerId) myFields = myLayer.dataProvider().fieldNameMap().keys() self.cboFields.clear() for myField in myFields: addComboItemInOrder(self.cboFields, myField, myField)
def on_cboPolygonLayers_currentIndexChanged(self, theIndex=None): """Automatic slot executed when the layer is changed to update fields. Args: theIndex: int - passed by the signal that triggers this slot. Returns: None. Raises: no exceptions explicitly raised.""" myLayerId = self.cboPolygonLayers.itemData( theIndex, QtCore.Qt.UserRole).toString() myLayer = QgsMapLayerRegistry.instance().mapLayer(myLayerId) myFields = myLayer.dataProvider().fieldNameMap().keys() self.cboFields.clear() for myField in myFields: addComboItemInOrder(self.cboFields, myField, myField)