示例#1
0
    def show_elderly_ratio_attribute(self):
        """Show the elderly ratio attribute in the dialog.
        """
        box = self.cboElderlyRatioAttribute
        box.blockSignals(True)
        box.clear()
        box.blockSignals(False)
        current_keyword = self.get_value_for_key(
            self.defaults['ELDERLY_RATIO_ATTR_KEY'])
        fields, attribute_position = layer_attribute_names(
            self.layer, [QtCore.QVariant.Double], current_keyword)

        box.addItem(self.global_default_string, self.global_default_data)
        box.addItem(self.do_not_use_string, self.do_not_use_data)
        for field in fields:
            box.addItem(field, field)

        if current_keyword == self.global_default_data:
            box.setCurrentIndex(0)
        elif current_keyword == self.do_not_use_data:
            box.setCurrentIndex(1)
        elif attribute_position is None:
            # current_keyword was not found in the attribute table.
            # Use default
            box.setCurrentIndex(0)
        else:
            # + 2 is because we add use defaults and don't use
            box.setCurrentIndex(attribute_position + 2)
示例#2
0
    def show_elderly_ratio_attribute(self):
        """Show the elderly ratio attribute in the dialog.
        """
        box = self.cboElderlyRatioAttribute
        box.blockSignals(True)
        box.clear()
        box.blockSignals(False)
        current_keyword = self.get_value_for_key(
            self.defaults['ELDERLY_RATIO_ATTR_KEY'])
        fields, attribute_position = layer_attribute_names(
            self.layer, [QtCore.QVariant.Double], current_keyword)

        box.addItem(self.global_default_string, self.global_default_data)
        box.addItem(self.do_not_use_string, self.do_not_use_data)
        for field in fields:
            box.addItem(field, field)

        if current_keyword == self.global_default_data:
            box.setCurrentIndex(0)
        elif current_keyword == self.do_not_use_data:
            box.setCurrentIndex(1)
        elif attribute_position is None:
            # current_keyword was not found in the attribute table.
            # Use default
            box.setCurrentIndex(0)
        else:
            # + 2 is because we add use defaults and don't use
            box.setCurrentIndex(attribute_position + 2)
示例#3
0
    def populate_cbo_aggregation_attribute(
            self, ratio_attribute_key, cbo_ratio_attribute):
        """Populate the combo box cbo_ratio_attribute for ratio_attribute_key.

        :param ratio_attribute_key: A ratio attribute key that saved in
               keywords.
        :type ratio_attribute_key: str

        :param cbo_ratio_attribute: A combo box that wants to be populated.
        :type cbo_ratio_attribute: QComboBox
        """
        cbo_ratio_attribute.clear()
        ratio_attribute = self.parent.get_existing_keyword(ratio_attribute_key)
        fields, attribute_position = layer_attribute_names(
            self.parent.layer, [QtCore.QVariant.Double], ratio_attribute)

        cbo_ratio_attribute.addItem(
            self.global_default_string, self.global_default_data)
        cbo_ratio_attribute.addItem(
            self.do_not_use_string, self.do_not_use_data)
        for field in fields:
            cbo_ratio_attribute.addItem(field, field)
        # For backward compatibility, still use Use default
        if (ratio_attribute == self.global_default_data or
                ratio_attribute == self.tr('Use default')):
            cbo_ratio_attribute.setCurrentIndex(0)
        elif ratio_attribute == self.do_not_use_data:
            cbo_ratio_attribute.setCurrentIndex(1)
        elif ratio_attribute is None or attribute_position is None:
            # current_keyword was not found in the attribute table.
            # Use default
            cbo_ratio_attribute.setCurrentIndex(0)
        else:
            # + 2 is because we add use defaults and don't use
            cbo_ratio_attribute.setCurrentIndex(attribute_position + 2)
示例#4
0
    def populate_cbo_aggregation_attribute(self, ratio_attribute_key,
                                           cbo_ratio_attribute):
        """Populate the combo box cbo_ratio_attribute for ratio_attribute_key.

        :param ratio_attribute_key: A ratio attribute key that saved in
               keywords.
        :type ratio_attribute_key: str

        :param cbo_ratio_attribute: A combo box that wants to be populated.
        :type cbo_ratio_attribute: QComboBox
        """
        cbo_ratio_attribute.clear()
        ratio_attribute = self.parent.get_existing_keyword(ratio_attribute_key)
        fields, attribute_position = layer_attribute_names(
            self.parent.layer, [QtCore.QVariant.Double], ratio_attribute)

        cbo_ratio_attribute.addItem(self.global_default_string,
                                    self.global_default_data)
        cbo_ratio_attribute.addItem(self.do_not_use_string,
                                    self.do_not_use_data)
        for field in fields:
            cbo_ratio_attribute.addItem(field, field)
        # For backward compatibility, still use Use default
        if (ratio_attribute == self.global_default_data
                or ratio_attribute == self.tr('Use default')):
            cbo_ratio_attribute.setCurrentIndex(0)
        elif ratio_attribute == self.do_not_use_data:
            cbo_ratio_attribute.setCurrentIndex(1)
        elif ratio_attribute is None or attribute_position is None:
            # current_keyword was not found in the attribute table.
            # Use default
            cbo_ratio_attribute.setCurrentIndex(0)
        else:
            # + 2 is because we add use defaults and don't use
            cbo_ratio_attribute.setCurrentIndex(attribute_position + 2)
