Skip to content

Commit

Permalink
handle fid attribute in attrLookup on synchronization
Browse files Browse the repository at this point in the history
and use column++ again on iteration through attributes on copyVectorLayer

fixes #20276 especially the not reported issue with synchronization

(cherry-picked from 0f65317)
  • Loading branch information
signedav committed Dec 11, 2018
1 parent 20ea3d6 commit e1c4419
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -762,10 +762,10 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit


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


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


return attrLookup; return attrLookup;
Expand Down

0 comments on commit e1c4419

Please sign in to comment.