QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
35  {
36  public:
38  enum Flag
39  {
41  UseOpacity = 0x02,
42  UseFilter = 0x04,
43  UseSelection = 0x08,
45  UpdateExtent = 0x20,
51  UseTileBuffer = 0x800
52  };
53  Q_DECLARE_FLAGS( Flags, Flag )
54 
55 
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 
251  bool isExternalLayer( const QString &name ) const;
252 
253  private:
254  void initNicknameLayers();
255  void initRestrictedLayers();
256  void initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName );
257 
258  void searchLayersToRender();
259  void searchLayersToRenderSld();
260  void searchLayersToRenderStyle();
261  void removeUnwantedLayers();
262 
263  void checkLayerReadPermissions();
264 
265  bool layerScaleVisibility( const QString &name ) const;
266 
267  const QgsProject *mProject = nullptr;
268  QgsServerInterface *mInterface = nullptr;
269  QgsWmsParameters mParameters;
270  Flags mFlags = Flags();
271  double mScaleDenominator = -1.0;
272 
273  // nickname of all layers defined within the project
274  QMultiMap<QString, QgsMapLayer *> mNicknameLayers;
275 
276  // map of layers to use for rendering
277  QList<QgsMapLayer *> mLayersToRender;
278 
279  // list of layers which are not usable
280  QStringList mRestrictedLayers;
281 
282  QMap<QString, QList<QgsMapLayer *> > mLayerGroups;
283 
284  QMap<QString, QDomElement> mSlds;
285  QMap<QString, QString> mStyles;
286 
287  // list for external layers
288  QList<QgsMapLayer *> mExternalLayers;
289  };
290 };
291 
292 #endif
QgsWms::QgsWmsRenderContext::UpdateExtent
@ UpdateExtent
Definition: qgswmsrendercontext.h:45
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:324
QgsWms::QgsWmsRenderContext::mapWidth
int mapWidth() const
Returns WIDTH or SRCWIDTH according to UseSrcWidthHeight flag.
Definition: qgswmsrendercontext.cpp:578
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:297
QgsWms::QgsWmsRenderContext::isExternalLayer
bool isExternalLayer(const QString &name) const
Returns true if the layer is an external layer, false otherwise.
Definition: qgswmsrendercontext.cpp:793
QgsWms::QgsWmsRenderContext::style
QString style(const QgsMapLayer &layer) const
Returns a style's name for a specific layer.
Definition: qgswmsrendercontext.cpp:100
QgsWms::QgsWmsRenderContext::UseFilter
@ UseFilter
Definition: qgswmsrendercontext.h:42
QgsWms::QgsWmsRenderContext::setFlag
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
Definition: qgswmsrendercontext.cpp:55
QgsWms::QgsWmsRenderContext::setParameters
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
Definition: qgswmsrendercontext.cpp:41
QgsWms::QgsWmsRenderContext::updateExtent
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
Definition: qgswmsrendercontext.cpp:249
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:573
QgsWms::QgsWmsRenderContext::AddHighlightLayers
@ AddHighlightLayers
Definition: qgswmsrendercontext.h:44
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:604
QgsWms::QgsWmsRenderContext
Rendering context for the WMS renderer.
Definition: qgswmsrendercontext.h:35
QgsWms::QgsWmsRenderContext::AddQueryLayers
@ AddQueryLayers
Definition: qgswmsrendercontext.h:47
QgsWms::QgsWmsRenderContext::imageQuality
int imageQuality() const
Returns the image quality to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:129
QgsWms::QgsWmsRenderContext::AddExternalLayers
@ AddExternalLayers
Definition: qgswmsrendercontext.h:49
QgsWms::QgsWmsParametersLayer
Definition: qgswmsparameters.h:50
QgsWms::QgsWmsRenderContext::QgsWmsRenderContext
QgsWmsRenderContext(const QgsProject *project, QgsServerInterface *interface)
Constructor for QgsWmsRenderContext.
Definition: qgswmsrendercontext.cpp:28
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsServerSettings
Provides a way to retrieve settings by prioritizing according to environment variables,...
Definition: qgsserversettings.h:85
QgsWms::QgsWmsRenderContext::UseSrcWidthHeight
@ UseSrcWidthHeight
Definition: qgswmsrendercontext.h:50
QgsWms::QgsWmsRenderContext::tileBuffer
int tileBuffer() const
Returns the tile buffer value to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:141
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:698
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:180
QgsWms::QgsWmsRenderContext::setScaleDenominator
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
Definition: qgswmsrendercontext.cpp:243
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:35
QgsWms::QgsWmsRenderContext::SetAccessControl
@ SetAccessControl
Definition: qgswmsrendercontext.h:46
QgsWms::QgsWmsRenderContext::UseWfsLayersOnly
@ UseWfsLayersOnly
Definition: qgswmsrendercontext.h:48
QgsWms::QgsWmsRenderContext::settings
const QgsServerSettings & settings() const
Returns settings of the server.
Definition: qgswmsrendercontext.cpp:77
QgsWms::QgsWmsRenderContext::isValidLayer
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
Definition: qgswmsrendercontext.cpp:292
QgsWms::QgsWmsRenderContext::precision
int precision() const
Returns the precision to use according to the current configuration.
Definition: qgswmsrendercontext.cpp:153
QgsWms::QgsWmsRenderContext::sld
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
Definition: qgswmsrendercontext.cpp:87
QgsWms::QgsWmsRenderContext::Flag
Flag
Available rendering options.
Definition: qgswmsrendercontext.h:39
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:261
qgswmsparameters.h
QgsAccessControl
A helper class that centralizes restrictions given by all the access control filter plugins.
Definition: qgsaccesscontrol.h:37
QgsWms
Median cut implementation.
Definition: qgsdxfwriter.cpp:23
QgsWms::QgsWmsRenderContext::isValidGroup
bool isValidGroup(const QString &name) const
Returns true if name is a group.
Definition: qgswmsrendercontext.cpp:302
QgsWms::QgsWmsRenderContext::scaleDenominator
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:227
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:276
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsWms::QgsWmsRenderContext::testFlag
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
Definition: qgswmsrendercontext.cpp:67
QgsWms::QgsWmsRenderContext::project
const QgsProject * project() const
Returns the project.
Definition: qgswmsrendercontext.cpp:82
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:678
QgsWms::QgsWmsRenderContext::~QgsWmsRenderContext
~QgsWmsRenderContext()
Destructor for QgsWmsRenderContext.
Definition: qgswmsrendercontext.cpp:35
QgsWms::QgsWmsRenderContext::UseSelection
@ UseSelection
Definition: qgswmsrendercontext.h:43
QgsWms::QgsWmsRenderContext::dotsPerMm
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
Definition: qgswmsrendercontext.cpp:165
QgsWms::QgsWmsRenderContext::UseScaleDenominator
@ UseScaleDenominator
Definition: qgswmsrendercontext.h:40
QgsWms::QgsWmsRenderContext::layersToRender
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
Definition: qgswmsrendercontext.cpp:217
QgsWms::QgsWmsRenderContext::UseTileBuffer
@ UseTileBuffer
Definition: qgswmsrendercontext.h:51
QgsWms::QgsWmsRenderContext::mapHeight
int mapHeight() const
Returns HEIGHT or SRCHEIGHT according to UseSrcWidthHeight flag.
Definition: qgswmsrendercontext.cpp:591
QgsWms::QgsWmsRenderContext::layers
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
Definition: qgswmsrendercontext.cpp:222
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:61
qgsproject.h
QgsWms::QgsWmsRenderContext::parameters
QgsWmsParameters parameters() const
Returns WMS parameters.
Definition: qgswmsrendercontext.cpp:72
QgsWms::QgsWmsRenderContext::UseOpacity
@ UseOpacity
Definition: qgswmsrendercontext.h:41
qgsserverinterface.h