QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgswmsrendercontext.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgswmsrendercontext.h
3  ---------------------
4  begin : March 22, 2019
5  copyright : (C) 2019 by Paul Blottiere
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSWMSRENDERCONTEXT_H
19 #define QGSWMSRENDERCONTEXT_H
20 
21 #include "qgswmsparameters.h"
22 #include "qgsproject.h"
23 #include "qgsserverinterface.h"
24 
25 namespace QgsWms
26 {
27 
34  class QgsWmsRenderContext
35  {
36  public:
38  enum Flag
39  {
40  UseScaleDenominator = 0x01,
41  UseOpacity = 0x02,
42  UseFilter = 0x04,
43  UseSelection = 0x08,
44  AddHighlightLayers = 0x10,
45  UpdateExtent = 0x20,
46  SetAccessControl = 0x40,
48  UseWfsLayersOnly = 0x100,
49  AddExternalLayers = 0x200,
50  UseSrcWidthHeight = 0x400,
51  UseTileBuffer = 0x800
52  };
53  Q_DECLARE_FLAGS( Flags, Flag )
54 
55 
58  QgsWmsRenderContext() = default;
59 
66 
71 
76 
80  const QgsServerSettings &settings() const;
81 
85  const QgsProject *project() const;
86 
90  void setFlag( Flag flag, bool on = true );
91 
97  bool testFlag( Flag flag ) const;
98 
102  QList<QgsMapLayer *> layers() const;
103 
108  QList<QgsMapLayer *> layersToRender() const;
109 
114  QDomElement sld( const QgsMapLayer &layer ) const;
115 
120  QString style( const QgsMapLayer &layer ) const;
121 
126  double scaleDenominator() const;
127 
132  void setScaleDenominator( double scaleDenominator );
133 
138  bool updateExtent() const;
139 
145 
150  int imageQuality() const;
151 
157  int tileBuffer() const;
158 
162  int precision() const;
163 
168  QString layerNickname( const QgsMapLayer &layer ) const;
169 
174  QgsMapLayer *layer( const QString &nickname ) const;
175 
179  bool isValidLayer( const QString &nickname ) const;
180 
185  QList<QgsMapLayer *> layersFromGroup( const QString &nickname ) const;
186 
190  bool isValidGroup( const QString &name ) const;
191 
195  qreal dotsPerMm() const;
196 
201  QStringList flattenedQueryLayers() const;
202 
203 #ifdef HAVE_SERVER_PYTHON_PLUGINS
204 
208  QgsAccessControl *accessControl() const;
209 #endif
210 
215  QMap<QString, QList<QgsMapLayer *> > layerGroups() const;
216 
221  double mapTileBuffer( int mapWidth ) const;
222 
228  QSize mapSize( bool aspectRatio = true ) const;
229 
235  bool isValidWidthHeight() const;
236 
240  int mapWidth() const;
241 
245  int mapHeight() const;
246 
247  private:
248  void initNicknameLayers();
249  void initRestrictedLayers();
250  void initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName );
251 
252  void searchLayersToRender();
253  void searchLayersToRenderSld();
254  void searchLayersToRenderStyle();
255  void removeUnwantedLayers();
256 
257  void checkLayerReadPermissions();
258 
259  bool layerScaleVisibility( const QString &name ) const;
260 
261  const QgsProject *mProject = nullptr;
262  QgsServerInterface *mInterface = nullptr;
263  QgsWmsParameters mParameters;
264  Flags mFlags = Flags();
265  double mScaleDenominator = -1.0;
266 
267  // nickname of all layers defined within the project
268  QMultiMap<QString, QgsMapLayer *> mNicknameLayers;
269 
270  // map of layers to use for rendering
271  QList<QgsMapLayer *> mLayersToRender;
272 
273  // list of layers which are not usable
274  QStringList mRestrictedLayers;
275 
276  QMap<QString, QList<QgsMapLayer *> > mLayerGroups;
277 
278  QMap<QString, QDomElement> mSlds;
279  QMap<QString, QString> mStyles;
280  };
281 };
282 
283 #endif
QgsWms::QgsWmsRenderContext::UpdateExtent
@ UpdateExtent
Definition: qgswmsrendercontext.h:58
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:336
QgsWms::QgsWmsRenderContext::mapWidth
int mapWidth() const
Returns WIDTH or SRCWIDTH according to UseSrcWidthHeight flag.
Definition: qgswmsrendercontext.cpp:560
QgsWms::QgsWmsRenderContext::layersFromGroup
QList< QgsMapLayer * > layersFromGroup(const QString &nickname) const
Returns the group's layers list corresponding to the nickname, or an empty list if not found.
Definition: qgswmsrendercontext.cpp:290
QgsWms::QgsWmsRenderContext::style
QString style(const QgsMapLayer &layer) const
Returns a style's name for a specific layer.
Definition: qgswmsrendercontext.cpp:93
QgsWms::QgsWmsRenderContext::UseFilter
@ UseFilter
Definition: qgswmsrendercontext.h:55
QgsWms::QgsWmsRenderContext::setFlag
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
Definition: qgswmsrendercontext.cpp:48
QgsWms::QgsWmsRenderContext::setParameters
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
Definition: qgswmsrendercontext.cpp:34
QgsWms::QgsWmsRenderContext::updateExtent
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
Definition: qgswmsrendercontext.cpp:242
QgsWms::QgsWmsRenderContext::layerGroups
QMap< QString, QList< QgsMapLayer * > > layerGroups() const
Returns a map having layer group names as keys and a list of layers as values.
Definition: qgswmsrendercontext.cpp:555
QgsWms::QgsWmsRenderContext::AddHighlightLayers
@ AddHighlightLayers
Definition: qgswmsrendercontext.h:57
QgsWms::QgsWmsRenderContext::isValidWidthHeight
bool isValidWidthHeight() const
Returns true if width and height are valid according to the maximum values defined within the project...
Definition: qgswmsrendercontext.cpp:586
QgsWms::QgsWmsRenderContext
Rendering context for the WMS renderer.
Definition: qgswmsrendercontext.h:47
QgsWms::QgsWmsRenderContext::AddQueryLayers
@ AddQueryLayers
Definition: qgswmsrendercontext.h:60
QgsWms::QgsWmsRenderContext::imageQuality
int imageQuality() const
Returns the image quality to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:122
QgsWms::QgsWmsRenderContext::AddExternalLayers
@ AddExternalLayers
Definition: qgswmsrendercontext.h:62
QgsWms::QgsWmsParametersLayer
Definition: qgswmsparameters.h:62
QgsProject
Definition: qgsproject.h:92
QgsServerSettings
Provides a way to retrieve settings by prioritizing according to environment variables,...
Definition: qgsserversettings.h:82
QgsWms::QgsWmsRenderContext::UseSrcWidthHeight
@ UseSrcWidthHeight
Definition: qgswmsrendercontext.h:63
QgsWms::QgsWmsRenderContext::tileBuffer
int tileBuffer() const
Returns the tile buffer value to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:134
QgsWms::QgsWmsRenderContext::mapSize
QSize mapSize(bool aspectRatio=true) const
Returns the size (in pixels) of the map to render, according to width and height WMS parameters as we...
Definition: qgswmsrendercontext.cpp:680
QgsWms::QgsWmsRenderContext::flattenedQueryLayers
QStringList flattenedQueryLayers() const
Returns a list of query layer names where group names are replaced by the names of their layer compon...
Definition: qgswmsrendercontext.cpp:173
QgsWms::QgsWmsRenderContext::setScaleDenominator
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
Definition: qgswmsrendercontext.cpp:236
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
QgsWms::QgsWmsRenderContext::SetAccessControl
@ SetAccessControl
Definition: qgswmsrendercontext.h:59
QgsWms::QgsWmsRenderContext::UseWfsLayersOnly
@ UseWfsLayersOnly
Definition: qgswmsrendercontext.h:61
QgsWms::QgsWmsRenderContext::settings
const QgsServerSettings & settings() const
Returns settings of the server.
Definition: qgswmsrendercontext.cpp:70
QgsWms::QgsWmsRenderContext::isValidLayer
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
Definition: qgswmsrendercontext.cpp:285
QgsWms::QgsWmsRenderContext::precision
int precision() const
Returns the precision to use according to the current configuration.
Definition: qgswmsrendercontext.cpp:146
QgsWms::QgsWmsRenderContext::sld
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
Definition: qgswmsrendercontext.cpp:80
QgsWms::QgsWmsRenderContext::Flag
Flag
Available rendering options.
Definition: qgswmsrendercontext.h:51
QgsWms::QgsWmsRenderContext::layerNickname
QString layerNickname(const QgsMapLayer &layer) const
Returns the nickname (short name, id or name) of the layer according to the current configuration.
Definition: qgswmsrendercontext.cpp:254
qgswmsparameters.h
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
QgsWms::QgsWmsRenderContext::isValidGroup
bool isValidGroup(const QString &name) const
Returns true if name is a group.
Definition: qgswmsrendercontext.cpp:295
QgsWms::QgsWmsRenderContext::scaleDenominator
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:220
QgsWms::QgsWmsRenderContext::layer
QgsMapLayer * layer(const QString &nickname) const
Returns the layer corresponding to the nickname, or a nullptr if not found or if the layer do not nee...
Definition: qgswmsrendercontext.cpp:269
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsWms::QgsWmsRenderContext::testFlag
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
Definition: qgswmsrendercontext.cpp:60
QgsWms::QgsWmsRenderContext::project
const QgsProject * project() const
Returns the project.
Definition: qgswmsrendercontext.cpp:75
QgsWms::QgsWmsRenderContext::mapTileBuffer
double mapTileBuffer(int mapWidth) const
Returns the tile buffer in geographical units for the given map width in pixels.
Definition: qgswmsrendercontext.cpp:660
QgsWms::QgsWmsRenderContext::UseSelection
@ UseSelection
Definition: qgswmsrendercontext.h:56
QgsWms::QgsWmsRenderContext::dotsPerMm
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
Definition: qgswmsrendercontext.cpp:158
QgsWms::QgsWmsRenderContext::UseScaleDenominator
@ UseScaleDenominator
Definition: qgswmsrendercontext.h:53
QgsWms::QgsWmsRenderContext::layersToRender
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
Definition: qgswmsrendercontext.cpp:210
QgsWms::QgsWmsRenderContext::UseTileBuffer
@ UseTileBuffer
Definition: qgswmsrendercontext.h:64
QgsWms::QgsWmsRenderContext::mapHeight
int mapHeight() const
Returns HEIGHT or SRCHEIGHT according to UseSrcWidthHeight flag.
Definition: qgswmsrendercontext.cpp:573
QgsWms::QgsWmsRenderContext::layers
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
Definition: qgswmsrendercontext.cpp:215
QgsServerInterface
Definition: qgsserverinterface.h:60
qgsproject.h
QgsWms::QgsWmsRenderContext::parameters
QgsWmsParameters parameters() const
Returns WMS parameters.
Definition: qgswmsrendercontext.cpp:65
QgsWms::QgsWmsRenderContext::UseOpacity
@ UseOpacity
Definition: qgswmsrendercontext.h:54
qgsserverinterface.h