Skip to content

Commit

Permalink
Last Redo [BUGFIX][QGIS Server] Joins was not reloaded if the layer i…
Browse files Browse the repository at this point in the history
…s in cache

Add an accessor to QgsVectorLayer join buffer, to not duplicate QgsVectorLayerJoinBuffer::readXml code
  • Loading branch information
rldhont committed Oct 12, 2016
1 parent 15fe635 commit 21cfb7d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 47 deletions.
5 changes: 5 additions & 0 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ class QgsVectorLayer : QgsMapLayer
@returns true if join was found and successfully removed */
bool removeJoin( const QString& joinLayerId );

/**
* Acccessor to the join buffer object
* @note added 2.14.7
*/
QgsVectorLayerJoinBuffer* joinBuffer();
const QList<QgsVectorJoinInfo> vectorJoins() const;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
@returns true if join was found and successfully removed */
bool removeJoin( const QString& joinLayerId );

/**
* Acccessor to the join buffer object
* @note added 2.14.7
*/
QgsVectorLayerJoinBuffer* joinBuffer() { return mJoinBuffer; }
const QList<QgsVectorJoinInfo> vectorJoins() const;

/**
Expand Down
48 changes: 3 additions & 45 deletions src/server/qgsserverprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsmslayercache.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgseditorwidgetregistry.h"
#include "qgslayertreegroup.h"

Expand Down Expand Up @@ -237,7 +238,8 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );
addValueRelationLayersForLayer( vlayer );
addJoinsToLayer( const_cast<QDomElement&>( elem ), vlayer );
QgsVectorLayerJoinBuffer* joinBuffer = vlayer->joinBuffer();
joinBuffer->readXml( const_cast<QDomElement&>( elem ) );
}

return layer;
Expand Down Expand Up @@ -1546,50 +1548,6 @@ void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerEl
}
}

// Based on QgsVectorLayerJoinBuffer::readXml
void QgsServerProjectParser::addJoinsToLayer( const QDomElement& layerElem, QgsVectorLayer *vl ) const
{
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 )
Expand Down
2 changes: 0 additions & 2 deletions src/server/qgsserverprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ class SERVER_EXPORT QgsServerProjectParser

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

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

0 comments on commit 21cfb7d

Please sign in to comment.