def __init__(self, parent=None, iface=None, setting=None):
        """Constructor."""
        QDialog.__init__(self, parent)
        self.setupUi(self)

        self.setWindowTitle(self.tr('InaSAFE Field Mapping Tool'))
        icon = resources_path('img', 'icons', 'show-mapping-tool.svg')
        self.setWindowIcon(QIcon(icon))
        self.parent = parent
        self.iface = iface
        if setting is None:
            setting = QSettings()
        self.setting = setting

        self.keyword_io = KeywordIO()

        self.layer = None
        self.metadata = {}

        self.layer_input_layout = QHBoxLayout()
        self.layer_label = QLabel(tr('Layer'))
        self.layer_combo_box = QgsMapLayerComboBox()
        # Filter only for Polygon and Point
        self.layer_combo_box.setFilters(
            QgsMapLayerProxyModel.PolygonLayer
            | QgsMapLayerProxyModel.PointLayer)
        # Filter out a layer that don't have layer groups
        excepted_layers = []
        for i in range(self.layer_combo_box.count()):
            layer = self.layer_combo_box.layer(i)
            try:
                keywords = self.keyword_io.read_keywords(layer)
            except (KeywordNotFoundError, NoKeywordsFoundError):
                excepted_layers.append(layer)
                continue
            layer_purpose = keywords.get('layer_purpose')
            if not layer_purpose:
                excepted_layers.append(layer)
                continue
            if layer_purpose == layer_purpose_exposure['key']:
                layer_subcategory = keywords.get('exposure')
            elif layer_purpose == layer_purpose_hazard['key']:
                layer_subcategory = keywords.get('hazard')
            else:
                layer_subcategory = None

            field_groups = get_field_groups(layer_purpose, layer_subcategory)
            if len(field_groups) == 0:
                excepted_layers.append(layer)
                continue
        self.layer_combo_box.setExceptedLayerList(excepted_layers)

        # Select the active layer.
        if self.iface.activeLayer():
            found = self.layer_combo_box.findText(
                self.iface.activeLayer().name())
            if found > -1:
                self.layer_combo_box.setLayer(self.iface.activeLayer())

        self.field_mapping_widget = None
        self.main_stacked_widget.setCurrentIndex(1)

        # Input
        self.layer_input_layout.addWidget(self.layer_label)
        self.layer_input_layout.addWidget(self.layer_combo_box)

        self.header_label = QLabel()
        self.header_label.setWordWrap(True)
        self.main_layout.addWidget(self.header_label)
        self.main_layout.addLayout(self.layer_input_layout)

        # Signal
        self.layer_combo_box.layerChanged.connect(self.set_layer)

        if self.layer_combo_box.currentLayer():
            self.set_layer(self.layer_combo_box.currentLayer())

        # Set up things for context help
        self.help_button = self.button_box.button(QDialogButtonBox.Help)
        # Allow toggling the help button
        self.help_button.setCheckable(True)
        self.help_button.toggled.connect(self.help_toggled)

        # Set up things for ok button
        self.ok_button = self.button_box.button(QDialogButtonBox.Ok)
        self.ok_button.clicked.connect(self.accept)

        # Set up things for cancel button
        self.cancel_button = self.button_box.button(QDialogButtonBox.Cancel)
        self.cancel_button.clicked.connect(self.reject)
def __init__ ( self , parent = None , iface = None , setting = None ) : QDialog . __init__ ( self , parent ) self . setupUi ( self ) self . setWindowTitle ( self . tr ( 'InaSAFE Field Mapping Tool' ) ) icon = resources_path ( 'img' , 'icons' , 'show-mapping-tool.svg' ) self . setWindowIcon ( QIcon ( icon ) ) self . parent = parent self . iface = iface if setting is None : setting = QSettings ( ) self . setting = setting self . keyword_io = KeywordIO ( ) self . layer = None self . metadata = { } self . layer_input_layout = QHBoxLayout ( ) self . layer_label = QLabel ( tr ( 'Layer' ) ) self . layer_combo_box = QgsMapLayerComboBox ( ) self . layer_combo_box . setFilters ( QgsMapLayerProxyModel . PolygonLayer | QgsMapLayerProxyModel . PointLayer ) excepted_layers = [ ] for i in range ( self . layer_combo_box . count ( ) ) : layer = self . layer_combo_box . layer ( i ) try : keywords = self . keyword_io . read_keywords ( layer ) except ( KeywordNotFoundError , NoKeywordsFoundError ) : excepted_layers . append ( layer ) continue layer_purpose = keywords . get ( 'layer_purpose' ) if not layer_purpose : excepted_layers . append ( layer ) continue if layer_purpose == layer_purpose_exposure [ 'key' ] : layer_subcategory = keywords . get ( 'exposure' ) elif layer_purpose == layer_purpose_hazard [ 'key' ] : layer_subcategory = keywords . get ( 'hazard' ) else : layer_subcategory = None field_groups = get_field_groups ( layer_purpose , layer_subcategory ) if len ( field_groups ) == 0 : excepted_layers . append ( layer ) continue self . layer_combo_box . setExceptedLayerList ( excepted_layers ) if self . iface . activeLayer ( ) : found = self . layer_combo_box . findText ( self . iface . activeLayer ( ) . name ( ) ) if found > - 1 : self . layer_combo_box . setLayer ( self . iface . activeLayer ( ) ) self . field_mapping_widget = None self . main_stacked_widget . setCurrentIndex ( 1 ) self . layer_input_layout . addWidget ( self . layer_label ) self . layer_input_layout . addWidget ( self . layer_combo_box ) self . header_label = QLabel ( ) self . header_label . setWordWrap ( True ) self . main_layout . addWidget ( self . header_label ) self . main_layout . addLayout ( self . layer_input_layout ) self . layer_combo_box . layerChanged . connect ( self . set_layer ) if self . layer_combo_box . currentLayer ( ) : self . set_layer ( self . layer_combo_box . currentLayer ( ) ) self . help_button = self . button_box . button ( QDialogButtonBox . Help ) self . help_button . setCheckable ( True ) self . help_button . toggled . connect ( self . help_toggled ) self . ok_button = self . button_box . button ( QDialogButtonBox . Ok ) self . ok_button . clicked . connect ( self . accept ) self . cancel_button = self . button_box . button ( QDialogButtonBox . Cancel ) self . cancel_button . clicked . connect ( self . reject )
Constructor.