Skip to content

Commit

Permalink
getPrint uses the style define in the maptheme
Browse files Browse the repository at this point in the history
  • Loading branch information
speillet committed Jun 30, 2021
1 parent f24bd45 commit 3119c4c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -33,6 +33,7 @@
#include "qgslegendrenderer.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerlegend.h"
#include "qgsmapthemecollection.h"
#include "qgsmaptopixel.h"
#include "qgsproject.h"
#include "qgsrasteridentifyresult.h"
Expand Down Expand Up @@ -695,15 +696,27 @@ namespace QgsWms
// If the map is set to follow preset we need to disable follow preset and manually
// configure the layers here or the map item internal logic will override and get
// the layers from the map theme.
QMap<QString, QString> layersStyle;
if ( map->followVisibilityPreset() )
{
QString presetName = map->followVisibilityPresetName();
if ( layerSet.isEmpty() )
{
// Get the layers from the theme
const QgsExpressionContext ex { map->createExpressionContext() };
layerSet = map->layersToRender( &ex );
}
map->setFollowVisibilityPreset( false );
QList<QgsMapThemeCollection::MapThemeLayerRecord> mapThemeRecords = QgsProject::instance()->mapThemeCollection()->mapThemeState( presetName ).layerRecords();
for ( auto layerMapThemeRecord : mapThemeRecords )
{
if ( layerSet.contains( layerMapThemeRecord.layer() ) )
{
QString styleName = layerMapThemeRecord.currentStyle;
layersStyle.insert( layerMapThemeRecord.layer()->id(),
layerMapThemeRecord.layer()->styleManager()->style( layerMapThemeRecord.currentStyle ).xmlData() );
}
}
}

// Handle highlight layers
Expand All @@ -715,6 +728,11 @@ namespace QgsWms

map->setLayers( layerSet );
map->setKeepLayerSet( true );
if ( !layersStyle.isEmpty() )
{
map->setLayerStyleOverrides( layersStyle );
map->setKeepLayerStyles( true );
}
}

//grid space x / y
Expand Down

0 comments on commit 3119c4c

Please sign in to comment.