QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
134  void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );
135 
136  private:
137  QgsLegendSettings legendSettings() const;
138 
139  // Build and returns highlight layers
140  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
141 
142  // Build and returns external layers
143  QList<QgsMapLayer *> externalLayers( const QList<QgsWmsParametersExternalLayer> &params );
144 
145  // Rendering step for layers
146  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;
147 
148  // Rendering step for annotations
149  void annotationsRendering( QPainter *painter ) const;
150 
151  // Set layer opacity
152  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
153 
154  // Set layer filter and dimension
155  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
156 
157  QStringList dimensionFilter( QgsVectorLayer *layer ) const;
158 
159  // Set layer python filter
160  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
161 
162  // Set layer selection
163  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
164 
165  // Combine map extent with layer extent
166  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
167 
168  // Scale image with WIDTH/HEIGHT if necessary
169  QImage *scaleImage( const QImage *image ) const;
170 
177  QImage *createImage( const QSize &size ) const;
178 
186  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;
187 
188  QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
189  const QImage *outputImage, const QString &version ) const;
190 
206  bool featureInfoFromVectorLayer( QgsVectorLayer *layer,
207  const QgsPointXY *infoPoint,
208  int nFeatures,
209  QDomDocument &infoDocument,
210  QDomElement &layerElement,
211  const QgsMapSettings &mapSettings,
212  QgsRenderContext &renderContext,
213  const QString &version,
214  QgsRectangle *featureBBox = nullptr,
215  QgsGeometry *filterGeom = nullptr ) const;
216 
218  bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
219  const QgsMapSettings &mapSettings,
220  const QgsPointXY *infoPoint,
221  QDomDocument &infoDocument,
222  QDomElement &layerElement,
223  const QString &version ) const;
224 
226  void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
228  void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
229 
233  bool testFilterStringSafety( const QString &filter ) const;
235  static void groupStringList( QStringList &list, const QString &groupString );
236 
238  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
239 
241  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
242 
244  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
245 
247  QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const;
248 
249  QDomElement createFeatureGML(
250  const QgsFeature *feat,
251  QgsVectorLayer *layer,
252  QDomDocument &doc,
254  const QgsMapSettings &mapSettings,
255  const QString &typeName,
256  bool withGeom,
257  int version,
258  QStringList *attributes = nullptr ) const;
259 
261  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
263  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
264 
265  /*
266  * Configures the print layout for the GetPrint request
267  *\param c the print layout
268  *\param mapSettings the map settings
269  *\param atlasPrint true if atlas is used for printing
270  *\returns true in case of success
271  * */
272  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, bool atlasPrint = false );
273 
274  void removeTemporaryLayers();
275 
276  void handlePrintErrors( const QgsLayout *layout ) const;
277 
278  void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;
279 
280  void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;
281 
282  QgsWmsParameters mWmsParameters;
283 
284  QgsFeatureFilter mFeatureFilter;
285 
286  const QgsProject *mProject = nullptr;
287  QList<QgsMapLayer *> mTemporaryLayers;
288  QgsWmsRenderContext mContext;
289  };
290 
291 } // namespace QgsWms
292 
293 #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:79
~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:122
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...
void configureLayers(QList< QgsMapLayer *> &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
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).