Skip to content

Commit

Permalink
Merge pull request #3781 from mhugent/wms_project_variables
Browse files Browse the repository at this point in the history
Set project expression variables in server
  • Loading branch information
mhugent authored Nov 18, 2016
2 parents 520a137 + 4cc85fd commit 339986d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/server/qgsserverprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}


3 changes: 3 additions & 0 deletions src/server/qgsserverprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/server/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,15 @@ 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;
newContext.appendScope( QgsExpressionContextUtils::projectScope() );
ctx->setExpressionContext( newContext );
}

return 0;
}

Expand Down

0 comments on commit 339986d

Please sign in to comment.