Skip to content
Permalink
Browse files

Server: fix loading of dependent layers when using the getFeature() f…

…unction (ticket #12090)
  • Loading branch information
mhugent committed Feb 10, 2015
1 parent db17513 commit 27bf440eace80c4f56c0f191706dfe1b046bcc96
Showing with 40 additions and 0 deletions.
  1. +38 −0 src/server/qgsserverprojectparser.cpp
  2. +2 −0 src/server/qgsserverprojectparser.h
@@ -28,6 +28,7 @@
#include <QDomDocument>
#include <QFileInfo>
#include <QStringList>
#include <QTextStream>
#include <QUrl>

QgsServerProjectParser::QgsServerProjectParser( QDomDocument* xmlDoc, const QString& filePath )
@@ -151,6 +152,7 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&

addJoinLayersForElement( elem, useCache );
addValueRelationLayersForElement( elem, useCache );
addGetFeatureLayers( elem, useCache );

QDomElement dataSourceElem = elem.firstChildElement( "datasource" );
QString uri = dataSourceElem.text();
@@ -1422,3 +1424,39 @@ void QgsServerProjectParser::addValueRelationLayersForElement( const QDomElement
}
}
}

void QgsServerProjectParser::addGetFeatureLayers( const QDomElement& layerElem, bool useCache ) const
{
QString str;
QTextStream stream( &str );
layerElem.save( stream, 2 );

QRegExp rx( "getFeature\\('([^']*)'" );
int idx = 0;
while (( idx = rx.indexIn( str, idx ) ) != -1 )
{
QString name = rx.cap( 1 );
QgsMapLayer* ml = 0;
QHash< QString, QDomElement >::const_iterator layerElemIt = mProjectLayerElementsById.find( name );
if ( layerElemIt != mProjectLayerElementsById.constEnd() )
{
ml = createLayerFromElement( layerElemIt.value() );

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Feb 11, 2015

Contributor

@mhugent should this (and 1450) be passed "useCache" too?

This comment has been minimized.

Copy link
@mhugent

mhugent Feb 12, 2015

Author Contributor

It is not necessary. We can even take away the useCache parameter from addJoinLayersForElement() and addValueRelationLayersForElement too.

}
else
{
layerElemIt = mProjectLayerElementsByName.find( name );
if ( layerElemIt != mProjectLayerElementsByName.constEnd() )
{
ml = createLayerFromElement( layerElemIt.value() );
}
}

if ( ml )
{
QgsMapLayerRegistry::instance()->addMapLayer( ml, false, false );
}
idx += rx.matchedLength();
}
}


@@ -113,6 +113,8 @@ class QgsServerProjectParser
void addJoinLayersForElement( const QDomElement& layerElem, bool useCache = true ) const;

void addValueRelationLayersForElement( const QDomElement& layerElem, bool useCache = true ) const;
/**Add layers which are necessary for the evaluation of the expression function 'getFeature( layer, attributField, value)'*/
void addGetFeatureLayers( const QDomElement& layerElem, bool useCache = true ) const;

/**Returns the text of the <id> element for a layer element
@return id or a null string in case of error*/

0 comments on commit 27bf440

Please sign in to comment.
You can’t perform that action at this time.