Consider tab layout for wms feature info

This commit is contained in:
Marco Hugentobler 2021-01-14 08:58:50 +01:00
parent 65691dcc2c
commit e28fb7f7d4
2 changed files with 60 additions and 3 deletions

View File

@ -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)
@ -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
{

View File

@ -50,6 +50,8 @@ class QImage;
class QPaintDevice;
class QPainter;
class QgsLayerTreeGroup;
class QgsEditFormConfig;
class QgsAttributeEditorElement;
namespace QgsWms
{
@ -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