Skip to content
Permalink
Browse files

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

  • Loading branch information
nyalldawson committed Jun 14, 2016
1 parent 92830a2 commit b1450802b99ac4a19b5ed4765066bcdf1e520556
Showing with 33 additions and 3 deletions.
  1. +28 −3 src/core/qgsproject.cpp
  2. +5 −0 src/core/qgsproject.h
@@ -578,6 +578,15 @@ QgsProjectVersion getVersion( const QDomDocument& doc )
return projectVersion;
}

void QgsProject::processLayerJoins( QgsVectorLayer* layer )
{
if ( !layer )
return;

layer->createJoinCaches();
layer->updateFields();
}

bool QgsProject::_getMapLayers( const QDomDocument& doc, QList<QDomNode>& brokenNodes )
{
// 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();
for ( ; vIt != vLayerList.end(); ++vIt )
{
vIt->first->createJoinCaches();
vIt->first->updateFields();
processLayerJoins( vIt->first );
}

QSet<QgsVectorLayer *> notified;
@@ -975,7 +983,24 @@ bool QgsProject::read( QDomNode &layerNode )
{
QList<QDomNode> brokenNodes;
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 )
@@ -491,6 +491,11 @@ class CORE_EXPORT QgsProject : public QObject
*/
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;

QgsProjectBadLayerHandler* mBadLayerHandler;

0 comments on commit b145080

Please sign in to comment.
You can’t perform that action at this time.