Skip to content

Commit 489e34b

Browse files
author
mhugent
committed
Fix loading of joined layers with old symbology, #121
git-svn-id: http://svn.osgeo.org/qgis/trunk@15450 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 906c7dd commit 489e34b

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src/core/qgsproject.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -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 );

src/core/renderer/qgscontinuouscolorrenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ int QgsContinuousColorRenderer::readXML( const QDomNode& rnode, QgsVectorLayer&
205205
int classificationId = theProvider->fieldNameIndex( classificationField );
206206
if ( classificationId == -1 )
207207
{
208-
return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
208+
//go on. Because with joins, it might be the joined layer is not loaded yet
209209
}
210210
setClassificationField( classificationId );
211211

src/core/renderer/qgsgraduatedsymbolrenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ int QgsGraduatedSymbolRenderer::readXML( const QDomNode& rnode, QgsVectorLayer&
268268
mMode = QgsGraduatedSymbolRenderer::EqualInterval;
269269
}
270270

271-
int classificationId = theProvider->fieldNameIndex( classificationField );
271+
int classificationId = vl.fieldNameIndex( classificationField );
272272
if ( classificationId == -1 )
273273
{
274-
return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
274+
//go on. Because with joins, it might be the joined layer is not loaded yet
275275
}
276276
setClassificationField( classificationId );
277277

src/core/renderer/qgsuniquevaluerenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int QgsUniqueValueRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
228228
int classificationId = theProvider->fieldNameIndex( classificationField );
229229
if ( classificationId == -1 )
230230
{
231-
return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
231+
//go on. Because with joins, it might be the joined layer is not loaded yet
232232
}
233233
setClassificationField( classificationId );
234234

0 commit comments

Comments
 (0)