QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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  };
52  Q_DECLARE_FLAGS( Flags, Flag )
53 
54 
57  QgsWmsRenderContext() = default;
58 
65 
70 
75 
79  const QgsServerSettings &settings() const;
80 
84  const QgsProject *project() const;
85 
89  void setFlag( Flag flag, bool on = true );
90 
96  bool testFlag( Flag flag ) const;
97 
101  QList<QgsMapLayer *> layers() const;
102 
107  QList<QgsMapLayer *> layersToRender() const;
108 
113  QDomElement sld( const QgsMapLayer &layer ) const;
114 
119  QString style( const QgsMapLayer &layer ) const;
120 
125  double scaleDenominator() const;
126 
131  void setScaleDenominator( double scaleDenominator );
132 
137  bool updateExtent() const;
138 
144 
149  int imageQuality() const;
150 
154  int precision() const;
155 
160  QString layerNickname( const QgsMapLayer &layer ) const;
161 
166  QgsMapLayer *layer( const QString &nickname ) const;
167 
171  bool isValidLayer( const QString &nickname ) const;
172 
176  bool isValidGroup( const QString &name ) const;
177 
181  qreal dotsPerMm() const;
182 
187  QStringList flattenedQueryLayers() const;
188 
189 #ifdef HAVE_SERVER_PYTHON_PLUGINS
190 
194  QgsAccessControl *accessControl() const;
195 #endif
196 
201  QMap<QString, QList<QgsMapLayer *> > layerGroups() const;
202 
208  QSize mapSize( bool aspectRatio = true ) const;
209 
215  bool isValidWidthHeight() const;
216 
220  int mapWidth() const;
221 
225  int mapHeight() const;
226 
227  private:
228  void initNicknameLayers();
229  void initRestrictedLayers();
230  void initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName );
231 
232  void searchLayersToRender();
233  void searchLayersToRenderSld();
234  void searchLayersToRenderStyle();
235  void removeUnwantedLayers();
236 
237  void checkLayerReadPermissions();
238 
239  bool layerScaleVisibility( const QString &name ) const;
240 
241  const QgsProject *mProject = nullptr;
242  QgsServerInterface *mInterface = nullptr;
243  QgsWmsParameters mParameters;
244  Flags mFlags = nullptr;
245  double mScaleDenominator = -1.0;
246 
247  // nickname of all layers defined within the project
248  QMap<QString, QgsMapLayer *> mNicknameLayers;
249 
250  // map of layers to use for rendering
251  QList<QgsMapLayer *> mLayersToRender;
252 
253  // list of layers which are not usable
254  QStringList mRestrictedLayers;
255 
256  QMap<QString, QList<QgsMapLayer *> > mLayerGroups;
257 
258  QMap<QString, QDomElement> mSlds;
259  QMap<QString, QString> mStyles;
260  };
261 };
262 
263 #endif
Layer tree group node serves as a container for layers and further groups.
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
Base class for all map layer types.
Definition: qgsmaplayer.h:78
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
QgsWmsParameters parameters() const
Returns WMS parameters.
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
Provides a way to retrieve settings by prioritizing according to environment variables, ini file and default values.
QMap< QString, QList< QgsMapLayer * > > layerGroups() const
Returns a map having layer group names as keys and a list of layers as values.
QStringList flattenedQueryLayers() const
Returns a list of query layer names where group names are replaced by the names of their layer compon...
int imageQuality() const
Returns the image quality to use for rendering according to the current configuration.
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
QgsWmsRenderContext()=default
Default constructor for QgsWmsRenderContext.
bool isValidWidthHeight() const
Returns true if width and height are valid according to the maximum values defined within the project...
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
Provides an interface to retrieve and manipulate WMS parameters received from the client...
Reads and writes project states.
Definition: qgsproject.h:89
Flag
Available rendering options.
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
const QgsServerSettings & settings() const
Returns settings of the server.
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...
const QgsProject * project() const
Returns the project.
Median cut implementation.
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
QString layerNickname(const QgsMapLayer &layer) const
Returns the nickname (short name, id or name) of the layer according to the current configuration...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
bool isValidGroup(const QString &name) const
Returns true if name is a group.
int precision() const
Returns the precision to use according to the current configuration.
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
Rendering context for the WMS renderer.
int mapHeight() const
Returns HEIGHT or SRCHEIGHT according to UseSrcWidthHeight flag.
A helper class that centralizes restrictions given by all the access control filter plugins...
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...
QString style(const QgsMapLayer &layer) const
Returns a style&#39;s name for a specific layer.
int mapWidth() const
Returns WIDTH or SRCWIDTH according to UseSrcWidthHeight flag.