@@ -254,6 +254,7 @@ void QgsOfflineEditing::synchronize()
254
254
255
255
// copy style
256
256
copySymbology ( offlineLayer, remoteLayer );
257
+ updateRelations ( offlineLayer, remoteLayer );
257
258
258
259
// apply layer edit log
259
260
QString qgisLayerId = layer->id ();
@@ -611,6 +612,7 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
611
612
}
612
613
}
613
614
615
+ updateRelations ( layer, newLayer );
614
616
// copy features
615
617
newLayer->startEditing ();
616
618
QgsFeature f;
@@ -898,6 +900,29 @@ void QgsOfflineEditing::copySymbology( QgsVectorLayer* sourceLayer, QgsVectorLay
898
900
}
899
901
}
900
902
903
+ void QgsOfflineEditing::updateRelations ( QgsVectorLayer* sourceLayer, QgsVectorLayer* targetLayer )
904
+ {
905
+ QgsRelationManager* relationManager = QgsProject::instance ()->relationManager ();
906
+ QList<QgsRelation> relations;
907
+ relations = relationManager->referencedRelations ( sourceLayer );
908
+
909
+ Q_FOREACH ( QgsRelation relation, relations )
910
+ {
911
+ relationManager->removeRelation ( relation );
912
+ relation.setReferencedLayer ( targetLayer->id () );
913
+ relationManager->addRelation ( relation );
914
+ }
915
+
916
+ relations = relationManager->referencingRelations ( sourceLayer );
917
+
918
+ Q_FOREACH ( QgsRelation relation, relations )
919
+ {
920
+ relationManager->removeRelation ( relation );
921
+ relation.setReferencingLayer ( targetLayer->id () );
922
+ relationManager->addRelation ( relation );
923
+ }
924
+ }
925
+
901
926
// NOTE: use this to map column indices in case the remote geometry column is not last
902
927
QMap<int , int > QgsOfflineEditing::attributeLookup ( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer )
903
928
{
0 commit comments