Commit
…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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,7 +234,11 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement& | |
if ( !QgsMapLayerRegistry::instance()->mapLayer( id ) ) | ||
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false ); | ||
if ( layer->type() == QgsMapLayer::VectorLayer ) | ||
addValueRelationLayersForLayer( dynamic_cast<QgsVectorLayer *>( layer ) ); | ||
{ | ||
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer ); | ||
addValueRelationLayersForLayer( vlayer ); | ||
addJoinsToLayer( const_cast<QDomElement&>( elem ), vlayer ); | ||
} | ||
|
||
return layer; | ||
} | ||
|
@@ -1541,13 +1545,57 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl | |
{ | ||
QString id = joinNodeList.at( i ).toElement().attribute( "joinLayerId" ); | ||
QgsMapLayer* layer = mapLayerFromLayerId( id ); | ||
if ( layer ) | ||
if ( layer && !QgsMapLayerRegistry::instance()->mapLayer( id ) ) | ||
{ | ||
QgsMapLayerRegistry::instance()->addMapLayer( layer, false, false ); | ||
} | ||
} | ||
} | ||
|
||
// Based on QgsVectorLayerJoinBuffer::readXml | ||
void QgsServerProjectParser::addJoinsToLayer( const QDomElement& layerElem, QgsVectorLayer *vl ) const | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rldhont
Author
Contributor
|
||
{ | ||
if ( !vl ) | ||
return; | ||
|
||
QDomElement vectorJoinsElem = layerElem.firstChildElement( "vectorjoins" ); | ||
if ( vectorJoinsElem.isNull() ) | ||
{ | ||
return; | ||
} | ||
|
||
QDomNodeList joinList = vectorJoinsElem.elementsByTagName( "join" ); | ||
for ( int i = 0; i < joinList.size(); ++i ) | ||
{ | ||
QDomElement infoElem = joinList.at( i ).toElement(); | ||
QgsVectorJoinInfo info; | ||
info.joinFieldName = infoElem.attribute( "joinFieldName" ); | ||
info.joinLayerId = infoElem.attribute( "joinLayerId" ); | ||
info.targetFieldName = infoElem.attribute( "targetFieldName" ); | ||
info.memoryCache = infoElem.attribute( "memoryCache" ).toInt(); | ||
|
||
info.joinFieldIndex = infoElem.attribute( "joinField" ).toInt(); //for compatibility with 1.x | ||
info.targetFieldIndex = infoElem.attribute( "targetField" ).toInt(); //for compatibility with 1.x | ||
|
||
QDomElement subsetElem = infoElem.firstChildElement( "joinFieldsSubset" ); | ||
if ( !subsetElem.isNull() ) | ||
{ | ||
QStringList* fieldNames = new QStringList; | ||
QDomNodeList fieldNodes = infoElem.elementsByTagName( "field" ); | ||
for ( int i = 0; i < fieldNodes.count(); ++i ) | ||
*fieldNames << fieldNodes.at( i ).toElement().attribute( "name" ); | ||
info.setJoinFieldNamesSubset( fieldNames ); | ||
} | ||
|
||
if ( infoElem.attribute( "hasCustomPrefix" ).toInt() ) | ||
info.prefix = infoElem.attribute( "customPrefix" ); | ||
else | ||
info.prefix = QString::null; | ||
|
||
vl->addJoin( info ); | ||
} | ||
} | ||
|
||
void QgsServerProjectParser::addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const | ||
{ | ||
if ( !vl ) | ||
|
Isn't it possible to refactor QgsVectorLayerJoinBuffer to avoid this duplication? It's things like this in server which has led to the current instability - people will update and change the format for the xml in QgsVectorLayerJoinBuffer::readXml without syncing the changes here.