@@ -675,7 +675,10 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
675675 bool returnStatus = true ;
676676
677677 emit layerLoaded ( 0 , nl.count () );
678- QList<QgsVectorLayer*> vLayerList; // collect
678+
679+ // Collect vector layers with joins.
680+ // They need to refresh join caches and symbology infos after all layers are loaded
681+ QList< QPair< QgsVectorLayer*, QDomElement > > vLayerList;
679682
680683 for ( int i = 0 ; i < nl.count (); i++ )
681684 {
@@ -716,9 +719,9 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
716719 {
717720 mapLayer = QgsMapLayerRegistry::instance ()->addMapLayer ( mapLayer );
718721 QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
719- if ( vLayer )
722+ if ( vLayer && vLayer-> vectorJoins (). size () > 0 )
720723 {
721- vLayerList.push_back ( vLayer );
724+ vLayerList.push_back ( qMakePair ( vLayer, element ) );
722725 }
723726 }
724727 else
@@ -736,11 +739,17 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
736739
737740 // Update field map of layers with joins and create join caches if necessary
738741 // Needs to be done here once all dependent layers are loaded
739- QList<QgsVectorLayer*>::iterator vIt = vLayerList.begin ();
742+ QString errorMessage;
743+ QList< QPair< QgsVectorLayer*, QDomElement > >::iterator vIt = vLayerList.begin ();
740744 for ( ; vIt != vLayerList.end (); ++vIt )
741745 {
742- ( *vIt )->createJoinCaches ();
743- ( *vIt )->updateFieldMap ();
746+ vIt->first ->createJoinCaches ();
747+ vIt->first ->updateFieldMap ();
748+ // for old symbology, it is necessary to read the symbology again after having the complete field map
749+ if ( !vIt->first ->isUsingRendererV2 () )
750+ {
751+ vIt->first ->readSymbology ( vIt->second , errorMessage );
752+ }
744753 }
745754
746755 return qMakePair ( returnStatus, brokenNodes );
0 commit comments