QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
104  QJsonObject getLegendGraphicsAsJson( QgsLayerTreeModel &model );
105 
106  typedef QSet<QString> SymbolSet;
107  typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;
108 
113  HitTest symbols();
114 
120  QImage *getMap();
121 
127  std::unique_ptr<QgsDxfExport> getDxf();
128 
132  QByteArray getPrint();
133 
138  QByteArray getFeatureInfo( const QString &version = "1.3.0" );
139 
143  void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );
144 
145  private:
146  QgsLegendSettings legendSettings() const;
147 
148  // Build and returns highlight layers
149  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
150 
151  // Build and returns external layers
152  QList<QgsMapLayer *> externalLayers( const QList<QgsWmsParametersExternalLayer> &params );
153 
154  // Rendering step for layers
155  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;
156 
157  // Rendering step for annotations
158  void annotationsRendering( QPainter *painter ) const;
159 
160  // Set layer opacity
161  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
162 
163  // Set layer filter and dimension
164  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
165 
166  QStringList dimensionFilter( QgsVectorLayer *layer ) const;
167 
168  // Set layer python filter
169  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
170 
171  // Set layer selection
172  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
173 
174  // Combine map extent with layer extent
175  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
176 
177  // Scale image with WIDTH/HEIGHT if necessary
178  QImage *scaleImage( const QImage *image ) const;
179 
186  QImage *createImage( const QSize &size ) const;
187 
195  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;
196 
197  QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
198  const QImage *outputImage, const QString &version ) const;
199 
215  bool featureInfoFromVectorLayer( QgsVectorLayer *layer,
216  const QgsPointXY *infoPoint,
217  int nFeatures,
218  QDomDocument &infoDocument,
219  QDomElement &layerElement,
220  const QgsMapSettings &mapSettings,
221  QgsRenderContext &renderContext,
222  const QString &version,
223  QgsRectangle *featureBBox = nullptr,
224  QgsGeometry *filterGeom = nullptr ) const;
225 
227  bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
228  const QgsMapSettings &mapSettings,
229  const QgsPointXY *infoPoint,
230  QDomDocument &infoDocument,
231  QDomElement &layerElement,
232  const QString &version ) const;
233 
235  void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
237  void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
238 
242  bool testFilterStringSafety( const QString &filter ) const;
244  static void groupStringList( QStringList &list, const QString &groupString );
245 
247  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
248 
250  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
251 
253  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
254 
256  QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const;
257 
258  QDomElement createFeatureGML(
259  const QgsFeature *feat,
260  QgsVectorLayer *layer,
261  QDomDocument &doc,
263  const QgsMapSettings &mapSettings,
264  const QString &typeName,
265  bool withGeom,
266  int version,
267  QStringList *attributes = nullptr ) const;
268 
270  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
272  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
273 
281  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, bool atlasPrint = false );
282 
283  void removeTemporaryLayers();
284 
285  void handlePrintErrors( const QgsLayout *layout ) const;
286 
287  void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;
288 
289  void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;
290 
291  QgsWmsParameters mWmsParameters;
292 
293  QgsFeatureFilter mFeatureFilter;
294 
295  const QgsProject *mProject = nullptr;
296  QList<QgsMapLayer *> mTemporaryLayers;
297  QgsWmsRenderContext mContext;
298  };
299 
300 } // namespace QgsWms
301 
302 #endif
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:336
qgsserversettings.h
QgsWms::QgsRenderer::HitTest
QHash< QgsVectorLayer *, SymbolSet > HitTest
Definition: qgswmsrenderer.h:107
qgslayertreemodellegendnode.h
QgsDxfExport
Definition: qgsdxfexport.h:62
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsWms::QgsWmsRenderContext
Rendering context for the WMS renderer.
Definition: qgswmsrendercontext.h:47
QgsWms::QgsRenderer::getPrint
QByteArray getPrint()
Returns printed page as binary.
Definition: qgswmsrenderer.cpp:300
QgsLayerTreeModel
Definition: qgslayertreemodel.h:53
qgsfeaturefilter.h
QgsRectangle
Definition: qgsrectangle.h:41
QgsWms::QgsRenderer::getFeatureInfo
QByteArray getFeatureInfo(const QString &version="1.3.0")
Creates an xml document that describes the result of the getFeatureInfo request.
Definition: qgswmsrenderer.cpp:927
QgsProject
Definition: qgsproject.h:92
QgsLayerTree
Definition: qgslayertree.h:32
QgsPrintLayout
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Definition: qgsprintlayout.h:30
QgsWms::QgsRenderer::QgsRenderer
QgsRenderer(const QgsWmsRenderContext &context)
Constructor for QgsRenderer.
Definition: qgswmsrenderer.cpp:113
QgsWms::QgsRenderer::~QgsRenderer
~QgsRenderer()
Destructor for QgsRenderer.
Definition: qgswmsrenderer.cpp:122
QgsWms::QgsRenderer::getMap
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
Definition: qgswmsrenderer.cpp:800
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
QgsLegendSettings
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:38
typeName
const QString & typeName
Definition: qgswfsgetfeature.cpp:109
QgsRasterLayer
Definition: qgsrasterlayer.h:72
QgsWms::QgsRenderer::SymbolSet
QSet< QString > SymbolSet
Definition: qgswmsrenderer.h:106
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
qgswmsparameters.h
QgsWms::QgsRenderer::getDxf
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.
Definition: qgswmsrenderer.cpp:848
withGeom
bool withGeom
Definition: qgswfsgetfeature.cpp:111
QgsPointXY
Definition: qgspointxy.h:43
QgsAccessControl
A helper class that centralizes restrictions given by all the access control filter plugins.
Definition: qgsaccesscontrol.h:36
QgsWms
WMS implementation.
Definition: qgsdxfwriter.cpp:22
QgsFeatureFilter
A feature filter provider allowing to set filter expressions on a per-layer basis.
Definition: qgsfeaturefilter.h:34
c
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
Definition: porting_processing.dox:1
QgsGeometry
Definition: qgsgeometry.h:122
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsFeature
Definition: qgsfeature.h:55
QgsWms::QgsRenderer
Map renderer for WMS requests.
Definition: qgswmsrenderer.h:63
QgsWms::QgsRenderer::getLegendGraphics
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
Definition: qgswmsrenderer.cpp:127
QgsWms::QgsRenderer::configureLayers
void configureLayers(QList< QgsMapLayer * > &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
Definition: qgswmsrenderer.cpp:3122
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsWms::QgsRenderer::getLegendGraphicsAsJson
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model)
Returns the map legend as a JSON object.
Definition: qgswmsrenderer.cpp:197
QgsServerInterface
Definition: qgsserverinterface.h:60
qgswmsrendercontext.h
QgsWms::QgsRenderer::symbols
HitTest symbols()
Returns the hit test according to the current context.
Definition: qgswmsrenderer.cpp:264
QgsLayerTreeModelLegendNode
Definition: qgslayertreemodellegendnode.h:50