Skip to content

Commit 21cfb7d

Browse files
committed
Last Redo [BUGFIX][QGIS Server] Joins was not reloaded if the layer is in cache
Add an accessor to QgsVectorLayer join buffer, to not duplicate QgsVectorLayerJoinBuffer::readXml code
1 parent 15fe635 commit 21cfb7d

File tree

4 files changed

+13
-47
lines changed

4 files changed

+13
-47
lines changed

python/core/qgsvectorlayer.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ class QgsVectorLayer : QgsMapLayer
232232
@returns true if join was found and successfully removed */
233233
bool removeJoin( const QString& joinLayerId );
234234

235+
/**
236+
* Acccessor to the join buffer object
237+
* @note added 2.14.7
238+
*/
239+
QgsVectorLayerJoinBuffer* joinBuffer();
235240
const QList<QgsVectorJoinInfo> vectorJoins() const;
236241

237242
/**

src/core/qgsvectorlayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
597597
@returns true if join was found and successfully removed */
598598
bool removeJoin( const QString& joinLayerId );
599599

600+
/**
601+
* Acccessor to the join buffer object
602+
* @note added 2.14.7
603+
*/
604+
QgsVectorLayerJoinBuffer* joinBuffer() { return mJoinBuffer; }
600605
const QList<QgsVectorJoinInfo> vectorJoins() const;
601606

602607
/**

src/server/qgsserverprojectparser.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsmaplayerregistry.h"
2626
#include "qgsmslayercache.h"
2727
#include "qgsrasterlayer.h"
28+
#include "qgsvectorlayerjoinbuffer.h"
2829
#include "qgseditorwidgetregistry.h"
2930
#include "qgslayertreegroup.h"
3031

@@ -237,7 +238,8 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
237238
{
238239
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
239240
addValueRelationLayersForLayer( vlayer );
240-
addJoinsToLayer( const_cast<QDomElement&>( elem ), vlayer );
241+
QgsVectorLayerJoinBuffer* joinBuffer = vlayer->joinBuffer();
242+
joinBuffer->readXml( const_cast<QDomElement&>( elem ) );
241243
}
242244

243245
return layer;
@@ -1546,50 +1548,6 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
15461548
}
15471549
}
15481550

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-
15931551
void QgsServerProjectParser::addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const
15941552
{
15951553
if ( !vl )

src/server/qgsserverprojectparser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ class SERVER_EXPORT QgsServerProjectParser
113113

114114
/** Add layers for vector joins */
115115
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;
118116

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

0 commit comments

Comments
 (0)