@@ -762,10 +762,10 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
762
762
763
763
// NOTE: SpatiaLite provider ignores position of geometry column
764
764
// fill gap in QgsAttributeMap if geometry column is not last (WORKAROUND)
765
+ int column = 0 ;
765
766
QgsAttributes attrs = f.attributes ();
766
767
// on GPKG newAttrs has an addition FID attribute, so we have to add a dummy in the original set
767
768
QgsAttributes newAttrs ( containerType == GPKG ? attrs.count () + 1 : attrs.count () );
768
- int column = 0 ;
769
769
for ( int it = 0 ; it < attrs.count (); ++it )
770
770
{
771
771
newAttrs[column++] = attrs.at ( it );
@@ -1137,13 +1137,14 @@ void QgsOfflineEditing::updateLayerOrder( QgsVectorLayer *sourceLayer, QgsVector
1137
1137
QMap<int , int > QgsOfflineEditing::attributeLookup ( QgsVectorLayer *offlineLayer, QgsVectorLayer *remoteLayer )
1138
1138
{
1139
1139
const QgsAttributeList &offlineAttrs = offlineLayer->attributeList ();
1140
- const QgsAttributeList &remoteAttrs = remoteLayer->attributeList ();
1141
1140
1142
1141
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++ )
1145
1145
{
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 () ) );
1147
1148
}
1148
1149
1149
1150
return attrLookup;
0 commit comments