Skip to content

Commit d5328f6

Browse files
committed
Redo [BUGFIX][QGIS Server] Joins was not reloaded if the layer is in cache
With the commit f6aad8b, the QgsMapLayerRegistry signal `layersWillBeRemoved` is always emit. This imply that the vector layer join buffer is empty and not reloaded if the layer is in cache. To fix it, the QgsServerProjectParser has to have the same method as QgsVectorLayerJoinBuffer::readXml. This commit fixed #15522 Qgis Server doesnt' respect the styling from Desktop
1 parent 89dd263 commit d5328f6

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/server/qgsserverprojectparser.cpp

+50-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
234234
if ( !QgsMapLayerRegistry::instance()->mapLayer( id ) )
235235
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
236236
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+
}
238242

239243
return layer;
240244
}
@@ -1535,13 +1539,57 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
15351539
{
15361540
QString id = joinNodeList.at( i ).toElement().attribute( "joinLayerId" );
15371541
QgsMapLayer* layer = mapLayerFromLayerId( id );
1538-
if ( layer )
1542+
if ( layer && !QgsMapLayerRegistry::instance()->mapLayer( id ) )
15391543
{
15401544
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false );
15411545
}
15421546
}
15431547
}
15441548

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+
15451593
void QgsServerProjectParser::addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const
15461594
{
15471595
if ( !vl )

src/server/qgsserverprojectparser.h

+3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class SERVER_EXPORT QgsServerProjectParser
111111
QStringList wfsLayers() const;
112112
QStringList wcsLayers() const;
113113

114+
/** Add layers for vector joins */
114115
void addJoinLayersForElement( const QDomElement& layerElem ) const;
116+
/** Update vector joins to layer, based on QgsVectorLayerJoinBuffer::readXml */
117+
void addJoinsToLayer( const QDomElement& layerElem, QgsVectorLayer *vl ) const;
115118

116119
void addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const;
117120
/** Add layers which are necessary for the evaluation of the expression function 'getFeature( layer, attributField, value)'*/

0 commit comments

Comments
 (0)