def on_cboPolygonLayers_currentIndexChanged(self, theIndex=None): """Automatic slot executed when the layer is changed to update fields. :param theIndex: Passed by the signal that triggers this slot. :type theIndex: int """ layer_id = self.cboPolygonLayers.itemData(theIndex, QtCore.Qt.UserRole) # noinspection PyArgumentList layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) fields = layer.dataProvider().fieldNameMap().keys() self.cboFields.clear() for field in fields: add_ordered_combo_item(self.cboFields, field, field)
def on_cboPolygonLayers_currentIndexChanged(self, theIndex=None): """Automatic slot executed when the layer is changed to update fields. :param theIndex: Passed by the signal that triggers this slot. :type theIndex: int """ layer_id = self.cboPolygonLayers.itemData( theIndex, QtCore.Qt.UserRole) # noinspection PyArgumentList layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) fields = layer.dataProvider().fieldNameMap().keys() self.cboFields.clear() for field in fields: add_ordered_combo_item(self.cboFields, field, field)
def polygon_layers_to_combo(self): """Populate the combo with all polygon layers loaded in QGIS.""" # noinspection PyArgumentList registry = QgsMapLayerRegistry.instance() layers = registry.mapLayers().values() found_flag = False for layer in layers: name = layer.name() source = str(layer.id()) # check if layer is a vector polygon layer if is_polygon_layer(layer) or is_point_layer(layer): found_flag = True add_ordered_combo_item(self.cboPolygonLayers, name, source) if found_flag: self.cboPolygonLayers.setCurrentIndex(0)
def polygon_layers_to_combo(self): """Populate the combo with all polygon layers loaded in QGIS.""" # noinspection PyArgumentList 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 is_polygon_layer(myLayer) or is_point_layer(myLayer): myFoundFlag = True add_ordered_combo_item(self.cboPolygonLayers, myName, mySource) if myFoundFlag: self.cboPolygonLayers.setCurrentIndex(0)
def polygon_layers_to_combo(self): """Populate the combo with all polygon layers loaded in QGIS.""" # noinspection PyArgumentList 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 is_polygon_layer(myLayer) or is_point_layer(myLayer): myFoundFlag = True add_ordered_combo_item(self.cboPolygonLayers, myName, mySource) if myFoundFlag: self.cboPolygonLayers.setCurrentIndex(0)
def get_project_layers(self): """Get impact layers and aggregation layer currently loaded in QGIS.""" #noinspection PyArgumentList registry = QgsMapLayerRegistry.instance() # MapLayers returns a QMap<QString id, QgsMapLayer layer> layers = registry.mapLayers().values() if len(layers) == 0: return # Clear the combo box first self.first_layer.clear() self.second_layer.clear() self.aggregation_layer.clear() for layer in layers: try: self.keyword_io.read_keywords(layer, 'impact_summary') except (NoKeywordsFoundError, KeywordNotFoundError): # Check if it has aggregation keyword try: self.keyword_io.read_keywords( layer, 'aggregation attribute') except (NoKeywordsFoundError, KeywordNotFoundError): # Skip if there are no keywords at all continue add_ordered_combo_item( self.aggregation_layer, layer.name(), layer) continue except (UnsupportedProviderError, InvalidParameterError): # UnsupportedProviderError: # Encounter unsupported provider layer, e.g Open Layer # InvalidParameterError: # Encounter invalid layer source, # see https://github.com/AIFDR/inasafe/issues/754 continue add_ordered_combo_item(self.first_layer, layer.name(), layer) add_ordered_combo_item(self.second_layer, layer.name(), layer) # Add Entire Area Option to Aggregated Layer: self.aggregation_layer.insertItem( 0, self.tr('Entire Area'), None ) self.aggregation_layer.setCurrentIndex(0)
def get_project_layers(self): """Get impact layers and aggregation layer currently loaded in QGIS.""" # noinspection PyArgumentList registry = QgsMapLayerRegistry.instance() # MapLayers returns a QMap<QString id, QgsMapLayer layer> layers = registry.mapLayers().values() if len(layers) == 0: return # Clear the combo box first self.first_layer.clear() self.second_layer.clear() self.aggregation_layer.clear() for layer in layers: try: self.keyword_io.read_keywords(layer, 'impact_summary') except (NoKeywordsFoundError, KeywordNotFoundError): # Check if it has aggregation keyword try: self.keyword_io.read_keywords(layer, 'aggregation attribute') except (NoKeywordsFoundError, KeywordNotFoundError): # Skip if there are no keywords at all continue add_ordered_combo_item(self.aggregation_layer, layer.name(), layer) continue except (UnsupportedProviderError, InvalidParameterError): # UnsupportedProviderError: # Encounter unsupported provider layer, e.g Open Layer # InvalidParameterError: # Encounter invalid layer source, # see https://github.com/AIFDR/inasafe/issues/754 continue add_ordered_combo_item(self.first_layer, layer.name(), layer) add_ordered_combo_item(self.second_layer, layer.name(), layer) # Add Entire Area Option to Aggregated Layer: self.aggregation_layer.insertItem(0, self.tr('Entire Area'), None) self.aggregation_layer.setCurrentIndex(0)