Skip to content

Commit

Permalink
Move code to write feature info XML attribute to function
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jan 15, 2021
1 parent 79572de commit 65691dc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
63 changes: 36 additions & 27 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -1568,33 +1568,7 @@ namespace QgsWms
featureAttributes = feature.attributes();
for ( int i = 0; i < featureAttributes.count(); ++i )
{
//skip attribute if it is explicitly excluded from WMS publication
if ( fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
{
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
//skip attribute if it is excluded by access control
if ( !attributes.contains( fields.at( i ).name() ) )
{
continue;
}
#endif

//replace attribute name if there is an attribute alias?
QString attributeName = layer->attributeDisplayName( i );

QDomElement attributeElement = infoDocument.createElement( QStringLiteral( "Attribute" ) );
attributeElement.setAttribute( QStringLiteral( "name" ), attributeName );
const QgsEditorWidgetSetup setup = layer->editorWidgetSetup( i );
attributeElement.setAttribute( QStringLiteral( "value" ),
QgsExpression::replaceExpressionText(
replaceValueMapAndRelation(
layer, i,
featureAttributes[i] ),
&renderContext.expressionContext() )
);
featureElement.appendChild( attributeElement );
writeVectorLayerAttribute( i, layer, fields, featureAttributes, infoDocument, featureElement, renderContext );
}

//add maptip attribute based on html/expression (in case there is no maptip attribute)
Expand Down Expand Up @@ -1662,6 +1636,41 @@ namespace QgsWms
return true;
}


void QgsRenderer::writeVectorLayerAttribute( int attributeIndex, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext ) const
{
if ( !layer )
{
return;
}

//skip attribute if it is explicitly excluded from WMS publication
if ( fields.at( attributeIndex ).configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
{
return;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
//skip attribute if it is excluded by access control
if ( !attributes.contains( fields.at( i ).name() ) )
{
return;
}
#endif

QString attributeName = layer->attributeDisplayName( attributeIndex );
QDomElement attributeElement = doc.createElement( QStringLiteral( "Attribute" ) );
attributeElement.setAttribute( QStringLiteral( "name" ), attributeName );
const QgsEditorWidgetSetup setup = layer->editorWidgetSetup( attributeIndex );
attributeElement.setAttribute( QStringLiteral( "value" ),
QgsExpression::replaceExpressionText(
replaceValueMapAndRelation(
layer, attributeIndex,
featureAttributes[attributeIndex] ),
&renderContext.expressionContext() )
);
featureElem.appendChild( attributeElement );
}

bool QgsRenderer::featureInfoFromRasterLayer( QgsRasterLayer *layer,
const QgsMapSettings &mapSettings,
const QgsPointXY *infoPoint,
Expand Down
2 changes: 2 additions & 0 deletions src/server/services/wms/qgswmsrenderer.h
Expand Up @@ -221,6 +221,8 @@ namespace QgsWms
QgsRectangle *featureBBox = nullptr,
QgsGeometry *filterGeom = nullptr ) const;

void writeVectorLayerAttribute( int attributeIndex, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext ) const;

//! Appends feature info xml for the layer to the layer element of the dom document
bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
const QgsMapSettings &mapSettings,
Expand Down

0 comments on commit 65691dc

Please sign in to comment.