Fix joins are not recreated when loading project with bad layers (fix #10500)

This commit is contained in:
Nyall Dawson 2016-06-14 11:31:58 +10:00
parent 92830a2509
commit b1450802b9
2 changed files with 33 additions and 3 deletions

View File

@ -578,6 +578,15 @@ QgsProjectVersion getVersion( const QDomDocument& doc )
return projectVersion; return projectVersion;
} }
void QgsProject::processLayerJoins( QgsVectorLayer* layer )
{
if ( !layer )
return;
layer->createJoinCaches();
layer->updateFields();
}
bool QgsProject::_getMapLayers( const QDomDocument& doc, QList<QDomNode>& brokenNodes ) bool QgsProject::_getMapLayers( const QDomDocument& doc, QList<QDomNode>& brokenNodes )
{ {
// Layer order is set by the restoring the legend settings from project file. // Layer order is set by the restoring the legend settings from project file.
@ -641,8 +650,7 @@ bool QgsProject::_getMapLayers( const QDomDocument& doc, QList<QDomNode>& broken
QList< QPair< QgsVectorLayer*, QDomElement > >::iterator vIt = vLayerList.begin(); QList< QPair< QgsVectorLayer*, QDomElement > >::iterator vIt = vLayerList.begin();
for ( ; vIt != vLayerList.end(); ++vIt ) for ( ; vIt != vLayerList.end(); ++vIt )
{ {
vIt->first->createJoinCaches(); processLayerJoins( vIt->first );
vIt->first->updateFields();
} }
QSet<QgsVectorLayer *> notified; QSet<QgsVectorLayer *> notified;
@ -975,7 +983,24 @@ bool QgsProject::read( QDomNode &layerNode )
{ {
QList<QDomNode> brokenNodes; QList<QDomNode> brokenNodes;
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList; QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;
return addLayer( layerNode.toElement(), brokenNodes, vectorLayerList ); if ( addLayer( layerNode.toElement(), brokenNodes, vectorLayerList ) )
{
// have to try to update joins for all layers now - a previously added layer may be dependant on this newly
// added layer for joins
QVector<QgsVectorLayer*> vectorLayers = QgsMapLayerRegistry::instance()->layers<QgsVectorLayer*>();
Q_FOREACH ( QgsVectorLayer* layer, vectorLayers )
{
processLayerJoins( layer );
}
if ( !vectorLayerList.isEmpty() )
{
emit readMapLayer( vectorLayerList.at( 0 ).first, vectorLayerList.at( 0 ).second );
}
return true;
}
return false;
} }
bool QgsProject::write( QFileInfo const &file ) bool QgsProject::write( QFileInfo const &file )

View File

@ -491,6 +491,11 @@ class CORE_EXPORT QgsProject : public QObject
*/ */
bool _getMapLayers( QDomDocument const &doc, QList<QDomNode>& brokenNodes ); bool _getMapLayers( QDomDocument const &doc, QList<QDomNode>& brokenNodes );
/** Processes any joins attached to a newly added layer.
* @param layer layer to process
*/
void processLayerJoins( QgsVectorLayer* layer );
QString mErrorMessage; QString mErrorMessage;
QgsProjectBadLayerHandler* mBadLayerHandler; QgsProjectBadLayerHandler* mBadLayerHandler;