QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgswmsrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgswmsrendrer.h
3  -------------------
4  begin : May 14, 2006
5  copyright : (C) 2006 by Marco Hugentobler
6  (C) 2017 by David Marteau
7  email : marco dot hugentobler at karto dot baug dot ethz dot ch
8  david dot marteau at 3liz dot com
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #ifndef QGSWMSRENDERER_H
21 #define QGSWMSRENDERER_H
22 
23 #include "qgsserversettings.h"
24 #include "qgswmsparameters.h"
25 #include "qgswmsrendercontext.h"
26 #include "qgsfeaturefilter.h"
28 #include <QDomDocument>
29 #include <QMap>
30 #include <QString>
31 
33 class QgsPrintLayout;
34 class QgsFeature;
35 class QgsLayout;
36 class QgsMapLayer;
37 class QgsMapSettings;
38 class QgsPointXY;
39 class QgsRasterLayer;
40 class QgsRectangle;
41 class QgsRenderContext;
42 class QgsVectorLayer;
43 class QgsAccessControl;
44 class QgsDxfExport;
45 class QgsLayerTreeModel;
46 class QgsLayerTree;
47 class QgsServerInterface;
48 
49 class QImage;
50 class QPaintDevice;
51 class QPainter;
52 class QgsLayerTreeGroup;
53 
54 namespace QgsWms
55 {
56 
64  {
65  public:
66 
72  QgsRenderer( const QgsWmsRenderContext &context );
73 
77  ~QgsRenderer();
78 
86  QImage *getLegendGraphics( QgsLayerTreeModel &model );
87 
95  QImage *getLegendGraphics( QgsLayerTreeModelLegendNode &nodeModel );
96 
97  typedef QSet<QString> SymbolSet;
98  typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;
99 
104  HitTest symbols();
105 
111  QImage *getMap();
112 
119 
123  QByteArray getPrint();
124 
129  QByteArray getFeatureInfo( const QString &version = "1.3.0" );
130 
131  private:
132  QgsLegendSettings legendSettings() const;
133 
134  // Build and returns highlight layers
135  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
136 
137  // Build and returns external layers
138  QList<QgsMapLayer *> externalLayers( const QList<QgsWmsParametersExternalLayer> &params );
139 
140  // Rendering step for layers
141  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;
142 
143  // Rendering step for annotations
144  void annotationsRendering( QPainter *painter ) const;
145 
146  // Set layer opacity
147  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
148 
149  // Set layer filter
150  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
151 
152  // Set layer python filter
153  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
154 
155  // Set layer selection
156  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
157 
158  // Combine map extent with layer extent
159  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
160 
161  // Scale image with WIDTH/HEIGHT if necessary
162  QImage *scaleImage( const QImage *image ) const;
163 
170  QImage *createImage( const QSize &size ) const;
171 
179  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;
180 
181  QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
182  const QImage *outputImage, const QString &version ) const;
183 
199  bool featureInfoFromVectorLayer( QgsVectorLayer *layer,
200  const QgsPointXY *infoPoint,
201  int nFeatures,
202  QDomDocument &infoDocument,
203  QDomElement &layerElement,
204  const QgsMapSettings &mapSettings,
205  QgsRenderContext &renderContext,
206  const QString &version,
207  QgsRectangle *featureBBox = nullptr,
208  QgsGeometry *filterGeom = nullptr ) const;
209 
211  bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
212  const QgsMapSettings &mapSettings,
213  const QgsPointXY *infoPoint,
214  QDomDocument &infoDocument,
215  QDomElement &layerElement,
216  const QString &version ) const;
217 
219  void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
221  void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
222 
226  bool testFilterStringSafety( const QString &filter ) const;
228  static void groupStringList( QStringList &list, const QString &groupString );
229 
231  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
232 
234  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
235 
237  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
238 
240  QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const;
241 
242  QDomElement createFeatureGML(
243  QgsFeature *feat,
244  QgsVectorLayer *layer,
245  QDomDocument &doc,
247  const QgsMapSettings &mapSettings,
248  const QString &typeName,
249  bool withGeom,
250  int version,
251  QStringList *attributes = nullptr ) const;
252 
254  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
256  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
257 
258  /*
259  * Configures the print layout for the GetPrint request
260  *\param c the print layout
261  *\param mapSettings the map settings
262  *\param atlasPrint true if atlas is used for printing
263  *\returns true in case of success
264  * */
265  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, bool atlasPrint = false );
266 
267  void removeTemporaryLayers();
268 
269  void handlePrintErrors( const QgsLayout *layout ) const;
270 
271  void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );
272 
273  void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;
274 
275  void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;
276 
277  QgsWmsParameters mWmsParameters;
278 
279  QgsFeatureFilter mFeatureFilter;
280 
281  const QgsProject *mProject = nullptr;
282  QList<QgsMapLayer *> mTemporaryLayers;
283  QgsWmsRenderContext mContext;
284  };
285 
286 } // namespace QgsWms
287 
288 #endif
QByteArray getFeatureInfo(const QString &version="1.3.0")
Creates an xml document that describes the result of the getFeatureInfo request.
Layer tree group node serves as a container for layers and further groups.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:78
~QgsRenderer()
Destructor for QgsRenderer.
HitTest symbols()
Returns the hit test according to the current context.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QByteArray getPrint()
Returns printed page as binary.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
QgsDxfExport getDxf()
Returns the map as DXF data.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsCoordinateReferenceSystem & crs
bool withGeom
The QgsMapSettings class contains configuration for rendering of the map.
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QHash< QgsVectorLayer *, SymbolSet > HitTest
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:32
const QString & typeName
A feature filter provider allowing to set filter expressions on a per-layer basis.
Provides an interface to retrieve and manipulate WMS parameters received from the client...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Reads and writes project states.
Definition: qgsproject.h:89
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsRenderer(const QgsWmsRenderContext &context)
Constructor for QgsRenderer.
Median cut implementation.
QSet< QString > SymbolSet
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
Map renderer for WMS requests.
Contains information about the context of a rendering operation.
Rendering context for the WMS renderer.
This class represents a coordinate reference system (CRS).
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
A helper class that centralizes restrictions given by all the access control filter plugins...
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Represents a vector layer which manages a vector based data sets.
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).