Skip to content
Permalink
Browse files
Re-enable vector joins and value relations
  • Loading branch information
mhugent committed Apr 4, 2014
1 parent 3bd2537 commit 3df34a8ba5a0f3dcd8de74ad3e33daf116fb1908
@@ -20,6 +20,7 @@
#include "qgsconfigparserutils.h"
#include "qgscrscache.h"
#include "qgsdatasourceuri.h"
#include "qgsmaplayerregistry.h"
#include "qgsmslayercache.h"
#include "qgsrasterlayer.h"

@@ -76,9 +77,8 @@ void QgsServerProjectParser::projectLayerMap( QMap<QString, QgsMapLayer*>& layer
QList<QDomElement>::const_iterator layerElemIt = mProjectLayerElements.constBegin();
for ( ; layerElemIt != mProjectLayerElements.constEnd(); ++layerElemIt )
{
//todo: fixme
//addJoinLayersForElement( *layerElemIt );
//addValueRelationLayersForElement( *layerElemIt );
addJoinLayersForElement( *layerElemIt );
addValueRelationLayersForElement( *layerElemIt );
QgsMapLayer *layer = createLayerFromElement( *layerElemIt );
if ( layer )
{
@@ -257,6 +257,16 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
return layer;
}

QgsMapLayer* QgsServerProjectParser::mapLayerFromLayerId( const QString& lId, bool useCache ) const
{
QHash< QString, QDomElement >::const_iterator layerIt = mProjectLayerElementsById.find( lId );
if ( layerIt != mProjectLayerElementsById.constEnd() )
{
return createLayerFromElement( layerIt.value(), useCache );
}
return 0;
}

QString QgsServerProjectParser::layerIdFromLegendLayer( const QDomElement& legendLayer ) const
{
if ( legendLayer.isNull() )
@@ -854,9 +864,9 @@ void QgsServerProjectParser::addLayerFromLegendLayer( const QDomElement& legendL
QHash< QString, QDomElement >::const_iterator layerIt = mProjectLayerElementsById.find( id );
if ( layerIt != mProjectLayerElementsById.constEnd() )
{
//todo: fixme
/*addJoinLayersForElement( layerIt.value(), useCache );
addValueRelationLayersForElement( layerIt.value(), useCache );*/

addJoinLayersForElement( layerIt.value(), useCache );
addValueRelationLayersForElement( layerIt.value(), useCache );
QgsMapLayer* layer = createLayerFromElement( layerIt.value(), useCache );
if ( layer )
{
@@ -1060,3 +1070,57 @@ QStringList QgsServerProjectParser::wfsLayers() const
}
return wfsList;
}

void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerElem, bool useCache ) const
{
QDomElement vectorJoinsElem = layerElem.firstChildElement( "vectorjoins" );
if ( vectorJoinsElem.isNull() )
{
return;
}

QDomNodeList joinNodeList = vectorJoinsElem.elementsByTagName( "join" );
if ( joinNodeList.size() > 1 )
{
return;
}

for ( int i = 0; i < joinNodeList.size(); ++i )
{
QString id = joinNodeList.at( i ).toElement().attribute( "joinLayerId" );
QgsMapLayer* layer = mapLayerFromLayerId( id, useCache );
if ( layer )
{
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
}
}
}

void QgsServerProjectParser::addValueRelationLayersForElement( const QDomElement& layerElem, bool useCache ) const
{
QDomElement editTypesElem = layerElem.firstChildElement( "edittypes" );
if ( editTypesElem.isNull() )
{
return;
}

QDomNodeList editTypeNodeList = editTypesElem.elementsByTagName( "edittype" );
for ( int i = 0; i < editTypeNodeList.size(); ++i )
{
QDomElement editTypeElem = editTypeNodeList.at( i ).toElement();
int type = editTypeElem.attribute( "type" ).toInt();
if ( type == QgsVectorLayer::ValueRelation )
{
QString layerId = editTypeElem.attribute( "layer" );
/*QString keyAttribute = editTypeEleml.attribute( "id" ); //relation attribute in other layer
QString valueAttribute = editTypeElem.attribute( "value" ); //value attribute in other layer
QString relationAttribute = editTypeElem.attribute( "name" );*/

QgsMapLayer* layer = mapLayerFromLayerId( layerId, useCache );
if ( layer )
{
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
}
}
}
}
@@ -50,6 +50,8 @@ class QgsServerProjectParser
@return the maplayer or 0 in case of error*/
QgsMapLayer* createLayerFromElement( const QDomElement& elem, bool useCache = true ) const;

QgsMapLayer* mapLayerFromLayerId( const QString& lId, bool useCache = true ) const;

/**Returns the layer id under a <legendlayer> tag in the QGIS projectfile*/
QString layerIdFromLegendLayer( const QDomElement& legendLayer ) const;

@@ -105,6 +107,10 @@ class QgsServerProjectParser

QStringList wfsLayers() const;

void addJoinLayersForElement( const QDomElement& layerElem, bool useCache = true ) const;

void addValueRelationLayersForElement( const QDomElement& layerElem, bool useCache = true ) const;

private:

/**Content of project file*/
@@ -172,7 +172,7 @@ void QgsWFSProjectParser::featureTypeList( QDomElement& parentElement, QDomDocum
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
//addJoinLayersForElement( elem ); //todo: fixme
mProjectParser.addJoinLayersForElement( elem );
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
if ( layer && wfsLayersId.contains( layer->id() ) )
{
@@ -421,7 +421,7 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
//addJoinLayersForElement( elem ); //todo: fixme
mProjectParser.addJoinLayersForElement( elem );
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
@@ -580,7 +580,7 @@ QList<QgsMapLayer*> QgsWFSProjectParser::mapLayerFromTypeName( const QString& aT
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
//addJoinLayersForElement( elem, useCache ); //todo: fixme
mProjectParser.addJoinLayersForElement( elem, useCache );
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem );
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
@@ -101,11 +101,8 @@ QList<QgsMapLayer*> QgsWMSProjectParser::mapLayerFromStyle( const QString& lName
QHash< QString, QDomElement >::const_iterator layerElemIt = projectLayerElementsByName.find( lName );
if ( layerElemIt != projectLayerElementsByName.constEnd() )
{
//todo: fixme
/*
addJoinLayersForElement( layerElemIt.value(), useCache );
addValueRelationLayersForElement( layerElemIt.value(), useCache );
*/
mProjectParser.addJoinLayersForElement( layerElemIt.value(), useCache );
mProjectParser.addValueRelationLayersForElement( layerElemIt.value(), useCache );
QgsMapLayer* layer = mProjectParser.createLayerFromElement( layerElemIt.value(), useCache );
if ( layer )
{

0 comments on commit 3df34a8

Please sign in to comment.