示例#5
0
    def test_get_layer_attribute_names(self):
        """Test we can get the correct attributes back"""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))

        # with good attribute name
        attributes, position = layer_attribute_names(
            layer,
            [QVariant.Int, QVariant.String],
            'TEST_STR')
        expected_attributes = ['KAB_NAME', 'TEST_STR', 'TEST_INT']
        expected_position = 1
        message = 'expected_attributes, got %s, expected %s' % (
            attributes, expected_attributes)
        self.assertEqual(attributes, expected_attributes, message)
        message = 'expected_position, got %s, expected %s' % (
            position, expected_position)
        self.assertEqual(position, expected_position, message)

        # with non existing attribute name
        attributes, position = layer_attribute_names(
            layer,
            [QVariant.Int, QVariant.String],
            'MISSING_ATTR')
        expected_attributes = ['KAB_NAME', 'TEST_STR', 'TEST_INT']
        expected_position = None
        message = 'expected_attributes, got %s, expected %s' % (
            attributes, expected_attributes)
        self.assertEqual(attributes, expected_attributes, message)
        message = 'expected_position, got %s, expected %s' % (
            position, expected_position)
        self.assertEqual(position, expected_position, message)

        # with raster layer
        layer = clone_raster_layer(
            name='padang_tsunami_mw8',
            extension='.tif',
            include_keywords=True,
            source_directory=test_data_path('hazard')
        )
        attributes, position = layer_attribute_names(layer, [], '')
        message = 'Should return None, None for raster layer, got %s, %s' % (
            attributes, position)
        assert (attributes is None and position is None), message
示例#6
0
文件: test_gis.py 项目: vck/inasafe
    def test_get_layer_attribute_names(self):
        """Test we can get the correct attributes back"""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))

        # with good attribute name
        attributes, position = layer_attribute_names(
            layer,
            [QVariant.Int, QVariant.String],
            'TEST_STR')
        expected_attributes = ['KAB_NAME', 'TEST_STR', 'TEST_INT']
        expected_position = 1
        message = 'expected_attributes, got %s, expected %s' % (
            attributes, expected_attributes)
        self.assertEqual(attributes, expected_attributes, message)
        message = 'expected_position, got %s, expected %s' % (
            position, expected_position)
        self.assertEqual(position, expected_position, message)

        # with non existing attribute name
        attributes, position = layer_attribute_names(
            layer,
            [QVariant.Int, QVariant.String],
            'MISSING_ATTR')
        expected_attributes = ['KAB_NAME', 'TEST_STR', 'TEST_INT']
        expected_position = None
        message = 'expected_attributes, got %s, expected %s' % (
            attributes, expected_attributes)
        self.assertEqual(attributes, expected_attributes, message)
        message = 'expected_position, got %s, expected %s' % (
            position, expected_position)
        self.assertEqual(position, expected_position, message)

        # with raster layer
        layer = clone_raster_layer(
            name='padang_tsunami_mw8',
            extension='.tif',
            include_keywords=True,
            source_directory=test_data_path('hazard')
        )
        attributes, position = layer_attribute_names(layer, [], '')
        message = 'Should return None, None for raster layer, got %s, %s' % (
            attributes, position)
        assert (attributes is None and position is None), message
示例#7
0
 def show_aggregation_attribute(self):
     """Hide or show the aggregation attribute in the keyword editor dialog.
     """
     box = self.cboAggregationAttribute
     box.blockSignals(True)
     box.clear()
     box.blockSignals(False)
     current_keyword = self.get_value_for_key(
         self.defaults['AGGR_ATTR_KEY'])
     fields, attribute_position = layer_attribute_names(
         self.layer, [QtCore.QVariant.Int, QtCore.QVariant.String],
         current_keyword)
     box.addItems(fields)
     if attribute_position is None:
         box.setCurrentIndex(0)
     else:
         box.setCurrentIndex(attribute_position)
示例#8
0
 def show_aggregation_attribute(self):
     """Hide or show the aggregation attribute in the keyword editor dialog.
     """
     box = self.cboAggregationAttribute
     box.blockSignals(True)
     box.clear()
     box.blockSignals(False)
     current_keyword = self.get_value_for_key(
         self.defaults['AGGR_ATTR_KEY'])
     fields, attribute_position = layer_attribute_names(
         self.layer,
         [QtCore.QVariant.Int, QtCore.QVariant.String],
         current_keyword)
     box.addItems(fields)
     if attribute_position is None:
         box.setCurrentIndex(0)
     else:
         box.setCurrentIndex(attribute_position)