Skip to content

Commit 726bac5

Browse files
committedOct 12, 2016
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 898addf commit 726bac5

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
@@ -419,6 +419,11 @@ class QgsVectorLayer : QgsMapLayer
419419
@returns true if join was found and successfully removed */
420420
bool removeJoin( const QString& joinLayerId );
421421

422+
/**
423+
* Acccessor to the join buffer object
424+
* @note added 2.14.7
425+
*/
426+
QgsVectorLayerJoinBuffer* joinBuffer();
422427
const QList<QgsVectorJoinInfo> vectorJoins() const;
423428

424429
/**

‎src/core/qgsvectorlayer.h

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

515+
/**
516+
* Acccessor to the join buffer object
517+
* @note added 2.14.7
518+
*/
519+
QgsVectorLayerJoinBuffer* joinBuffer() { return mJoinBuffer; }
515520
const QList<QgsVectorJoinInfo> vectorJoins() const;
516521

517522
/**

‎src/server/qgsserverprojectparser.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgsmaplayerregistry.h"
2525
#include "qgsmslayercache.h"
2626
#include "qgsrasterlayer.h"
27+
#include "qgsvectorlayerjoinbuffer.h"
2728
#include "qgseditorwidgetregistry.h"
2829
#include "qgslayertreegroup.h"
2930
#include "qgslogger.h"
@@ -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;
@@ -1552,50 +1554,6 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
15521554
}
15531555
}
15541556

1555-
// Based on QgsVectorLayerJoinBuffer::readXml
1556-
void QgsServerProjectParser::addJoinsToLayer( const QDomElement& layerElem, QgsVectorLayer *vl ) const
1557-
{
1558-
if ( !vl )
1559-
return;
1560-
1561-
QDomElement vectorJoinsElem = layerElem.firstChildElement( "vectorjoins" );
1562-
if ( vectorJoinsElem.isNull() )
1563-
{
1564-
return;
1565-
}
1566-
1567-
QDomNodeList joinList = vectorJoinsElem.elementsByTagName( "join" );
1568-
for ( int i = 0; i < joinList.size(); ++i )
1569-
{
1570-
QDomElement infoElem = joinList.at( i ).toElement();
1571-
QgsVectorJoinInfo info;
1572-
info.joinFieldName = infoElem.attribute( "joinFieldName" );
1573-
info.joinLayerId = infoElem.attribute( "joinLayerId" );
1574-
info.targetFieldName = infoElem.attribute( "targetFieldName" );
1575-
info.memoryCache = infoElem.attribute( "memoryCache" ).toInt();
1576-
1577-
info.joinFieldIndex = infoElem.attribute( "joinField" ).toInt(); //for compatibility with 1.x
1578-
info.targetFieldIndex = infoElem.attribute( "targetField" ).toInt(); //for compatibility with 1.x
1579-
1580-
QDomElement subsetElem = infoElem.firstChildElement( "joinFieldsSubset" );
1581-
if ( !subsetElem.isNull() )
1582-
{
1583-
QStringList* fieldNames = new QStringList;
1584-
QDomNodeList fieldNodes = infoElem.elementsByTagName( "field" );
1585-
for ( int i = 0; i < fieldNodes.count(); ++i )
1586-
*fieldNames << fieldNodes.at( i ).toElement().attribute( "name" );
1587-
info.setJoinFieldNamesSubset( fieldNames );
1588-
}
1589-
1590-
if ( infoElem.attribute( "hasCustomPrefix" ).toInt() )
1591-
info.prefix = infoElem.attribute( "customPrefix" );
1592-
else
1593-
info.prefix = QString::null;
1594-
1595-
vl->addJoin( info );
1596-
}
1597-
}
1598-
15991557
void QgsServerProjectParser::addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const
16001558
{
16011559
if ( !vl )

‎src/server/qgsserverprojectparser.h

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

115115
/** Add layers for vector joins */
116116
void addJoinLayersForElement( const QDomElement& layerElem ) const;
117-
/** Update vector joins to layer, based on QgsVectorLayerJoinBuffer::readXml */
118-
void addJoinsToLayer( const QDomElement& layerElem, QgsVectorLayer *vl ) const;
119117

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

0 commit comments

Comments
 (0)
Please sign in to comment.