QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgswmsgetprint.h"
23 #include "qgswmsrenderer.h"
24 
25 namespace QgsWms
26 {
27  void writeGetPrint( QgsServerInterface *serverIface, const QgsProject *project,
28  const QString &version, const QgsServerRequest &request,
29  QgsServerResponse &response )
30  {
31  QgsServerRequest::Parameters params = request.parameters();
32 
33  Q_UNUSED( version );
34 
35  QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
36  QgsRenderer renderer( serverIface, project, wmsParameters );
37 
38  QString format = params.value( "FORMAT" );
39  QString contentType;
40 
41  // GetPrint supports svg/png/pdf
42  if ( format.compare( QLatin1String( "image/png" ), Qt::CaseInsensitive ) == 0 ||
43  format.compare( QLatin1String( "png" ), Qt::CaseInsensitive ) == 0 )
44  {
45  format = QStringLiteral( "png" );
46  contentType = QStringLiteral( "image/png" );
47  }
48  else if ( format.compare( QLatin1String( "image/jpg" ), Qt::CaseInsensitive ) == 0 ||
49  format.compare( QLatin1String( "image/jpeg" ), Qt::CaseInsensitive ) == 0 ||
50  format.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0 ||
51  format.compare( QLatin1String( "jpeg" ), Qt::CaseInsensitive ) == 0 )
52  {
53  format = QStringLiteral( "jpg" );
54  contentType = QStringLiteral( "image/jpeg" );
55  }
56  else if ( format.compare( QLatin1String( "image/svg" ), Qt::CaseInsensitive ) == 0 ||
57  format.compare( QLatin1String( "image/svg+xml" ), Qt::CaseInsensitive ) == 0 ||
58  format.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
59  {
60  format = QStringLiteral( "svg" );
61  contentType = QStringLiteral( "image/svg+xml" );
62  }
63  else if ( format.compare( QLatin1String( "application/pdf" ), Qt::CaseInsensitive ) == 0 ||
64  format.compare( QLatin1String( "pdf" ), Qt::CaseInsensitive ) == 0 )
65  {
66  format = QStringLiteral( "pdf" );
67  contentType = QStringLiteral( "application/pdf" );
68  }
69  else
70  {
71  throw QgsServiceException( QStringLiteral( "InvalidFormat" ),
72  QString( "Output format %1 is not supported by the GetPrint request" ).arg( format ) );
73  }
74 
75  response.setHeader( QStringLiteral( "Content-Type" ), contentType );
76  response.write( renderer.getPrint( format ) );
77  }
78 
79 } // namespace QgsWms
80 
81 
82 
83 
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...
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device...
Exception class for WMS service exceptions.
QByteArray getPrint(const QString &formatString)
Returns printed page as binary.
Provides an interface to retrieve and manipulate WMS parameters received from the client...
Reads and writes project states.
Definition: qgsproject.h:89
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetPrint response.
Median cut implementation.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
Map renderer for WMS requests.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
QMap< QString, QString > Parameters