mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
N:M Relations, support for linking table with default values
This commit is contained in:
parent
30eec2b392
commit
0c35dde461
@ -306,12 +306,27 @@ void QgsRelationEditorWidget::addFeature()
|
|||||||
QgsFeature f;
|
QgsFeature f;
|
||||||
if ( vlTools->addFeature( mNmRelation.referencedLayer(), QgsAttributeMap(), QgsGeometry(), &f ) )
|
if ( vlTools->addFeature( mNmRelation.referencedLayer(), QgsAttributeMap(), QgsGeometry(), &f ) )
|
||||||
{
|
{
|
||||||
QgsFeature flink( mRelation.referencingLayer()->fields() ); // Linking feature
|
// Fields of the linking table
|
||||||
|
const QgsFields fields = mRelation.referencingLayer()->fields();
|
||||||
|
|
||||||
flink.setAttribute( mRelation.fieldPairs().at( 0 ).first, mFeature.attribute( mRelation.fieldPairs().at( 0 ).second ) );
|
// Expression context for the linking table
|
||||||
flink.setAttribute( mNmRelation.referencingFields().at( 0 ), f.attribute( mNmRelation.referencedFields().at( 0 ) ) );
|
QgsExpressionContext context = mRelation.referencingLayer()->createExpressionContext();
|
||||||
|
|
||||||
mRelation.referencingLayer()->addFeature( flink );
|
QgsAttributeMap linkAttributes;
|
||||||
|
Q_FOREACH ( const QgsRelation::FieldPair &fieldPair, mRelation.fieldPairs() )
|
||||||
|
{
|
||||||
|
int index = fields.indexOf( fieldPair.first );
|
||||||
|
linkAttributes.insert( index, mFeature.attribute( fieldPair.second ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_FOREACH ( const QgsRelation::FieldPair &fieldPair, mNmRelation.fieldPairs() )
|
||||||
|
{
|
||||||
|
int index = fields.indexOf( fieldPair.first );
|
||||||
|
linkAttributes.insert( index, f.attribute( fieldPair.second ) );
|
||||||
|
}
|
||||||
|
QgsFeature linkFeature = QgsVectorLayerUtils::createFeature( mRelation.referencingLayer(), QgsGeometry(), linkAttributes, &context );
|
||||||
|
|
||||||
|
mRelation.referencingLayer()->addFeature( linkFeature );
|
||||||
|
|
||||||
updateUi();
|
updateUi();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user