Skip to content

Commit

Permalink
Fix loading of joined layers with old symbology, #121
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15450 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 12, 2011
1 parent f376ec5 commit 78a0508
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/core/qgsproject.cpp
Expand Up @@ -675,7 +675,10 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
bool returnStatus = true;

emit layerLoaded( 0, nl.count() );
QList<QgsVectorLayer*> vLayerList; //collect

//Collect vector layers with joins.
//They need to refresh join caches and symbology infos after all layers are loaded
QList< QPair< QgsVectorLayer*, QDomElement > > vLayerList;

for ( int i = 0; i < nl.count(); i++ )
{
Expand Down Expand Up @@ -716,9 +719,9 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
{
mapLayer = QgsMapLayerRegistry::instance()->addMapLayer( mapLayer );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
if ( vLayer )
if ( vLayer && vLayer->vectorJoins().size() > 0 )
{
vLayerList.push_back( vLayer );
vLayerList.push_back( qMakePair( vLayer, element ) );
}
}
else
Expand All @@ -736,11 +739,17 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do

//Update field map of layers with joins and create join caches if necessary
//Needs to be done here once all dependent layers are loaded
QList<QgsVectorLayer*>::iterator vIt = vLayerList.begin();
QString errorMessage;
QList< QPair< QgsVectorLayer*, QDomElement > >::iterator vIt = vLayerList.begin();
for ( ; vIt != vLayerList.end(); ++vIt )
{
( *vIt )->createJoinCaches();
( *vIt )->updateFieldMap();
vIt->first->createJoinCaches();
vIt->first->updateFieldMap();
//for old symbology, it is necessary to read the symbology again after having the complete field map
if( !vIt->first->isUsingRendererV2() )
{
vIt->first->readSymbology( vIt->second, errorMessage );
}
}

return qMakePair( returnStatus, brokenNodes );
Expand Down
2 changes: 1 addition & 1 deletion src/core/renderer/qgscontinuouscolorrenderer.cpp
Expand Up @@ -205,7 +205,7 @@ int QgsContinuousColorRenderer::readXML( const QDomNode& rnode, QgsVectorLayer&
int classificationId = theProvider->fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
//go on. Because with joins, it might be the joined layer is not loaded yet
}
setClassificationField( classificationId );

Expand Down
4 changes: 2 additions & 2 deletions src/core/renderer/qgsgraduatedsymbolrenderer.cpp
Expand Up @@ -268,10 +268,10 @@ int QgsGraduatedSymbolRenderer::readXML( const QDomNode& rnode, QgsVectorLayer&
mMode = QgsGraduatedSymbolRenderer::EqualInterval;
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/core/renderer/qgsuniquevaluerenderer.cpp
Expand Up @@ -228,7 +228,7 @@ int QgsUniqueValueRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
int classificationId = theProvider->fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
//go on. Because with joins, it might be the joined layer is not loaded yet
}
setClassificationField( classificationId );

Expand Down

0 comments on commit 78a0508

Please sign in to comment.