Skip to content
Permalink
Browse files

Update getPrint with render context

  • Loading branch information
pblottiere committed Mar 25, 2019
1 parent 8a46e2f commit 24f3f97011b18e1bce1dc1c614f7f36da2b7c5b3
Showing with 35 additions and 69 deletions.
  1. +15 −4 src/server/services/wms/qgswmsgetprint.cpp
  2. +20 −65 src/server/services/wms/qgswmsrenderer.cpp
@@ -28,13 +28,12 @@ namespace QgsWms
const QString &, const QgsServerRequest &request,
QgsServerResponse &response )
{
// get wms parameters from query
const QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
QgsRenderer renderer( serverIface, project, wmsParameters );

// GetPrint supports svg/png/pdf
const QgsWmsParameters::Format format = wmsParameters.format();
QString contentType;

// GetPrint supports svg/png/pdf
switch ( format )
{
case QgsWmsParameters::PNG:
@@ -55,8 +54,20 @@ namespace QgsWms
break;
}

// prepare render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UpdateExtent );
context.setFlag( QgsWmsRenderContext::UseOpacity );
context.setFlag( QgsWmsRenderContext::UseFilter );
context.setFlag( QgsWmsRenderContext::UseSelection );
context.setFlag( QgsWmsRenderContext::SetAccessControl );
context.setFlag( QgsWmsRenderContext::AddHighlightLayers );
context.setFlag( QgsWmsRenderContext::AddExternalLayers );
context.setParameters( wmsParameters );

// rendering
QgsRenderer renderer( context );
response.setHeader( QStringLiteral( "Content-Type" ), contentType );
response.write( renderer.getPrint() );
}

} // namespace QgsWms
@@ -286,77 +286,19 @@ namespace QgsWms

QByteArray QgsRenderer::getPrint()
{
//GetPrint request needs a template parameter
QString templateName = mWmsParameters.composerTemplate();
if ( templateName.isEmpty() )
{
throw QgsBadRequestException( QStringLiteral( "ParameterMissing" ),
QStringLiteral( "The TEMPLATE parameter is required for the GetPrint request" ) );
}

// get layers parameters
QList<QgsMapLayer *> layers;
QList<QgsWmsParametersLayer> params = mWmsParameters.layersParameters();

// create the output image (this is not really used but configureMapSettings
// needs it)
std::unique_ptr<QImage> image( new QImage() );

// configure map settings (background, DPI, ...)
QgsMapSettings mapSettings;
configureMapSettings( image.get(), mapSettings );

// init layer restorer before doing anything
std::unique_ptr<QgsLayerRestorer> restorer;
restorer.reset( new QgsLayerRestorer( mNicknameLayers.values() ) );

// init stylized layers according to LAYERS/STYLES or SLD
QString sld = mWmsParameters.sldBody();
if ( !sld.isEmpty() )
{
layers = sldStylizedLayers( sld );
}
else
{
layers = stylizedLayers( params );
}

// remove unwanted layers (restricted layers, ...)
removeUnwantedLayers( layers );
restorer.reset( new QgsLayerRestorer( mContext.layers() ) );

// configure each layer with opacity, selection filter, ...
bool updateMapExtent = mWmsParameters.bbox().isEmpty();
for ( QgsMapLayer *layer : layers )
// GetPrint request needs a template parameter
const QString templateName = mWmsParameters.composerTemplate();
if ( templateName.isEmpty() )
{
checkLayerReadPermissions( layer );

for ( const QgsWmsParametersLayer &param : params )
{
if ( param.mNickname == layerNickname( *layer ) )
{
setLayerOpacity( layer, param.mOpacity );

setLayerFilter( layer, param.mFilter );

setLayerSelection( layer, param.mSelection );

if ( updateMapExtent )
updateExtent( layer, mapSettings );

break;
}
}

setLayerAccessControlFilter( layer );
throw QgsBadRequestException( QStringLiteral( "ParameterMissing" ),
QStringLiteral( "The TEMPLATE parameter is required for the GetPrint request" ) );
}

// add highlight layers above others
layers = layers << highlightLayers( mWmsParameters.highlightLayersParameters() );

// add layers to map settings (revert order for the rendering)
std::reverse( layers.begin(), layers.end() );
mapSettings.setLayers( layers );

// check template
const QgsLayoutManager *lManager = mProject->layoutManager();
QgsPrintLayout *sourceLayout( dynamic_cast<QgsPrintLayout *>( lManager->layoutByName( templateName ) ) );
if ( !sourceLayout )
@@ -470,6 +412,19 @@ namespace QgsWms
}
}

// configure layers
QgsMapSettings mapSettings;
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers, &mapSettings );

// configure map settings (background, DPI, ...)
std::unique_ptr<QImage> image( new QImage() );
configureMapSettings( image.get(), mapSettings );

// add layers to map settings (revert order for the rendering)
mapSettings.setLayers( layers );

// configure layout
configurePrintLayout( layout.get(), mapSettings, atlas );

// Get the temporary output file

0 comments on commit 24f3f97

Please sign in to comment.
You can’t perform that action at this time.