Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make vector joins work within layer-definition-files
  • Loading branch information
SebDieBln committed Jan 1, 2016
1 parent 5a42728 commit ff3200f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/qgslayerdefinition.cpp
Expand Up @@ -6,6 +6,7 @@

#include "qgslogger.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgslayertree.h"
#include "qgsmaplayerregistry.h"
#include "qgslayerdefinition.h"
Expand Down Expand Up @@ -62,6 +63,18 @@ bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsLayerTreeGrou
layerNode.toElement().setAttribute( "id", newid );
}
}

// change layer IDs for vector joins
QDomNodeList vectorJoinNodes = doc.elementsByTagName( "join" ); // TODO: Find a better way of searching for vectorjoins, there might be other <join> elements within the project.
for ( int j = 0; j < vectorJoinNodes.size(); ++j )
{
QDomNode joinNode = vectorJoinNodes.at( j );
QDomElement joinElement = joinNode.toElement();
if ( joinElement.attribute( "joinLayerId" ) == oldid )
{
joinNode.toElement().setAttribute( "joinLayerId", newid );
}
}
}

QDomElement layerTreeElem = doc.documentElement().firstChildElement( "layer-tree-group" );
Expand All @@ -75,6 +88,17 @@ bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsLayerTreeGrou
QList<QgsMapLayer*> layers = QgsMapLayer::fromLayerDefinition( doc );
QgsMapLayerRegistry::instance()->addMapLayers( layers, loadInLegend );

// Now that all layers are loaded, refresh the vectorjoins to get the joined fields
Q_FOREACH ( QgsMapLayer* layer, layers )
{
QgsVectorLayer* vlayer = static_cast< QgsVectorLayer * >( layer );
if ( vlayer )
{
vlayer->createJoinCaches();
vlayer->updateFields();
}
}

QList<QgsLayerTreeNode*> nodes = root->children();
Q_FOREACH ( QgsLayerTreeNode *node, nodes )
root->takeChild( node );
Expand Down

0 comments on commit ff3200f

Please sign in to comment.