@@ -118,8 +118,7 @@ void QgsAttributesFormProperties::loadAttributeTypeDialog()
118118}
119119
120120
121- void QgsAttributesFormProperties::storeAttributeTypeDialog ()
122- {
121+ void QgsAttributesFormProperties::storeAttributeTypeDialog (){
123122 FieldConfig cfg;
124123
125124 cfg.mEditable = mAttributeTypeDialog ->fieldEditable ();
@@ -194,8 +193,17 @@ void QgsAttributesFormProperties::loadAttributeRelationEdit()
194193 RelationConfig cfg = currentItem->data ( 0 , RelationConfigRole ).value <RelationConfig>();
195194
196195 mAttributeRelationEdit = new QgsAttributeRelationEdit ( currentItem->data ( 0 , FieldNameRole ).toString (), mAttributeTypeFrame );
197- mAttributeRelationEdit ->setCardinalityCombo ( " testoption 1" );
198- mAttributeRelationEdit ->setCardinalityCombo ( " testoption 2" );
196+
197+ mAttributeRelationEdit ->setCardinalityCombo ( tr ( " Many to one relation" ) );
198+
199+ QgsRelation relation = QgsProject::instance ()->relationManager ()->relation ( currentItem->data ( 0 , FieldNameRole ).toString () );
200+
201+ Q_FOREACH ( const QgsRelation &nmrel, QgsProject::instance ()->relationManager ()->referencingRelations ( relation.referencingLayer () ) )
202+ {
203+ if ( nmrel.fieldPairs ().at ( 0 ).referencingField () != relation.fieldPairs ().at ( 0 ).referencingField () )
204+ mAttributeRelationEdit ->setCardinalityCombo ( QStringLiteral ( " %1 (%2)" ).arg ( nmrel.referencedLayer ()->name (), nmrel.fieldPairs ().at ( 0 ).referencedField () ), nmrel.id () );
205+ }
206+
199207 mAttributeRelationEdit ->setCardinality ( cfg.mCardinality );
200208
201209 mAttributeRelationEdit ->layout ()->setMargin ( 0 );
@@ -501,14 +509,9 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
501509
502510void QgsAttributesFormProperties::apply ()
503511{
504- if ( mAttributeTypeDialog )
505- {
506- storeAttributeTypeDialog ();
507- }
508- else
509- {
510- storeAttributeRelationEdit ();
511- }
512+
513+ storeAttributeTypeDialog ();
514+ storeAttributeRelationEdit ();
512515
513516 QgsEditFormConfig editFormConfig = mLayer ->editFormConfig ();
514517
0 commit comments