From 772033dac4a607d03094bb2006cb1d7bd2a7dcc8 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Thu, 22 Jan 2015 16:29:56 +0100 Subject: [PATCH] Offline editing: preserve join field names (layer prefix) --- src/core/qgsofflineediting.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/qgsofflineediting.cpp b/src/core/qgsofflineediting.cpp index 9f644949d78..95255e041ab 100644 --- a/src/core/qgsofflineediting.cpp +++ b/src/core/qgsofflineediting.cpp @@ -95,7 +95,24 @@ bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath, { QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerIds.at( i ) ); QgsVectorLayer* vl = qobject_cast( layer ); - const QgsVectorJoinList& joins = vl->vectorJoins(); + QgsVectorJoinList joins = vl->vectorJoins(); + + // Layer names will be appended an _offline suffix + // Join fields are prefixed with the layer name and we do not want the + // field name to change so we stabilize the field name by defining a + // custom prefix with the layername without _offline suffix. + QgsVectorJoinList::iterator it = joins.begin(); + while ( it != joins.end() ) + { + if (( *it ).prefix.isNull() ) + { + QgsVectorLayer* vl = qobject_cast( QgsMapLayerRegistry::instance()->mapLayer(( *it ).joinLayerId ) ); + + if ( vl ) + ( *it ).prefix = vl->name() + "_"; + } + ++it; + } joinInfoBuffer.insert( vl->id(), joins ); }