Skip to content

Commit

Permalink
Fix multi-editing can lead to crash
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and github-actions[bot] committed Sep 17, 2024
1 parent 51c2afb commit 97428ad
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core/featuremodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,19 @@ bool FeatureModel::save()

case MultiFeatureModel:
{
for ( QgsFeature &feature : mFeatures )
// We need to copy these members as the first feature updated triggers a refresh of the selected features, leading to changes in feature model members
const QgsFeature referenceFeature = mFeature;
const QList<bool> attributesAllowEdit = mAttributesAllowEdit;
QList<QgsFeature> features = mFeatures;
for ( QgsFeature &feature : features )
{
for ( int i = 0; i < mFeature.attributes().count(); i++ )
for ( int i = 0; i < referenceFeature.attributes().count(); i++ )
{
if ( !mAttributesAllowEdit[i] )
if ( !attributesAllowEdit[i] )
continue;

feature.setAttribute( i, mFeature.attributes().at( i ) );
feature.setAttribute( i, referenceFeature.attributes().at( i ) );
}

if ( !mLayer->updateFeature( feature ) )
{
QgsMessageLog::logMessage( tr( "Cannot update feature" ), QStringLiteral( "QField" ), Qgis::Warning );
Expand Down

0 comments on commit 97428ad

Please sign in to comment.