Skip to content

Commit

Permalink
Fix relations in offline editing
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Feb 22, 2017
1 parent 84cc377 commit 94c4d6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -256,6 +256,7 @@ void QgsOfflineEditing::synchronize()

// copy style
copySymbology( offlineLayer, remoteLayer );
updateRelations( offlineLayer, remoteLayer );

// apply layer edit log
QString qgisLayerId = layer->id();
Expand Down Expand Up @@ -630,6 +631,7 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
copySymbology( layer, newLayer );
}

updateRelations( layer, newLayer );
// copy features
newLayer->startEditing();
QgsFeature f;
Expand Down Expand Up @@ -945,6 +947,29 @@ void QgsOfflineEditing::copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLay
}
}

void QgsOfflineEditing::updateRelations( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer )
{
QgsRelationManager* relationManager = QgsProject::instance()->relationManager();
QList<QgsRelation> relations;
relations = relationManager->referencedRelations( sourceLayer );

Q_FOREACH ( QgsRelation relation, relations )
{
relationManager->removeRelation( relation );
relation.setReferencedLayer( targetLayer->id() );
relationManager->addRelation( relation );
}

relations = relationManager->referencingRelations( sourceLayer );

Q_FOREACH ( QgsRelation relation, relations )
{
relationManager->removeRelation( relation );
relation.setReferencingLayer( targetLayer->id() );
relationManager->addRelation( relation );
}
}

// NOTE: use this to map column indices in case the remote geometry column is not last
QMap<int, int> QgsOfflineEditing::attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer )
{
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsofflineediting.h
Expand Up @@ -108,6 +108,10 @@ class CORE_EXPORT QgsOfflineEditing : public QObject
void applyGeometryChanges( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId, int commitNo );
void updateFidLookup( QgsVectorLayer* remoteLayer, sqlite3* db, int layerId );
void copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
/**
* Updates all relations that reference or are referenced by the source layer to the targetLayer.
*/
void updateRelations( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer );
QMap<int, int> attributeLookup( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer );

void showWarning( const QString& message );
Expand Down

0 comments on commit 94c4d6b

Please sign in to comment.