From 5402247a382a84535a08fe7473e07f191344db0b Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Tue, 2 Jun 2020 15:08:16 +0200 Subject: [PATCH] Fix setting editor widget setup --- qfieldsync/core/offline_converter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qfieldsync/core/offline_converter.py b/qfieldsync/core/offline_converter.py index a2a5921d..d2c1e19f 100644 --- a/qfieldsync/core/offline_converter.py +++ b/qfieldsync/core/offline_converter.py @@ -174,17 +174,22 @@ def convert(self): QgsProject.instance().setEvaluateDefaultValues(False) QgsProject.instance().setAutoTransaction(False) - # check and convert value relations + # check if value relations point to offline layers and adjust if necessary for layer in project.mapLayers().values(): if layer.type() == QgsMapLayer.VectorLayer: for field in layer.fields(): ews = field.editorWidgetSetup() if ews.type() == 'ValueRelation': - online_layer_id = ews.config()['Layer'] + widget_config = ews.config() + online_layer_id = widget_config['Layer'] + if project.mapLayer(online_layer_id): + continue + layer_name = original_names[online_layer_id] + " (offline)" layer_id = project.mapLayersByName(layer_name)[0].id() - ews.config()['Layer'] = layer_id - layer.setEditorWidgetSetup(layer.fields().indexOf(field.name()), ews) + widget_config['Layer'] = layer_id + offline_ews = QgsEditorWidgetSetup(ews.type(), widget_config) + layer.setEditorWidgetSetup(layer.fields().indexOf(field.name()), offline_ews) # Now we have a project state which can be saved as offline project QgsProject.instance().write(project_path)