Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Set project expression variables in server
  • Loading branch information
mhugent committed Feb 27, 2018
1 parent 9a3ecc2 commit b385f42
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
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 @@ -1633,4 +1644,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
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
Expand Up @@ -2193,6 +2193,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 b385f42

Please sign in to comment.