@@ -234,7 +234,11 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
234
234
if ( !QgsMapLayerRegistry::instance ()->mapLayer ( id ) )
235
235
QgsMapLayerRegistry::instance ()->addMapLayer ( layer, false , false );
236
236
if ( layer->type () == QgsMapLayer::VectorLayer )
237
- addValueRelationLayersForLayer ( dynamic_cast <QgsVectorLayer *>( layer ) );
237
+ {
238
+ QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
239
+ addValueRelationLayersForLayer ( vlayer );
240
+ addJoinsToLayer ( const_cast <QDomElement&>( elem ), vlayer );
241
+ }
238
242
239
243
return layer;
240
244
}
@@ -1535,13 +1539,57 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
1535
1539
{
1536
1540
QString id = joinNodeList.at ( i ).toElement ().attribute ( " joinLayerId" );
1537
1541
QgsMapLayer* layer = mapLayerFromLayerId ( id );
1538
- if ( layer )
1542
+ if ( layer && ! QgsMapLayerRegistry::instance ()-> mapLayer ( id ) )
1539
1543
{
1540
1544
QgsMapLayerRegistry::instance ()->addMapLayer ( layer, false , false );
1541
1545
}
1542
1546
}
1543
1547
}
1544
1548
1549
+ // Based on QgsVectorLayerJoinBuffer::readXml
1550
+ void QgsServerProjectParser::addJoinsToLayer ( const QDomElement& layerElem, QgsVectorLayer *vl ) const
1551
+ {
1552
+ if ( !vl )
1553
+ return ;
1554
+
1555
+ QDomElement vectorJoinsElem = layerElem.firstChildElement ( " vectorjoins" );
1556
+ if ( vectorJoinsElem.isNull () )
1557
+ {
1558
+ return ;
1559
+ }
1560
+
1561
+ QDomNodeList joinList = vectorJoinsElem.elementsByTagName ( " join" );
1562
+ for ( int i = 0 ; i < joinList.size (); ++i )
1563
+ {
1564
+ QDomElement infoElem = joinList.at ( i ).toElement ();
1565
+ QgsVectorJoinInfo info;
1566
+ info.joinFieldName = infoElem.attribute ( " joinFieldName" );
1567
+ info.joinLayerId = infoElem.attribute ( " joinLayerId" );
1568
+ info.targetFieldName = infoElem.attribute ( " targetFieldName" );
1569
+ info.memoryCache = infoElem.attribute ( " memoryCache" ).toInt ();
1570
+
1571
+ info.joinFieldIndex = infoElem.attribute ( " joinField" ).toInt (); // for compatibility with 1.x
1572
+ info.targetFieldIndex = infoElem.attribute ( " targetField" ).toInt (); // for compatibility with 1.x
1573
+
1574
+ QDomElement subsetElem = infoElem.firstChildElement ( " joinFieldsSubset" );
1575
+ if ( !subsetElem.isNull () )
1576
+ {
1577
+ QStringList* fieldNames = new QStringList;
1578
+ QDomNodeList fieldNodes = infoElem.elementsByTagName ( " field" );
1579
+ for ( int i = 0 ; i < fieldNodes.count (); ++i )
1580
+ *fieldNames << fieldNodes.at ( i ).toElement ().attribute ( " name" );
1581
+ info.setJoinFieldNamesSubset ( fieldNames );
1582
+ }
1583
+
1584
+ if ( infoElem.attribute ( " hasCustomPrefix" ).toInt () )
1585
+ info.prefix = infoElem.attribute ( " customPrefix" );
1586
+ else
1587
+ info.prefix = QString::null;
1588
+
1589
+ vl->addJoin ( info );
1590
+ }
1591
+ }
1592
+
1545
1593
void QgsServerProjectParser::addValueRelationLayersForLayer ( const QgsVectorLayer *vl ) const
1546
1594
{
1547
1595
if ( !vl )
0 commit comments