def showFemaleRatioAttribute(self, theFlag): theBox = self.cboFemaleRatioAttribute theBox.blockSignals(True) theBox.clear() theBox.blockSignals(False) if theFlag: currentKeyword = self.getValueForKey( self.defaults['FEM_RATIO_ATTR_KEY']) fields, attributePosition = getLayerAttributeNames(self.layer, [QtCore.QVariant.Double], currentKeyword) fields.insert(0, self.tr('Use default')) fields.insert(1, self.tr('Don\'t use')) theBox.addItems(fields) if currentKeyword == self.tr('Use default'): theBox.setCurrentIndex(0) elif currentKeyword == self.tr('Don\'t use'): theBox.setCurrentIndex(1) elif attributePosition is None: # currentKeyword was not found in the attribute table. # Use default theBox.setCurrentIndex(0) else: # + 2 is because we add use defaults and don't use theBox.setCurrentIndex(attributePosition + 2) theBox.setVisible(theFlag) self.lblFemaleRatioAttribute.setVisible(theFlag)
def showFemaleRatioAttribute(self, theFlag): theBox = self.cboFemaleRatioAttribute theBox.blockSignals(True) theBox.clear() theBox.blockSignals(False) if theFlag: currentKeyword = self.getValueForKey( self.defaults['FEM_RATIO_ATTR_KEY']) fields, attributePosition = getLayerAttributeNames(self.layer, [QtCore.QVariant.Double], currentKeyword) fields.insert(0, self.tr('Use default')) fields.insert(1, self.tr('Don\'t use')) theBox.addItems(fields) if currentKeyword == self.tr('Use default'): theBox.setCurrentIndex(0) elif currentKeyword == self.tr('Don\'t use'): theBox.setCurrentIndex(1) elif attributePosition is None: # currentKeyword was not found in the attribute table. # Use default theBox.setCurrentIndex(0) else: # + 2 is because we add use defaults and don't use theBox.setCurrentIndex(attributePosition + 2) theBox.setVisible(theFlag) self.lblFemaleRatioAttribute.setVisible(theFlag)
def test_getLayerAttributeNames(self): """Test we can get the correct attributes back""" myLayer = makePolygonLayer() #with good attribute name myAttrs, myPos = getLayerAttributeNames(myLayer, [ QVariant.Int, QVariant.String], 'TEST_STRIN') myExpectedAttrs = ['KAB_NAME', 'TEST_INT', 'TEST_STRIN'] myExpectedPos = 2 myMessage = 'myExpectedAttrs, got %s, expected %s' % ( myAttrs, myExpectedAttrs) assert (myAttrs == myExpectedAttrs), myMessage myMessage = 'myExpectedPos, got %s, expected %s' % ( myPos, myExpectedPos) assert (myPos == myExpectedPos), myMessage #with inexistent attribute name myAttrs, myPos = getLayerAttributeNames( myLayer, [QVariant.Int, QVariant.String], 'MISSING_ATTR') myExpectedAttrs = ['KAB_NAME', 'TEST_INT', 'TEST_STRIN'] myExpectedPos = None myMessage = 'myExpectedAttrs, got %s, expected %s' % ( myAttrs, myExpectedAttrs) assert (myAttrs == myExpectedAttrs), myMessage myMessage = 'myExpectedPos, got %s, expected %s' % ( myPos, myExpectedPos) assert (myPos == myExpectedPos), myMessage #with raster layer myLayer = makePadangLayer() myAttrs, myPos = getLayerAttributeNames(myLayer, [], '') myMessage = 'Should return None, None for raster layer, got %s, %s' % ( myAttrs, myPos) assert (myAttrs is None and myPos is None), myMessage
def test_getLayerAttributeNames(self): """Test we can get the correct attributes back""" myLayer = makePolygonLayer() #with good attribute name myAttrs, myPos = getLayerAttributeNames(myLayer, [ QVariant.Int, QVariant.String], 'TEST_STRIN') myExpectedAttrs = ['KAB_NAME', 'TEST_INT', 'TEST_STRIN'] myExpectedPos = 2 myMessage = 'myExpectedAttrs, got %s, expected %s' % ( myAttrs, myExpectedAttrs) assert (myAttrs == myExpectedAttrs), myMessage myMessage = 'myExpectedPos, got %s, expected %s' % ( myPos, myExpectedPos) assert (myPos == myExpectedPos), myMessage #with inexistent attribute name myAttrs, myPos = getLayerAttributeNames( myLayer, [QVariant.Int, QVariant.String], 'MISSING_ATTR') myExpectedAttrs = ['KAB_NAME', 'TEST_INT', 'TEST_STRIN'] myExpectedPos = None myMessage = 'myExpectedAttrs, got %s, expected %s' % ( myAttrs, myExpectedAttrs) assert (myAttrs == myExpectedAttrs), myMessage myMessage = 'myExpectedPos, got %s, expected %s' % ( myPos, myExpectedPos) assert (myPos == myExpectedPos), myMessage #with raster layer myLayer = makePadangLayer() myAttrs, myPos = getLayerAttributeNames(myLayer, [], '') myMessage = 'Should return None, None for raster layer, got %s, %s' % ( myAttrs, myPos) assert (myAttrs is None and myPos is None), myMessage
def showAggregationAttribute(self, theFlag): theBox = self.cboAggregationAttribute theBox.blockSignals(True) theBox.clear() theBox.blockSignals(False) if theFlag: currentKeyword = self.getValueForKey( self.defaults['AGGR_ATTR_KEY']) fields, attributePosition = getLayerAttributeNames(self.layer, [QtCore.QVariant.Int, QtCore.QVariant.String], currentKeyword) theBox.addItems(fields) if attributePosition is None: theBox.setCurrentIndex(0) else: theBox.setCurrentIndex(attributePosition) theBox.setVisible(theFlag) self.lblAggregationAttribute.setVisible(theFlag)
def showAggregationAttribute(self, theFlag): theBox = self.cboAggregationAttribute theBox.blockSignals(True) theBox.clear() theBox.blockSignals(False) if theFlag: currentKeyword = self.getValueForKey( self.defaults['AGGR_ATTR_KEY']) fields, attributePosition = getLayerAttributeNames(self.layer, [QtCore.QVariant.Int, QtCore.QVariant.String], currentKeyword) theBox.addItems(fields) if attributePosition is None: theBox.setCurrentIndex(0) else: theBox.setCurrentIndex(attributePosition) theBox.setVisible(theFlag) self.lblAggregationAttribute.setVisible(theFlag)