|
@@ -216,34 +216,32 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry ) |
|
|
// n:m Relation: first let the user create a new feature on the other table |
|
|
// and autocreate a new linking feature. |
|
|
QgsFeature f; |
|
|
if ( vlTools->addFeature( mNmRelation.referencedLayer(), QgsAttributeMap(), geometry, &f ) ) |
|
|
{ |
|
|
// Fields of the linking table |
|
|
const QgsFields fields = mRelation.referencingLayer()->fields(); |
|
|
|
|
|
// Expression context for the linking table |
|
|
QgsExpressionContext context = mRelation.referencingLayer()->createExpressionContext(); |
|
|
if ( vlTools->addFeature( mNmRelation.referencedLayer(), QgsAttributeMap(), geometry, &f ) == false ) |
|
|
return; |
|
|
|
|
|
QgsAttributeMap linkAttributes; |
|
|
const auto constFieldPairs = mRelation.fieldPairs(); |
|
|
for ( const QgsRelation::FieldPair &fieldPair : constFieldPairs ) |
|
|
{ |
|
|
int index = fields.indexOf( fieldPair.first ); |
|
|
linkAttributes.insert( index, mFeature.attribute( fieldPair.second ) ); |
|
|
} |
|
|
// Fields of the linking table |
|
|
const QgsFields fields = mRelation.referencingLayer()->fields(); |
|
|
|
|
|
const auto constNmFieldPairs = mNmRelation.fieldPairs(); |
|
|
for ( const QgsRelation::FieldPair &fieldPair : constNmFieldPairs ) |
|
|
{ |
|
|
int index = fields.indexOf( fieldPair.first ); |
|
|
linkAttributes.insert( index, f.attribute( fieldPair.second ) ); |
|
|
} |
|
|
QgsFeature linkFeature = QgsVectorLayerUtils::createFeature( mRelation.referencingLayer(), QgsGeometry(), linkAttributes, &context ); |
|
|
// Expression context for the linking table |
|
|
QgsExpressionContext context = mRelation.referencingLayer()->createExpressionContext(); |
|
|
|
|
|
mRelation.referencingLayer()->addFeature( linkFeature ); |
|
|
QgsAttributeMap linkAttributes; |
|
|
const auto constFieldPairs = mRelation.fieldPairs(); |
|
|
for ( const QgsRelation::FieldPair &fieldPair : constFieldPairs ) |
|
|
{ |
|
|
int index = fields.indexOf( fieldPair.first ); |
|
|
linkAttributes.insert( index, mFeature.attribute( fieldPair.second ) ); |
|
|
} |
|
|
|
|
|
updateUi(); |
|
|
const auto constNmFieldPairs = mNmRelation.fieldPairs(); |
|
|
for ( const QgsRelation::FieldPair &fieldPair : constNmFieldPairs ) |
|
|
{ |
|
|
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 ); |
|
|
} |
|
|
else |
|
|
{ |
|
@@ -260,8 +258,11 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry ) |
|
|
keyAttrs.insert( fields.indexFromName( fieldPair.referencingField() ), mFeature.attribute( fieldPair.referencedField() ) ); |
|
|
} |
|
|
|
|
|
vlTools->addFeature( mRelation.referencingLayer(), keyAttrs, geometry ); |
|
|
if ( vlTools->addFeature( mRelation.referencingLayer(), keyAttrs, geometry ) == false ) |
|
|
return; |
|
|
} |
|
|
|
|
|
updateUi(); |
|
|
} |
|
|
|
|
|
void QgsAbstractRelationEditorWidget::deleteFeature( const QgsFeatureId fid ) |
|
@@ -542,8 +543,6 @@ void QgsAbstractRelationEditorWidget::unlinkFeatures( const QgsFeatureIds &fids |
|
|
} |
|
|
|
|
|
mRelation.referencingLayer()->deleteFeatures( fids ); |
|
|
|
|
|
updateUi(); |
|
|
} |
|
|
else |
|
|
{ |
|
@@ -584,6 +583,8 @@ void QgsAbstractRelationEditorWidget::unlinkFeatures( const QgsFeatureIds &fids |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
updateUi(); |
|
|
} |
|
|
|
|
|
void QgsAbstractRelationEditorWidget::updateUi() |
|
|