QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
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 "qgseditformconfig.h"
24#include "qgsfeaturefilter.h"
26#include "qgslayoutatlas.h"
27#include "qgsmaprendererjob.h"
28#include "qgsserversettings.h"
29#include "qgswmsparameters.h"
30#include "qgswmsrendercontext.h"
31
32#include <QDomDocument>
33#include <QMap>
34#include <QString>
35
37class QgsPrintLayout;
38class QgsFeature;
39class QgsLayout;
40class QgsMapLayer;
42class QgsMapSettings;
43class QgsPointXY;
44class QgsRasterLayer;
45class QgsMeshLayer;
46class QgsRectangle;
48class QgsVectorLayer;
50class QgsDxfExport;
52class QgsLayerTree;
56
57class QImage;
58class QPaintDevice;
59class QPainter;
61
62namespace QgsWms
63{
64
71 {
72 public:
78 QgsRenderer( const QgsWmsRenderContext &context );
79
81
89 QImage *getLegendGraphics( QgsLayerTreeModel &model );
90
99
109
119
120
121 typedef QSet<QString> SymbolSet;
122 typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;
123
129
135 std::unique_ptr<QImage> getMap();
136
141 std::unique_ptr<QgsDxfExport> getDxf();
142
149 std::unique_ptr<QgsMapRendererTask> getPdf( const QString &tmpFileName );
150
155 QByteArray getPrint();
156
161 QByteArray getFeatureInfo( const QString &version = "1.3.0" );
162
166 void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );
167
168 private:
169 QgsLegendSettings legendSettings();
170
171 // Build and returns highlight layers
172 QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
173
174 // Rendering step for layers
175 QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage *image ) const;
176
177 // Rendering step for annotations
178 void annotationsRendering( QPainter *painter, const QgsMapSettings &mapSettings ) const;
179
180 // Set layer opacity
181 void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
182
183 // Set layer filter and dimension
184 void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
185
186 QStringList dimensionFilter( QgsVectorLayer *layer ) const;
187
188 // Set layer python filter
189 void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
190
191 // Set layer selection
192 void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
193
194 // Combine map extent with layer extent
195 void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
196
197 // Scale image with WIDTH/HEIGHT if necessary
198 QImage *scaleImage( const QImage *image ) const;
199
206 QImage *createImage( const QSize &size ) const;
207
215 void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true );
216
223 QgsRenderContext configureDefaultRenderContext( QPainter *painter = nullptr );
224
225 QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings, const QImage *outputImage, const QString &version ) const;
226
242 bool featureInfoFromVectorLayer(
243 QgsVectorLayer *layer,
244 const QgsPointXY *infoPoint,
245 int nFeatures,
246 QDomDocument &infoDocument,
247 QDomElement &layerElement,
248 const QgsMapSettings &mapSettings,
249 QgsRenderContext &renderContext,
250 const QString &version,
251 QgsRectangle *featureBBox = nullptr,
252 QgsGeometry *filterGeom = nullptr
253 ) const;
254
266 void writeAttributesTabGroup(
267 const QgsAttributeEditorElement *group,
268 QgsVectorLayer *layer,
269 const QgsFields &fields,
270 QgsAttributes &featureAttributes,
271 QDomDocument &doc,
272 QDomElement &featureElem,
273 QgsRenderContext &renderContext,
274 QStringList *attributes = nullptr
275 ) const;
276
288 void writeAttributesTabLayout(
289 QgsEditFormConfig &config,
290 QgsVectorLayer *layer,
291 const QgsFields &fields,
292 QgsAttributes &featureAttributes,
293 QDomDocument &doc,
294 QDomElement &featureElem,
295 QgsRenderContext &renderContext,
296 QStringList *attributes = nullptr
297 ) const;
298
310 void writeVectorLayerAttribute(
311 int attributeIndex,
312 QgsVectorLayer *layer,
313 const QgsFields &fields,
314 QgsAttributes &featureAttributes,
315 QDomDocument &doc,
316 QDomElement &featureElem,
317 QgsRenderContext &renderContext,
318 QStringList *attributes = nullptr
319 ) const;
320
322 bool featureInfoFromMeshLayer(
323 QgsMeshLayer *layer, const QgsMapSettings &mapSettings, const QgsPointXY *infoPoint, const QgsRenderContext &renderContext, QDomDocument &infoDocument, QDomElement &layerElement, const QString &version
324 ) const;
326 bool featureInfoFromRasterLayer(
327 QgsRasterLayer *layer, const QgsMapSettings &mapSettings, const QgsPointXY *infoPoint, const QgsRenderContext &renderContext, QDomDocument &infoDocument, QDomElement &layerElement, const QString &version
328 ) const;
329
331 void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
333 void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
334
339 bool testFilterStringSafety( const QString &filter ) const;
341 static void groupStringList( QStringList &list, const QString &groupString );
342
344 void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
345
347 QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
348
350 QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
351
353 QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc, const QgsCoordinateReferenceSystem &destCRS ) const;
354
355 QDomElement createFeatureGML(
356 const QgsFeature *feat,
357 QgsVectorLayer *layer,
358 QDomDocument &doc,
360 const QgsMapSettings &mapSettings,
361 const QString &typeName,
362 bool withGeom,
363 int version,
364 QStringList *attributes = nullptr
365 ) const;
366
368 static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
370 QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
371
379 bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, QgsLayoutAtlas *atlas );
380
381 void removeTemporaryLayers();
382
383 void logRenderingErrors( const QgsMapRendererJob::Errors &errors ) const;
384
385 void handlePrintErrors( const QgsLayout *layout ) const;
386
387 void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;
388
389 void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;
390
391 QgsWmsParameters mWmsParameters;
392
393 QgsFeatureFilter mFeatureFilter;
394
395 const QgsProject *mProject = nullptr;
396 QList<QgsMapLayer *> mTemporaryLayers;
397 const QgsWmsRenderContext &mContext;
398
400 bool mIsTemporal = false;
401 };
402
403} // namespace QgsWms
404
405#endif
QFlags< LegendJsonRenderFlag > LegendJsonRenderFlags
Definition qgis.h:4756
A helper class that centralizes restrictions given by all the access control filter plugins.
An abstract base class for any elements of a drag and drop form.
A vector of attributes.
Represents a coordinate reference system (CRS).
Exports QGIS layers to the DXF format.
Contains configuration settings for an editor form.
A feature filter provider allowing to set filter expressions on a per-layer basis.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
Layer tree group node serves as a container for layers and further groups.
An abstract interface for legend items returned from QgsMapLayerLegend implementation.
A model representing the layer tree, including layers and groups of layers.
Namespace with helper functions for layer tree operations.
Used to render QgsLayout as an atlas, by iterating over the features from an associated vector layer.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
Stores the appearance and layout settings for legend drawing with QgsLegendRenderer.
Base class for all map layer types.
Definition qgsmaplayer.h:83
QList< QgsMapRendererJob::Error > Errors
QgsTask task which draws a map to an image file or a painter as a background task.
Contains configuration for rendering maps.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Represents a 2D point.
Definition qgspointxy.h:62
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
Represents a raster layer.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Defines interfaces exposed by QGIS Server and made available to plugins.
Represents a vector layer which manages a vector based dataset.
QgsRenderer(const QgsWmsRenderContext &context)
Constructor for QgsRenderer.
QHash< QgsVectorLayer *, SymbolSet > HitTest
QByteArray getPrint()
Returns printed page as binary.
HitTest symbols()
Returns the hit test according to the current context.
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.
QSet< QString > SymbolSet
void configureLayers(QList< QgsMapLayer * > &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
std::unique_ptr< QgsMapRendererTask > getPdf(const QString &tmpFileName)
Returns a configured pdf export task.
QByteArray getFeatureInfo(const QString &version="1.3.0")
Creates an xml document that describes the result of the getFeatureInfo request.
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
std::unique_ptr< QImage > getMap()
Returns the map as an image (or nullptr in case of error).
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model, const Qgis::LegendJsonRenderFlags &jsonRenderFlags=Qgis::LegendJsonRenderFlags())
Returns the map legend as a JSON object.
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Rendering context for the WMS renderer.
Median cut implementation.
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
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