Skip to content

Commit

Permalink
Re-enable vector joins and value relations
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 4, 2014
1 parent 3bd2537 commit 3df34a8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 14 deletions.
76 changes: 70 additions & 6 deletions src/mapserver/qgsserverprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "qgsconfigparserutils.h"
#include "qgscrscache.h"
#include "qgsdatasourceuri.h"
#include "qgsmaplayerregistry.h"
#include "qgsmslayercache.h"
#include "qgsrasterlayer.h"

Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
}
}
}
}
6 changes: 6 additions & 0 deletions src/mapserver/qgsserverprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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*/
Expand Down
6 changes: 3 additions & 3 deletions src/mapserver/qgswfsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) )
{
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
7 changes: 2 additions & 5 deletions src/mapserver/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down

0 comments on commit 3df34a8

Please sign in to comment.