Skip to content
Permalink
Browse files

Merge pull request #42256 from domi4484/abstractRelationWidgetUpdateUi

Added missing calls to updateUi hook
  • Loading branch information
m-kuhn committed Mar 18, 2021
2 parents 0c75aa3 + ae6aeea commit c22f5a927bef349ff56335610209a33ed2e2c27f
Showing with 27 additions and 26 deletions.
  1. +27 −26 src/gui/qgsabstractrelationeditorwidget.cpp
@@ -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 ) )
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 ) )
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()

0 comments on commit c22f5a9

Please sign in to comment.