ImportAutoFieldsDialog.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:AutoFields 作者: gacarrillor 项目源码 文件源码
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 )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号