You could achieve this based on the QGIS Combo Manager
Just create your own filter for the fields in a subclass of FieldCombo. The following code is untested (literally), so please bear with me if there's a typo or other minor problems, and think of it as a reference.
from qgiscombomanager import *
class MyFieldCombo( FieldCombo ):
def __init__(self, widget, vectorLayerCombo1, vectorLayerCombo2, initField="", options={}):
FieldCombo.__init__(self, widget, vectorLayerCombo1, vectorLayerCombo2, initField, options)
self.vectorLayerCombo1 = vectorLayerCombo1
self.vectorLayerCombo2 = vectorLayerCombo2
# Overrides the filter from FieldCombo. Will be called for every field
# and should return True, if the field should be shown.
def __isFieldValid(self, idx):
if not FieldCombo.__isFieldValid(self, idx):
return False
for f in self.vectorLayerCombo2.pendingFields():
# adjust this line to reflect your idea of "common"
if f.name() == self.vectorLayerCombo1.pendingFields()[idx].name():
return True
return False
# run method that performs all the real work
def run(self):
# show the dialog
self.dlg.show()
self.vlc1 = VectorLayerCombo( self.dlg.comboBox )
self.vlc2 = VectorLayerCombo( self.dlg.comboBox_2 )
self.fc = MyFieldCombo( self.dlg.comboBox_3 )