def on_cboPolygonLayers_currentIndexChanged(self, index): """Automatic slot executed when the layer is changed to update fields. :param index: Passed by the signal that triggers this slot. :type index: int """ layer_id = self.cboPolygonLayers.itemData( index, QtCore.Qt.UserRole) # noinspection PyArgumentList layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) fields = layer.pendingFields() self.cboFields.clear() has_fields = False for field in fields: LOGGER.info(field.typeName()) # TODO exclude dates too? TS if field.typeName() != 'String': has_fields = True add_ordered_combo_item( self.cboFields, field.name(), field.name()) # Now disable the run button if no suitable fields were found # see #2206 ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok) if not has_fields: ok_button.setEnabled(False) else: ok_button.setEnabled(True)
def on_cboPolygonLayers_currentIndexChanged(self, index): """Automatic slot executed when the layer is changed to update fields. :param index: Passed by the signal that triggers this slot. :type index: int """ layer_id = self.cboPolygonLayers.itemData(index, QtCore.Qt.UserRole) # noinspection PyArgumentList layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) fields = layer.pendingFields() self.cboFields.clear() has_fields = False for field in fields: LOGGER.info(field.typeName()) # TODO exclude dates too? TS if field.typeName() != 'String': has_fields = True add_ordered_combo_item(self.cboFields, field.name(), field.name()) # Now disable the run button if no suitable fields were found # see #2206 ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok) if not has_fields: ok_button.setEnabled(False) else: ok_button.setEnabled(True)
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 = 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 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 registry = QgsMapLayerRegistry.instance() layers = registry.mapLayers().values() found_flag = False for layer in layers: name = layer.name() source = 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) # Now disable the run button if no suitable layers were found # see #2206 ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok) if found_flag: self.cboPolygonLayers.setCurrentIndex(0) ok_button.setEnabled(True) else: ok_button.setEnabled(False)
def get_project_layers(self): """Get impact layers and aggregation layer currently loaded in QGIS.""" # noinspection PyArgumentList,PyUnresolvedReferences 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() # empty list self.available_aggregation[:] = [] 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 self.available_aggregation.append(layer) 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,PyUnresolvedReferences 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() # empty list self.available_aggregation[:] = [] 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 self.available_aggregation.append(layer) 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 __init__(self, parent=None, iface=None): """Constructor for Raster Reclassification to Vector Polygon. .. versionadded: 3.4 :param parent: Optional widget to use as parent :type parent: QWidget :param iface: An instance of QGisInterface :type iface: QGisInterface """ QDialog.__init__(self, parent) self.parent = parent self.setupUi(self) self.setWindowTitle(self.tr('Raster Reclassification')) self.iface = iface self.if_registry = Registry() self.keyword_io = KeywordIO() # populate raster input self.cbo_raster_input.clear() registry = QgsMapLayerRegistry.instance() # MapLayers returns a QMap<QString id, QgsMapLayer layer> layers = registry.mapLayers().values() for layer in layers: try: name = layer.name() source = layer.id() layer_purpose = self.keyword_io.read_keywords( layer, 'layer_purpose') if (isinstance(layer, QgsRasterLayer) and layer_purpose == 'hazard'): add_ordered_combo_item( self.cbo_raster_input, self.tr(name), source) except Exception as e: raise e # self.input_list_parameter = InputListParameter() # self.input_list_parameter.name = 'Thresholds' # self.input_list_parameter.description = ( # 'List of thresholds of values used in reclassification.') # self.input_list_parameter.help_text = 'list of thresholds used' # self.input_list_parameter.maximum_item_count = 100 # self.input_list_parameter.minimum_item_count = 1 # self.input_list_parameter.element_type = float # self.input_list_parameter.value = [0.0, 1.0] # self.input_list_parameter.ordering = \ # InputListParameter.AscendingOrder # self.thresholds_widget = InputListParameterWidget( # self.input_list_parameter) # self.threshold_editor.layout().addWidget(self.thresholds_widget) # Set up context help self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help) self.ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok) # self.cancel_button = self.button_box.button( # QtGui.QDialogButtonBox.Cancel) self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject) # Allow toggling the help button self.help_button.setCheckable(True) self.help_button.toggled.connect(self.help_toggled) self.main_stacked_widget.setCurrentIndex(1) # adapt layer changed self.cbo_raster_input.currentIndexChanged.connect(self.raster_changed) self.raster_changed(self.cbo_raster_input.currentIndex())