Skip to content
Permalink
Browse files

make vector joins work within layer-definition-files

  • Loading branch information
SebDieBln committed Dec 27, 2015
1 parent 5a42728 commit ff3200fd6c507429b50c56b8307869d62cce6dcf
Showing with 24 additions and 0 deletions.
  1. +24 −0 src/core/qgslayerdefinition.cpp
@@ -6,6 +6,7 @@

#include "qgslogger.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgslayertree.h"
#include "qgsmaplayerregistry.h"
#include "qgslayerdefinition.h"
@@ -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" );
@@ -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 );

0 comments on commit ff3200f

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