Skip to content
Permalink
Browse files

server: also load layers referenced in value relations (followup ceceebd

)
  • Loading branch information
jef-n committed Feb 17, 2015
1 parent 70a0a6e commit 0954a20373519deaa1f1e251d9c20bb2667bfaa6
Showing with 25 additions and 25 deletions.
  1. +24 −24 src/server/qgsserverprojectparser.cpp
  2. +1 −1 src/server/qgsserverprojectparser.h
@@ -152,7 +152,6 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
}

addJoinLayersForElement( elem );
addValueRelationLayersForElement( elem );
addGetFeatureLayers( elem );

QDomElement dataSourceElem = elem.firstChildElement( "datasource" );
@@ -250,6 +249,12 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&

layer->readLayerXML( const_cast<QDomElement&>( elem ) ); //should be changed to const in QgsMapLayer
layer->setLayerName( layerName( elem ) );

if ( layer->type() == QgsMapLayer::VectorLayer )
{
addValueRelationLayersForLayer( dynamic_cast<QgsVectorLayer *>( layer ) );
}

if ( useCache )
{
QgsMSLayerCache::instance()->insertLayer( absoluteUri, id, layer, mProjectPath );
@@ -1357,34 +1362,29 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
}
}

void QgsServerProjectParser::addValueRelationLayersForElement( const QDomElement& layerElem ) const
void QgsServerProjectParser::addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const
{
QDomElement editTypesElem = layerElem.firstChildElement( "edittypes" );
if ( editTypesElem.isNull() )
{
if ( !vl )
return;
}

QDomNodeList editTypeNodeList = editTypesElem.elementsByTagName( "edittype" );
for ( int i = 0; i < editTypeNodeList.size(); ++i )
for ( int idx = 0; idx < vl->pendingFields().size(); idx++ )
{
QDomElement editTypeElem = editTypeNodeList.at( i ).toElement();
int type = editTypeElem.attribute( "type" ).toInt();
if ( type == QgsVectorLayer::ValueRelation )
{
QString layerId = editTypeElem.attribute( "layer" );
#if 0
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" );
#endif
if ( vl->editorWidgetV2( idx ) != "ValueRelation" )
continue;

QgsMapLayer* layer = mapLayerFromLayerId( layerId );
if ( layer )
{
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
}
}
QgsEditorWidgetConfig cfg( vl->editorWidgetV2Config( idx ) );
if ( !cfg.contains( "Layer" ) )
continue;

QString layerId = cfg.value( "Layer" ).toString();
if ( QgsMapLayerRegistry::instance()->mapLayer( layerId ) )
continue;

QgsMapLayer *layer = mapLayerFromLayerId( layerId );
if ( !layer )
continue;

QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
}
}

@@ -110,7 +110,7 @@ class QgsServerProjectParser

void addJoinLayersForElement( const QDomElement& layerElem ) const;

void addValueRelationLayersForElement( const QDomElement& layerElem ) const;
void addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const;
/**Add layers which are necessary for the evaluation of the expression function 'getFeature( layer, attributField, value)'*/
void addGetFeatureLayers( const QDomElement& layerElem ) const;

0 comments on commit 0954a20

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