QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgseditformconfig.h"
29 #include <QDomDocument>
30 #include <QMap>
31 #include <QString>
32 
34 class QgsPrintLayout;
35 class QgsFeature;
36 class QgsLayout;
37 class QgsMapLayer;
38 class QgsMapSettings;
39 class QgsPointXY;
40 class QgsRasterLayer;
41 class QgsRectangle;
42 class QgsRenderContext;
43 class QgsVectorLayer;
44 class QgsAccessControl;
45 class QgsDxfExport;
46 class QgsLayerTreeModel;
47 class QgsLayerTree;
48 class QgsServerInterface;
50 class QgsEditFormConfig;
51 
52 class QImage;
53 class QPaintDevice;
54 class QPainter;
55 class QgsLayerTreeGroup;
56 
57 namespace QgsWms
58 {
59 
67  {
68  public:
69 
75  QgsRenderer( const QgsWmsRenderContext &context );
76 
80  ~QgsRenderer();
81 
89  QImage *getLegendGraphics( QgsLayerTreeModel &model );
90 
98  QImage *getLegendGraphics( QgsLayerTreeModelLegendNode &nodeModel );
99 
107  QJsonObject getLegendGraphicsAsJson( QgsLayerTreeModel &model );
108 
109  typedef QSet<QString> SymbolSet;
110  typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;
111 
116  HitTest symbols();
117 
123  QImage *getMap();
124 
130  std::unique_ptr<QgsDxfExport> getDxf();
131 
136  QByteArray getPrint();
137 
142  QByteArray getFeatureInfo( const QString &version = "1.3.0" );
143 
147  void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );
148 
149  private:
150  QgsLegendSettings legendSettings();
151 
152  // Build and returns highlight layers
153  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
154 
155  // Rendering step for layers
156  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;
157 
158  // Rendering step for annotations
159  void annotationsRendering( QPainter *painter, const QgsMapSettings &mapSettings ) const;
160 
161  // Set layer opacity
162  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
163 
164  // Set layer filter and dimension
165  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
166 
167  QStringList dimensionFilter( QgsVectorLayer *layer ) const;
168 
169  // Set layer python filter
170  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
171 
172  // Set layer selection
173  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
174 
175  // Combine map extent with layer extent
176  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
177 
178  // Scale image with WIDTH/HEIGHT if necessary
179  QImage *scaleImage( const QImage *image ) const;
180 
187  QImage *createImage( const QSize &size ) const;
188 
196  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true );
197 
198  QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
199  const QImage *outputImage, const QString &version ) const;
200 
216  bool featureInfoFromVectorLayer( QgsVectorLayer *layer,
217  const QgsPointXY *infoPoint,
218  int nFeatures,
219  QDomDocument &infoDocument,
220  QDomElement &layerElement,
221  const QgsMapSettings &mapSettings,
222  QgsRenderContext &renderContext,
223  const QString &version,
224  QgsRectangle *featureBBox = nullptr,
225  QgsGeometry *filterGeom = nullptr ) const;
226 
238  void writeAttributesTabGroup( const QgsAttributeEditorElement *group, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext, QStringList *attributes = nullptr ) const;
239 
251  void writeAttributesTabLayout( QgsEditFormConfig &config, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext, QStringList *attributes = nullptr ) const;
252 
264  void writeVectorLayerAttribute( int attributeIndex, QgsVectorLayer *layer, const QgsFields &fields, QgsAttributes &featureAttributes, QDomDocument &doc, QDomElement &featureElem, QgsRenderContext &renderContext, QStringList *attributes = nullptr ) const;
265 
267  bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
268  const QgsMapSettings &mapSettings,
269  const QgsPointXY *infoPoint,
270  QDomDocument &infoDocument,
271  QDomElement &layerElement,
272  const QString &version ) const;
273 
275  void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
277  void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
278 
283  bool testFilterStringSafety( const QString &filter ) const;
285  static void groupStringList( QStringList &list, const QString &groupString );
286 
288  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
289 
291  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
292 
294  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
295 
297  QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const;
298 
299  QDomElement createFeatureGML(
300  const QgsFeature *feat,
301  QgsVectorLayer *layer,
302  QDomDocument &doc,
304  const QgsMapSettings &mapSettings,
305  const QString &typeName,
306  bool withGeom,
307  int version,
308  QStringList *attributes = nullptr ) const;
309 
311  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
313  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
314 
322  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, bool atlasPrint = false );
323 
324  void removeTemporaryLayers();
325 
326  void handlePrintErrors( const QgsLayout *layout ) const;
327 
328  void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;
329 
330  void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;
331 
332  QgsWmsParameters mWmsParameters;
333 
334  QgsFeatureFilter mFeatureFilter;
335 
336  const QgsProject *mProject = nullptr;
337  QList<QgsMapLayer *> mTemporaryLayers;
338  const QgsWmsRenderContext &mContext;
339 
341  bool mIsTemporal = false;
342  };
343 
344 } // namespace QgsWms
345 
346 #endif
QgsAttributeEditorElement
This is an abstract base class for any elements of a drag and drop form.
Definition: qgsattributeeditorelement.h:37
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:346
qgsserversettings.h
QgsWms::QgsRenderer::HitTest
QHash< QgsVectorLayer *, SymbolSet > HitTest
Definition: qgswmsrenderer.h:110
qgslayertreemodellegendnode.h
QgsDxfExport
Exports QGIS layers to the DXF format.
Definition: qgsdxfexport.h:64
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
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:316
QgsLayerTreeModel
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Definition: qgslayertreemodel.h:55
qgsfeaturefilter.h
QgsRectangle
A rectangle specified with double values.
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:1112
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsLayerTree
Namespace with helper functions for layer tree operations.
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:120
QgsWms::QgsRenderer::~QgsRenderer
~QgsRenderer()
Destructor for QgsRenderer.
Definition: qgswmsrenderer.cpp:129
QgsWms::QgsRenderer::getMap
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
Definition: qgswmsrenderer.cpp:940
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:40
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
Represents a raster layer.
Definition: qgsrasterlayer.h:76
QgsWms::QgsRenderer::SymbolSet
QSet< QString > SymbolSet
Definition: qgswmsrenderer.h:109
QgsEditFormConfig
Contains configuration settings for an editor form.
Definition: qgseditformconfig.h:39
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
qgswmsparameters.h
QgsWms::QgsRenderer::getDxf
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.
Definition: qgswmsrenderer.cpp:988
withGeom
bool withGeom
Definition: qgswfsgetfeature.cpp:111
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
qgseditformconfig.h
QgsAccessControl
A helper class that centralizes restrictions given by all the access control filter plugins.
Definition: qgsaccesscontrol.h:36
QgsWms
Median cut 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
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsAttributes
A vector of attributes. Mostly equal to QVector<QVariant>.
Definition: qgsattributes.h:57
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsWms::QgsRenderer
Map renderer for WMS requests.
Definition: qgswmsrenderer.h:66
QgsWms::QgsRenderer::getLegendGraphics
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
Definition: qgswmsrenderer.cpp:134
QgsWms::QgsRenderer::configureLayers
void configureLayers(QList< QgsMapLayer * > &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
Definition: qgswmsrenderer.cpp:3540
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
Definition: qgsmapsettings.h:88
QgsWms::QgsRenderer::getLegendGraphicsAsJson
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model)
Returns the map legend as a JSON object.
Definition: qgswmsrenderer.cpp:213
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
qgswmsrendercontext.h
QgsWms::QgsRenderer::symbols
HitTest symbols()
Returns the hit test according to the current context.
Definition: qgswmsrenderer.cpp:280
QgsLayerTreeModelLegendNode
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Definition: qgslayertreemodellegendnode.h:49