Skip to content
Permalink
Browse files

Set project expression variables in server

  • Loading branch information
mhugent committed Nov 18, 2016
1 parent 520a137 commit 551442742b6d859bf839dc1b02860a18b7fcbfbf
Showing with 54 additions and 0 deletions.
  1. +41 −0 src/server/qgsserverprojectparser.cpp
  2. +3 −0 src/server/qgsserverprojectparser.h
  3. +10 −0 src/server/qgswmsserver.cpp
@@ -80,6 +80,17 @@ QgsServerProjectParser::QgsServerProjectParser( QDomDocument* xmlDoc, const QStr
{
QgsProject::instance()->setFileName( mProjectPath );
}

// Set the project scope variables
QStringList variableNames = readListEntry( "Variables", "variableNames" );
QStringList variableValues = readListEntry( "Variables", "variableValues" );

//read values

//append standard values

QgsProject::instance()->writeEntry( "Variables", "/variableNames", variableNames );
QgsProject::instance()->writeEntry( "Variables", "/variableValues", variableValues );
}

QgsServerProjectParser::QgsServerProjectParser()
@@ -1612,4 +1623,34 @@ void QgsServerProjectParser::addGetFeatureLayers( const QDomElement& layerElem )
}
}

QStringList QgsServerProjectParser::readListEntry( const QString& scope, const QString& key ) const
{
QStringList entryList;
QDomElement propertiesElement = propertiesElem();
if ( propertiesElement.isNull() )
{
return entryList;
}

QDomElement scopeElem = propertiesElement.firstChildElement( scope );
if ( scopeElem.isNull() )
{
return entryList;
}

QDomElement keyElem = scopeElem.firstChildElement( key );
if ( keyElem.isNull() )
{
return entryList;
}

QDomNodeList valueNodeList = keyElem.elementsByTagName( "value" );
for ( int i = 0; i < valueNodeList.size(); ++i )
{
entryList.append( valueNodeList.at( i ).toElement().text() );
}

return entryList;
}


@@ -175,6 +175,9 @@ class SERVER_EXPORT QgsServerProjectParser

/** Adds sublayers of an embedded group to layer set*/
static void sublayersOfEmbeddedGroup( const QString& projectFilePath, const QString& groupName, QSet<QString>& layerSet );

/** Reads list entry from project properties*/
QStringList readListEntry( const QString& scope, const QString& key ) const;
};

#endif // QGSSERVERPROJECTPARSER_H
@@ -2079,6 +2079,16 @@ int QgsWMSServer::configureMapRender( const QPaintDevice* paintDevice ) const
mMapRenderer->setOutputUnits( QgsMapRenderer::Pixels ); //SLD units are in pixels normally
}

//Clear expression context and set project variables
QgsRenderContext* ctx = mMapRenderer->rendererContext();
if ( ctx )
{
QgsExpressionContext newContext;
ctx->setExpressionContext( newContext );
QgsExpressionContext& expCtx = ctx->expressionContext();
expCtx.appendScope( QgsExpressionContextUtils::projectScope() );
}

return 0;
}

0 comments on commit 5514427

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