Skip to content

Commit

Permalink
Respect default values in N:M relation linking table
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 11, 2017
1 parent 72c8335 commit bfa507a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/gui/qgsrelationeditorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,22 @@ void QgsRelationEditorWidget::addFeature()
QgsFeature f;
if ( vlTools->addFeature( mNmRelation.referencedLayer(), QgsAttributeMap(), QgsGeometry(), &f ) )
{
QgsFeature flink( mRelation.referencingLayer()->fields() ); // Linking feature
QgsFields fields = mRelation.referencingLayer()->fields();
QgsFeature flink( fields ); // Linking feature
int attrCount = fields.size();

flink.setAttribute( mRelation.fieldPairs().at( 0 ).first, mFeature.attribute( mRelation.fieldPairs().at( 0 ).second ) );
flink.setAttribute( mNmRelation.referencingFields().at( 0 ), f.attribute( mNmRelation.referencedFields().at( 0 ) ) );
int firstIdx = fields.indexFromName( mRelation.fieldPairs().at( 0 ).first );
int secondIdx = mNmRelation.referencingFields().at( 0 );

for ( int i = 0; i < attrCount; ++i )
{
if ( i == firstIdx )
flink.setAttribute( i, mFeature.attribute( mRelation.fieldPairs().at( 0 ).second ) );
else if ( i == secondIdx )
flink.setAttribute( i, f.attribute( mNmRelation.referencedFields().at( 0 ) ) );
else
flink.setAttribute( i, mRelation.referencingLayer()->defaultValue( i ) );
}

mRelation.referencingLayer()->addFeature( flink );

Expand Down

0 comments on commit bfa507a

Please sign in to comment.