Skip to content

Commit

Permalink
[offline editing] fix overwriting of first field on remote layer when…
Browse files Browse the repository at this point in the history
… it has virtual fields (#45002)
  • Loading branch information
3nids committed Sep 9, 2021
1 parent e05e9c0 commit 6c39e30
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -1020,12 +1020,16 @@ void QgsOfflineEditing::applyFeaturesAdded( QgsVectorLayer *offlineLayer, QgsVec
{
// NOTE: SpatiaLite provider ignores position of geometry column
// restore gap in QgsAttributeMap if geometry column is not last (WORKAROUND)
QMap<int, int> attrLookup = attributeLookup( offlineLayer, remoteLayer );
const QMap<int, int> attrLookup = attributeLookup( offlineLayer, remoteLayer );
QgsAttributes newAttrs( newAttrsCount );
QgsAttributes attrs = it->attributes();
for ( int it = 0; it < attrs.count(); ++it )
{
newAttrs[ attrLookup[ it ] ] = attrs.at( it );
const int remoteAttributeIndex = attrLookup.value( it, -1 );
// if virtual or non existing field
if ( remoteAttributeIndex == -1 )
continue;
newAttrs[ remoteAttributeIndex ] = attrs.at( it );
}

// respect constraints and provider default values
Expand Down Expand Up @@ -1739,4 +1743,3 @@ void QgsOfflineEditing::layerAdded( QgsMapLayer *layer )
connect( vLayer, &QgsVectorLayer::editingStopped, this, &QgsOfflineEditing::stopListenFeatureChanges );
}
}

0 comments on commit 6c39e30

Please sign in to comment.