Skip to content

Commit

Permalink
Set project expression variables in server
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Nov 18, 2016
1 parent 520a137 commit 5514427
Show file tree
Hide file tree
Showing 3 changed files with 54 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
10 changes: 10 additions & 0 deletions src/server/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 5514427

Please sign in to comment.