Skip to content

Commit 0954a20

Browse files
committedFeb 17, 2015
server: also load layers referenced in value relations (followup ceceebd)
1 parent 70a0a6e commit 0954a20

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed
 

‎src/server/qgsserverprojectparser.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
152152
}
153153

154154
addJoinLayersForElement( elem );
155-
addValueRelationLayersForElement( elem );
156155
addGetFeatureLayers( elem );
157156

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

251250
layer->readLayerXML( const_cast<QDomElement&>( elem ) ); //should be changed to const in QgsMapLayer
252251
layer->setLayerName( layerName( elem ) );
252+
253+
if ( layer->type() == QgsMapLayer::VectorLayer )
254+
{
255+
addValueRelationLayersForLayer( dynamic_cast<QgsVectorLayer *>( layer ) );
256+
}
257+
253258
if ( useCache )
254259
{
255260
QgsMSLayerCache::instance()->insertLayer( absoluteUri, id, layer, mProjectPath );
@@ -1357,34 +1362,29 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
13571362
}
13581363
}
13591364

1360-
void QgsServerProjectParser::addValueRelationLayersForElement( const QDomElement& layerElem ) const
1365+
void QgsServerProjectParser::addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const
13611366
{
1362-
QDomElement editTypesElem = layerElem.firstChildElement( "edittypes" );
1363-
if ( editTypesElem.isNull() )
1364-
{
1367+
if ( !vl )
13651368
return;
1366-
}
13671369

1368-
QDomNodeList editTypeNodeList = editTypesElem.elementsByTagName( "edittype" );
1369-
for ( int i = 0; i < editTypeNodeList.size(); ++i )
1370+
for ( int idx = 0; idx < vl->pendingFields().size(); idx++ )
13701371
{
1371-
QDomElement editTypeElem = editTypeNodeList.at( i ).toElement();
1372-
int type = editTypeElem.attribute( "type" ).toInt();
1373-
if ( type == QgsVectorLayer::ValueRelation )
1374-
{
1375-
QString layerId = editTypeElem.attribute( "layer" );
1376-
#if 0
1377-
QString keyAttribute = editTypeEleml.attribute( "id" ); //relation attribute in other layer
1378-
QString valueAttribute = editTypeElem.attribute( "value" ); //value attribute in other layer
1379-
QString relationAttribute = editTypeElem.attribute( "name" );
1380-
#endif
1372+
if ( vl->editorWidgetV2( idx ) != "ValueRelation" )
1373+
continue;
13811374

1382-
QgsMapLayer* layer = mapLayerFromLayerId( layerId );
1383-
if ( layer )
1384-
{
1385-
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
1386-
}
1387-
}
1375+
QgsEditorWidgetConfig cfg( vl->editorWidgetV2Config( idx ) );
1376+
if ( !cfg.contains( "Layer" ) )
1377+
continue;
1378+
1379+
QString layerId = cfg.value( "Layer" ).toString();
1380+
if ( QgsMapLayerRegistry::instance()->mapLayer( layerId ) )
1381+
continue;
1382+
1383+
QgsMapLayer *layer = mapLayerFromLayerId( layerId );
1384+
if ( !layer )
1385+
continue;
1386+
1387+
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
13881388
}
13891389
}
13901390

‎src/server/qgsserverprojectparser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class QgsServerProjectParser
110110

111111
void addJoinLayersForElement( const QDomElement& layerElem ) const;
112112

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

0 commit comments

Comments
 (0)
Please sign in to comment.