@@ -152,7 +152,6 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
152
152
}
153
153
154
154
addJoinLayersForElement ( elem );
155
- addValueRelationLayersForElement ( elem );
156
155
addGetFeatureLayers ( elem );
157
156
158
157
QDomElement dataSourceElem = elem.firstChildElement ( " datasource" );
@@ -250,6 +249,12 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
250
249
251
250
layer->readLayerXML ( const_cast <QDomElement&>( elem ) ); // should be changed to const in QgsMapLayer
252
251
layer->setLayerName ( layerName ( elem ) );
252
+
253
+ if ( layer->type () == QgsMapLayer::VectorLayer )
254
+ {
255
+ addValueRelationLayersForLayer ( dynamic_cast <QgsVectorLayer *>( layer ) );
256
+ }
257
+
253
258
if ( useCache )
254
259
{
255
260
QgsMSLayerCache::instance ()->insertLayer ( absoluteUri, id, layer, mProjectPath );
@@ -1357,34 +1362,29 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
1357
1362
}
1358
1363
}
1359
1364
1360
- void QgsServerProjectParser::addValueRelationLayersForElement ( const QDomElement& layerElem ) const
1365
+ void QgsServerProjectParser::addValueRelationLayersForLayer ( const QgsVectorLayer *vl ) const
1361
1366
{
1362
- QDomElement editTypesElem = layerElem.firstChildElement ( " edittypes" );
1363
- if ( editTypesElem.isNull () )
1364
- {
1367
+ if ( !vl )
1365
1368
return ;
1366
- }
1367
1369
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++ )
1370
1371
{
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 ;
1381
1374
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 );
1388
1388
}
1389
1389
}
1390
1390
0 commit comments