From e28fb7f7d4c196fa6ad4dbc1481a37d981be2e50 Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Thu, 14 Jan 2021 08:58:50 +0100 Subject: [PATCH] Consider tab layout for wms feature info --- src/server/services/wms/qgswmsrenderer.cpp | 56 ++++++++++++++++++++-- src/server/services/wms/qgswmsrenderer.h | 7 +++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/server/services/wms/qgswmsrenderer.cpp b/src/server/services/wms/qgswmsrenderer.cpp index 3345374abf8..b749b8d7fd6 100644 --- a/src/server/services/wms/qgswmsrenderer.cpp +++ b/src/server/services/wms/qgswmsrenderer.cpp @@ -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( group ); + if ( container ) + { + QString groupName = container->name(); + QDomElement nameElem; + + if ( !groupName.isEmpty() ) + { + nameElem = doc.createElement( groupName ); + parentElem.appendChild( nameElem ); + } + + QList 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( 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 { diff --git a/src/server/services/wms/qgswmsrenderer.h b/src/server/services/wms/qgswmsrenderer.h index 4808b9940ec..571989edc1d 100644 --- a/src/server/services/wms/qgswmsrenderer.h +++ b/src/server/services/wms/qgswmsrenderer.h @@ -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