QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgswmsgetprint.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswmsgetprint.h
3  -------------------------
4  begin : December 20 , 2016
5  copyright : (C) 2007 by Marco Hugentobler (original code)
6  (C) 2014 by Alessandro Pasotti (original code)
7  (C) 2016 by David Marteau
8  email : marco dot hugentobler at karto dot baug dot ethz dot ch
9  a dot pasotti at itopen dot it
10  david dot marteau at 3liz dot com
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 #include "qgswmsutils.h"
22 #include "qgswmsrequest.h"
23 #include "qgswmsgetprint.h"
24 #include "qgswmsrenderer.h"
25 #include "qgswmsserviceexception.h"
26 
27 namespace QgsWms
28 {
29  void writeGetPrint( QgsServerInterface *serverIface, const QgsProject *project,
30  const QgsWmsRequest &request,
31  QgsServerResponse &response )
32  {
33  const QgsWmsParameters parameters = request.wmsParameters();
34 
35  // GetPrint supports svg/png/pdf
36  const QgsWmsParameters::Format format = parameters.format();
37  QString contentType;
38  switch ( format )
39  {
41  contentType = QStringLiteral( "image/png" );
42  break;
44  contentType = QStringLiteral( "image/jpeg" );
45  break;
47  contentType = QStringLiteral( "image/svg+xml" );
48  break;
50  contentType = QStringLiteral( "application/pdf" );
51  break;
52  default:
54  parameters[QgsWmsParameter::FORMAT] );
55  break;
56  }
57 
58  // prepare render context
59  QgsWmsRenderContext context( project, serverIface );
60  context.setFlag( QgsWmsRenderContext::UpdateExtent );
61  context.setFlag( QgsWmsRenderContext::UseOpacity );
62  context.setFlag( QgsWmsRenderContext::UseFilter );
63  context.setFlag( QgsWmsRenderContext::UseSelection );
64  context.setFlag( QgsWmsRenderContext::SetAccessControl );
65  context.setFlag( QgsWmsRenderContext::AddHighlightLayers );
66  context.setFlag( QgsWmsRenderContext::AddExternalLayers );
67  context.setFlag( QgsWmsRenderContext::AddAllLayers );
68  context.setParameters( parameters );
69 
70  // rendering
71  QgsRenderer renderer( context );
72  response.setHeader( QStringLiteral( "Content-Type" ), contentType );
73  response.write( renderer.getPrint() );
74  }
75 } // namespace QgsWms
QgsWms::QgsWmsRenderContext::UpdateExtent
@ UpdateExtent
Definition: qgswmsrendercontext.h:58
qgswmsrenderer.h
qgswmsutils.h
QgsWms::QgsWmsRenderContext::UseFilter
@ UseFilter
Definition: qgswmsrendercontext.h:55
QgsWms::QgsWmsParameters::Format
Format
Output format for the response.
Definition: qgswmsparameters.h:353
QgsWms::QgsWmsRenderContext::AddHighlightLayers
@ AddHighlightLayers
Definition: qgswmsrendercontext.h:57
QgsWms::QgsServiceException::OGC_InvalidFormat
@ OGC_InvalidFormat
Definition: qgswmsserviceexception.h:62
QgsWms::QgsWmsRenderContext::AddExternalLayers
@ AddExternalLayers
Definition: qgswmsrendercontext.h:62
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsWms::QgsWmsParameters::PNG
@ PNG
Definition: qgswmsparameters.h:357
QgsServerResponse::write
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
Definition: qgsserverresponse.cpp:25
QgsWms::QgsWmsRenderContext::AddAllLayers
@ AddAllLayers
For GetPrint: add layers from LAYER(S) parameter.
Definition: qgswmsrendercontext.h:65
QgsWms::QgsWmsRenderContext::SetAccessControl
@ SetAccessControl
Definition: qgswmsrendercontext.h:59
QgsWms::QgsWmsParameters::SVG
@ SVG
Definition: qgswmsparameters.h:358
QgsWms::QgsWmsParameters::PDF
@ PDF
Definition: qgswmsparameters.h:359
QgsWms
Median cut implementation.
Definition: qgsdxfwriter.cpp:22
QgsWms::QgsBadRequestException
Exception thrown in case of malformed request.
Definition: qgswmsserviceexception.h:226
QgsWms::writeGetPrint
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetPrint response.
Definition: qgswmsgetprint.cpp:46
qgswmsgetprint.h
QgsWms::QgsWmsParameters::JPG
@ JPG
Definition: qgswmsparameters.h:356
QgsWms::QgsWmsParameter::FORMAT
@ FORMAT
Definition: qgswmsparameters.h:163
qgswmsserviceexception.h
QgsWms::QgsWmsRenderContext::UseSelection
@ UseSelection
Definition: qgswmsrendercontext.h:56
qgswmsrequest.h
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:43
QgsServerResponse::setHeader
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
QgsWms::QgsWmsRenderContext::UseOpacity
@ UseOpacity
Definition: qgswmsrendercontext.h:54