Skip to content

Commit e1c4419

Browse files
committed
handle fid attribute in attrLookup on synchronization
and use column++ again on iteration through attributes on copyVectorLayer fixes #20276 especially the not reported issue with synchronization (cherry-picked from 0f65317)
1 parent 20ea3d6 commit e1c4419

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/core/qgsofflineediting.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,10 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
762762

763763
// NOTE: SpatiaLite provider ignores position of geometry column
764764
// fill gap in QgsAttributeMap if geometry column is not last (WORKAROUND)
765+
int column = 0;
765766
QgsAttributes attrs = f.attributes();
766767
// on GPKG newAttrs has an addition FID attribute, so we have to add a dummy in the original set
767768
QgsAttributes newAttrs( containerType == GPKG ? attrs.count() + 1 : attrs.count() );
768-
int column = 0;
769769
for ( int it = 0; it < attrs.count(); ++it )
770770
{
771771
newAttrs[column++] = attrs.at( it );
@@ -1137,13 +1137,14 @@ void QgsOfflineEditing::updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVector
11371137
QMap<int, int> QgsOfflineEditing::attributeLookup( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer )
11381138
{
11391139
const QgsAttributeList &offlineAttrs = offlineLayer->attributeList();
1140-
const QgsAttributeList &remoteAttrs = remoteLayer->attributeList();
11411140

11421141
QMap < int /*offline attr*/, int /*remote attr*/ > attrLookup;
1143-
// NOTE: use size of remoteAttrs, as offlineAttrs can have new attributes not yet synced
1144-
for ( int i = 0; i < remoteAttrs.size(); i++ )
1142+
// NOTE: though offlineAttrs can have new attributes not yet synced, we take the amount of offlineAttrs
1143+
// because we anyway only add mapping for the fields existing in remoteLayer (this because it could contain fid on 0)
1144+
for ( int i = 0; i < offlineAttrs.size(); i++ )
11451145
{
1146-
attrLookup.insert( offlineAttrs.at( i ), remoteAttrs.at( i ) );
1146+
if ( remoteLayer->fields().lookupField( offlineLayer->fields().field( i ).name() ) >= 0 )
1147+
attrLookup.insert( offlineAttrs.at( i ), remoteLayer->fields().indexOf( offlineLayer->fields().field( i ).name() ) );
11471148
}
11481149

11491150
return attrLookup;

0 commit comments

Comments
 (0)