def layerOrFieldCombosChanged( self, callerRow=None, idx=None ):
""" SLOT. Handles both layer or field selection changed SIGNALS updating
all rows in the table. Namely, this function:
+ updates assignation arrows,
+ enables/disables OK button accordingly, and
+ updates field comboBox if layer was changed.
"""
assigned = []
bEnableOkButton = True
for row in range(self.tblAutoFields.rowCount()):
indexLayerCombo = self.tblAutoFields.cellWidget( row, 4 ).currentIndex()
indexFieldCombo = self.tblAutoFields.cellWidget( row, 5 ).currentIndex()
layerId = self.tblAutoFields.cellWidget( row, 4 ).itemData( indexLayerCombo )
fieldName = self.tblAutoFields.cellWidget( row, 5 ).itemText( indexFieldCombo )
layer = QgsMapLayerRegistry.instance().mapLayer( layerId )
# Update fieldCombo if necessary
if callerRow is not None and row == callerRow:
fieldCombo = self.tblAutoFields.cellWidget( row, 5 )
fieldCombo.blockSignals(True)
fieldCombo.clear()
fieldCombo.addItem( '[Select a field]', None )
if indexLayerCombo != 0:
autoFieldFieldName = self.tblAutoFields.item( row, 1 ).text()
for field in layer.fields():
fieldCombo.addItem( field.name() )
fieldIndex = fieldCombo.findText( autoFieldFieldName )
fieldCombo.setCurrentIndex( fieldIndex if fieldIndex != -1 else 0 )
fieldCombo.blockSignals(False)
# Update fieldCombo status info
indexFieldCombo = self.tblAutoFields.cellWidget( row, 5 ).currentIndex()
fieldName = self.tblAutoFields.cellWidget( row, 5 ).itemText( indexFieldCombo )
# Arrows
label = QLabel()
if indexLayerCombo != 0 and indexFieldCombo != 0 and layerId + "_" + fieldName in assigned:
label.setPixmap( QPixmap( ":/plugins/AutoFields/icons/red_arrow.png" ) )
label.setToolTip( 'Target layer/field pair already selected. You cannot assign two AutoFields to the same layer/field pair.' )
label.setAlignment( Qt.AlignCenter )
bEnableOkButton = False
else:
if indexLayerCombo != 0 and indexFieldCombo != 0:
assigned.append( layerId + "_" + fieldName )
label = self.getLabelWithArrow( indexLayerCombo, indexFieldCombo, layer, fieldName )
self.tblAutoFields.setCellWidget( row, 3, label )
self.buttonBox.button( QDialogButtonBox.Ok ).setEnabled( bEnableOkButton )
评论列表
文章目录