Skip to content

Commit

Permalink
Consider tab layout for wms feature info
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jan 15, 2021
1 parent 65691dc commit e28fb7f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
56 changes: 53 additions & 3 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -1564,11 +1564,18 @@ namespace QgsWms
featureElement.setAttribute( QStringLiteral( "id" ), QgsServerFeatureId::getServerFid( feature, layer->dataProvider()->pkAttributeIndexes() ) );
layerElement.appendChild( featureElement );

//read all attribute values from the feature
featureAttributes = feature.attributes();
for ( int i = 0; i < featureAttributes.count(); ++i )
QgsEditFormConfig editConfig = layer->editFormConfig();
if ( editConfig.layout() == QgsEditFormConfig::TabLayout )
{
writeVectorLayerAttribute( i, layer, fields, featureAttributes, infoDocument, featureElement, renderContext );
writeAttributesTabLayout( editConfig, layer, fields, featureAttributes, infoDocument, featureElement, renderContext );
}
else
{
for ( int i = 0; i < featureAttributes.count(); ++i )
{
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 @@ -1636,6 +1643,49 @@ namespace QgsWms
return true;
}

void QgsRenderer::writeAttributesTabGroup( const QgsAttributeEditorElement *group, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &parentElem, QgsRenderContext &renderContext ) const
{
const QgsAttributeEditorContainer *container = dynamic_cast<const QgsAttributeEditorContainer *>( group );
if ( container )
{
QString groupName = container->name();
QDomElement nameElem;

if ( !groupName.isEmpty() )
{
nameElem = doc.createElement( groupName );
parentElem.appendChild( nameElem );
}

QList<QgsAttributeEditorElement *> children = container->children();
foreach ( const QgsAttributeEditorElement *child, children )
{
if ( child->type() == QgsAttributeEditorElement::AeTypeContainer )
{
writeAttributesTabGroup( child, layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext );
}
else if ( child->type() == QgsAttributeEditorElement::AeTypeField )
{
const QgsAttributeEditorField *editorField = dynamic_cast<const QgsAttributeEditorField *>( child );
if ( editorField )
{
writeVectorLayerAttribute( editorField->idx(), layer, fields, featureAttributes, doc, nameElem.isNull() ? parentElem : nameElem, renderContext );
}
}
}
}
}

void QgsRenderer::writeAttributesTabLayout( QgsEditFormConfig &config, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext ) const
{
QgsAttributeEditorContainer *editorContainer = config.invisibleRootContainer();
if ( !editorContainer )
{
return;
}

writeAttributesTabGroup( editorContainer, layer, fields, featureAttributes, doc, featureElem, renderContext );
}

void QgsRenderer::writeVectorLayerAttribute( int attributeIndex, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext ) const
{
Expand Down
7 changes: 7 additions & 0 deletions src/server/services/wms/qgswmsrenderer.h
Expand Up @@ -50,6 +50,8 @@ class QImage;
class QPaintDevice;
class QPainter;
class QgsLayerTreeGroup;
class QgsEditFormConfig;
class QgsAttributeEditorElement;

namespace QgsWms
{
Expand Down Expand Up @@ -221,6 +223,11 @@ namespace QgsWms
QgsRectangle *featureBBox = nullptr,
QgsGeometry *filterGeom = nullptr ) const;

//!Recursively called to write tab layout groups to XML
void writeAttributesTabGroup( const QgsAttributeEditorElement *group, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext ) const;
//!Writes attributes to XML document using the group/attribute layout defined in the tab layout
void writeAttributesTabLayout( QgsEditFormConfig &config, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext ) const;
//! Writes a vectorlayer attribute into the XML document
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
Expand Down

0 comments on commit e28fb7f

Please sign in to comment.