@@ -59,7 +59,7 @@ QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget* parent )
59
59
, mCanvas( NULL )
60
60
, mMessageBar( NULL )
61
61
, mForeignKey( QVariant() )
62
- , mFkeyFieldIdx ( -1 )
62
+ , mReferencedFieldIdx ( -1 )
63
63
, mAllowNull( true )
64
64
, mHighlight( NULL )
65
65
, mMapTool( NULL )
@@ -199,7 +199,8 @@ void QgsRelationReferenceWidget::setRelation( const QgsRelation& relation, bool
199
199
mReferencingLayer = relation.referencingLayer ();
200
200
mRelationName = relation.name ();
201
201
mReferencedLayer = relation.referencedLayer ();
202
- mFkeyFieldIdx = mReferencedLayer ->fieldNameIndex ( relation.fieldPairs ().at ( 0 ).second );
202
+ mReferencedFieldIdx = mReferencedLayer ->fieldNameIndex ( relation.fieldPairs ().at ( 0 ).second );
203
+ mReferencingFieldIdx = mReferencingLayer ->fieldNameIndex ( relation.fieldPairs ().at ( 0 ).first );
203
204
204
205
QgsAttributeEditorContext context ( mEditorContext , relation, QgsAttributeEditorContext::Single, QgsAttributeEditorContext::Embed );
205
206
@@ -260,7 +261,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
260
261
return ;
261
262
}
262
263
263
- mForeignKey = mFeature .attribute ( mFkeyFieldIdx );
264
+ mForeignKey = mFeature .attribute ( mReferencedFieldIdx );
264
265
265
266
if ( mReadOnlySelector )
266
267
{
@@ -273,7 +274,7 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
273
274
QString title = expr.evaluate ( &context ).toString ();
274
275
if ( expr.hasEvalError () )
275
276
{
276
- title = mFeature .attribute ( mFkeyFieldIdx ).toString ();
277
+ title = mFeature .attribute ( mReferencedFieldIdx ).toString ();
277
278
}
278
279
mLineEdit ->setText ( title );
279
280
}
@@ -355,11 +356,11 @@ QVariant QgsRelationReferenceWidget::foreignKey()
355
356
{
356
357
if ( !mFeature .isValid () )
357
358
{
358
- return QVariant ( mReferencingLayer ->fields ().at ( mFkeyFieldIdx ).type () );
359
+ return QVariant ( mReferencingLayer ->fields ().at ( mReferencingFieldIdx ).type () );
359
360
}
360
361
else
361
362
{
362
- return mFeature .attribute ( mFkeyFieldIdx );
363
+ return mFeature .attribute ( mReferencedFieldIdx );
363
364
}
364
365
}
365
366
}
@@ -675,7 +676,7 @@ void QgsRelationReferenceWidget::comboReferenceChanged( int index )
675
676
mReferencedLayer ->getFeatures ( QgsFeatureRequest ().setFilterFid ( fid ) ).nextFeature ( mFeature );
676
677
highlightFeature ( mFeature );
677
678
updateAttributeEditorFrame ( mFeature );
678
- emit foreignKeyChanged ( mFeature .attribute ( mFkeyFieldIdx ) );
679
+ emit foreignKeyChanged ( mFeature .attribute ( mReferencedFieldIdx ) );
679
680
}
680
681
681
682
void QgsRelationReferenceWidget::updateAttributeEditorFrame ( const QgsFeature& feature )
@@ -703,15 +704,15 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
703
704
QString title = expr.evaluate ( &context ).toString ();
704
705
if ( expr.hasEvalError () )
705
706
{
706
- title = feature.attribute ( mFkeyFieldIdx ).toString ();
707
+ title = feature.attribute ( mReferencedFieldIdx ).toString ();
707
708
}
708
709
mLineEdit ->setText ( title );
709
- mForeignKey = feature.attribute ( mFkeyFieldIdx );
710
+ mForeignKey = feature.attribute ( mReferencedFieldIdx );
710
711
mFeature = feature;
711
712
}
712
713
else
713
714
{
714
- mComboBox ->setCurrentIndex ( mComboBox ->findData ( feature.attribute ( mFkeyFieldIdx ), QgsAttributeTableModel::FeatureIdRole ) );
715
+ mComboBox ->setCurrentIndex ( mComboBox ->findData ( feature.attribute ( mReferencedFieldIdx ), QgsAttributeTableModel::FeatureIdRole ) );
715
716
mFeature = feature;
716
717
}
717
718
0 commit comments