QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  AddAllLayers = 0x1000
53  };
54  Q_DECLARE_FLAGS( Flags, Flag )
55 
56 
60 
67 
72 
77 
81  const QgsServerSettings &settings() const;
82 
86  const QgsProject *project() const;
87 
91  void setFlag( Flag flag, bool on = true );
92 
98  bool testFlag( Flag flag ) const;
99 
103  QList<QgsMapLayer *> layers() const;
104 
109  QList<QgsMapLayer *> layersToRender() const;
110 
115  QDomElement sld( const QgsMapLayer &layer ) const;
116 
121  QString style( const QgsMapLayer &layer ) const;
122 
127  double scaleDenominator() const;
128 
133  void setScaleDenominator( double scaleDenominator );
134 
139  bool updateExtent() const;
140 
146 
151  int imageQuality() const;
152 
158  int tileBuffer() const;
159 
169  bool renderMapTiles() const;
170 
174  int precision() const;
175 
180  QString layerNickname( const QgsMapLayer &layer ) const;
181 
186  QgsMapLayer *layer( const QString &nickname ) const;
187 
191  bool isValidLayer( const QString &nickname ) const;
192 
197  QList<QgsMapLayer *> layersFromGroup( const QString &nickname ) const;
198 
202  bool isValidGroup( const QString &name ) const;
203 
207  qreal dotsPerMm() const;
208 
213  QStringList flattenedQueryLayers( const QStringList &layerNames ) const;
214 
215 #ifdef HAVE_SERVER_PYTHON_PLUGINS
216 
220  QgsAccessControl *accessControl() const;
221 #endif
222 
227  QMap<QString, QList<QgsMapLayer *> > layerGroups() const;
228 
233  double mapTileBuffer( int mapWidth ) const;
234 
240  QSize mapSize( bool aspectRatio = true ) const;
241 
247  bool isValidWidthHeight() const;
248 
255  bool isValidWidthHeight( int width, int height ) const;
256 
260  int mapWidth() const;
261 
265  int mapHeight() const;
266 
271  bool isExternalLayer( const QString &name ) const;
272 
273  private:
274  void initNicknameLayers();
275  void initRestrictedLayers();
276  void initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName );
277 
278  void searchLayersToRender();
279  void searchLayersToRenderSld();
280  void searchLayersToRenderStyle();
281  void removeUnwantedLayers();
282 
283  void checkLayerReadPermissions();
284 
285  bool layerScaleVisibility( const QString &name ) const;
286 
287  const QgsProject *mProject = nullptr;
288  QgsServerInterface *mInterface = nullptr;
289  QgsWmsParameters mParameters;
290  Flags mFlags = Flags();
291  double mScaleDenominator = -1.0;
292 
293  // nickname of all layers defined within the project
294  QMultiMap<QString, QgsMapLayer *> mNicknameLayers;
295 
296  // map of layers to use for rendering
297  QList<QgsMapLayer *> mLayersToRender;
298 
299  // list of layers which are not usable
300  QStringList mRestrictedLayers;
301 
302  QMap<QString, QList<QgsMapLayer *> > mLayerGroups;
303 
304  QMap<QString, QDomElement> mSlds;
305  QMap<QString, QString> mStyles;
306 
307  // list for external layers
308  QList<QgsMapLayer *> mExternalLayers;
309  };
310 };
311 
312 #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:346
QgsWms::QgsWmsRenderContext::mapWidth
int mapWidth() const
Returns WIDTH or SRCWIDTH according to UseSrcWidthHeight flag.
Definition: qgswmsrendercontext.cpp:606
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:310
QgsWms::QgsWmsRenderContext::isExternalLayer
bool isExternalLayer(const QString &name) const
Returns true if the layer is an external layer, false otherwise.
Definition: qgswmsrendercontext.cpp:826
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: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: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:256
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:601
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:632
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:131
QgsWms::QgsWmsRenderContext::AddExternalLayers
@ AddExternalLayers
Definition: qgswmsrendercontext.h:62
QgsWms::QgsWmsParametersLayer
Definition: qgswmsparameters.h:62
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:103
QgsServerSettings
Provides a way to retrieve settings by prioritizing according to environment variables,...
Definition: qgsserversettings.h:92
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:143
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:731
QgsWms::QgsWmsRenderContext::setScaleDenominator
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
Definition: qgswmsrendercontext.cpp:250
QgsWms::QgsWmsRenderContext::AddAllLayers
@ AddAllLayers
For GetPrint: add layers from LAYER(S) parameter.
Definition: qgswmsrendercontext.h:65
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:40
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:77
QgsWms::QgsWmsRenderContext::isValidLayer
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
Definition: qgswmsrendercontext.cpp:305
QgsWms::QgsWmsRenderContext::precision
int precision() const
Returns the precision to use according to the current configuration.
Definition: qgswmsrendercontext.cpp:160
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: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:268
qgswmsparameters.h
QgsWms::QgsWmsRenderContext::renderMapTiles
bool renderMapTiles() const
Returns true if WMS requests should use the QgsMapSettings::RenderMapTile flag, so that no visible ar...
Definition: qgswmsrendercontext.cpp:155
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
QgsWms::QgsWmsRenderContext::isValidGroup
bool isValidGroup(const QString &name) const
Returns true if name is a group.
Definition: qgswmsrendercontext.cpp:315
QgsWms::QgsWmsRenderContext::scaleDenominator
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:234
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:289
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
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:711
QgsWms::QgsWmsRenderContext::~QgsWmsRenderContext
~QgsWmsRenderContext()
Destructor for QgsWmsRenderContext.
Definition: qgswmsrendercontext.cpp:35
QgsWms::QgsWmsRenderContext::flattenedQueryLayers
QStringList flattenedQueryLayers(const QStringList &layerNames) const
Returns a list of query layer names where group names are replaced by the names of their layer compon...
Definition: qgswmsrendercontext.cpp:187
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:172
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:224
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:619
QgsWms::QgsWmsRenderContext::layers
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
Definition: qgswmsrendercontext.cpp:229
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
qgsproject.h
QgsWms::QgsWmsRenderContext::parameters
QgsWmsParameters parameters() const
Returns WMS parameters.
Definition: qgswmsrendercontext.cpp:72
QgsWms::QgsWmsRenderContext::UseOpacity
@ UseOpacity
Definition: qgswmsrendercontext.h:54
qgsserverinterface.h