53 const QString format = request.
parameters().value( QStringLiteral(
"FORMAT" ), QStringLiteral(
"PNG" ) );
58 switch ( outputFormat )
64 contentType =
"image/png";
68 contentType =
"image/jpeg";
73 QStringLiteral(
"Output format '%1' is not supported in the GetLegendGraphic request" ).arg( format ) );
78 #ifdef HAVE_SERVER_PYTHON_PLUGINS 84 QByteArray content = cacheManager->
getCachedImage( project, request, accessControl );
85 if ( !content.isEmpty() && image.loadFromData( content ) )
87 response.
setHeader( QStringLiteral(
"Content-Type" ), contentType );
88 image.save( response.
io(), qPrintable( saveFormat ) );
96 std::unique_ptr<QgsLayerTree> tree(
layerTree( context ) );
97 std::unique_ptr<QgsLayerTreeModel> model(
legendModel( context, *tree.get() ) );
100 std::unique_ptr<QImage> result;
101 if ( !parameters.
rule().isEmpty() )
116 #ifdef HAVE_SERVER_PYTHON_PLUGINS 119 QByteArray content = response.
data();
120 if ( !content.isEmpty() )
121 cacheManager->
setCachedImage( &content, project, request, accessControl );
127 throw QgsException( QStringLiteral(
"Failed to compute GetLegendGraphics image" ) );
139 if ( parameters.
format() == QgsWmsParameters::Format::NONE )
145 if ( ! parameters.
bbox().isEmpty() && !parameters.
rule().isEmpty() )
148 QStringLiteral(
"BBOX parameter cannot be combined with RULE." ) );
169 if ( ! parameters.
bbox().isEmpty() )
188 if ( symbols[vl].contains( prop ) )
196 if ( order.isEmpty() )
203 model->refreshLayerLegend( layer );
209 if ( parameters.
rule().isEmpty() )
211 QList<QgsLayerTreeNode *> children = tree.
children();
242 return model.release();
247 std::unique_ptr<QgsLayerTree> tree(
new QgsLayerTree() );
249 QList<QgsVectorLayerFeatureCounter *> counters;
256 if ( !ml->title().isEmpty() )
261 const QString
property = QStringLiteral(
"showFeatureCount" );
272 counters.append( counter );
280 return tree.release();
289 if ( node->data( Qt::DisplayRole ).toString().compare( rule ) == 0 )
static void setNodeLegendStyle(QgsLayerTreeNode *node, QgsLegendStyle::Style style)
Sets the style of a node.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Base class for all map layer types.
virtual bool isEmbeddedInParent() const
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
HitTest symbols()
Returns the hit test according to the current context.
static void setLegendNodeOrder(QgsLayerTreeLayer *nodeLayer, const QList< int > &order)
QgsVectorLayerFeatureCounter * countSymbolFeatures()
Count features for symbols.
void setUseLayerName(bool use=true)
Uses the layer's name if use is true, or the name manually set if false.
QgsWmsParameters parameters() const
Returns WMS parameters.
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
bool setCachedImage(const QByteArray *img, const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl) const
Updates or inserts the image in cache like tiles.
Counts the features in a QgsVectorLayer in task.
QgsLayerTree * layerTree(const QgsWmsRenderContext &context)
bool waitForFinished(int timeout=30000)
Blocks the current thread until the task finishes or a maximum of timeout milliseconds.
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group.
Exception thrown in case of malformed request.
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 ¶meters)
Sets WMS parameters.
QString bbox() const
Returns BBOX if defined or an empty string.
bool ruleLabelAsBool() const
Returns RULELABEL as a bool.
Exception class for WMS service exceptions.
bool showFeatureCountAsBool() const
Returns SHOWFEATURECOUNT as a bool.
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QHash< QgsVectorLayer *, SymbolSet > HitTest
QStringList allLayersNickname() const
Returns nickname of layers found in LAYER and LAYERS parameters.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
Namespace with helper functions for layer tree operations.
bool isEmpty() const
Returns true if the rectangle is empty.
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
Provides an interface to retrieve and manipulate WMS parameters received from the client...
A helper class that centralizes caches accesses given by all the server cache filter plugins...
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
This class is a base class for nodes in a layer tree.
Reads and writes project states.
QgsFeatureRenderer * renderer()
Returns renderer.
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
Format format() const
Returns format.
void writeGetLegendGraphics(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetLegendGRaphics response.
void setName(const QString &n) override
Sets the layer's name.
bool layerTitleAsBool() const
Returns LAYERTITLE as a bool or its default value if not defined.
Median cut implementation.
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
virtual QByteArray data() const =0
Gets the data written so far.
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
void checkParameters(const QgsWmsParameters ¶meters)
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
Special style, item is hidden including margins around.
virtual void setEmbeddedInParent(bool embedded)
Map renderer for WMS requests.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QgsLayerTreeModel * legendModel(const QgsWmsRenderContext &context, QgsLayerTree &tree)
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
virtual QIODevice * io()=0
Returns the underlying QIODevice.
Rendering context for the WMS renderer.
virtual QgsServerCacheManager * cacheManager() const =0
Gets the registered server cache filters.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
QList< QgsLayerTreeModelLegendNode * > layerLegendNodes(QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent=false)
Returns filtered list of active legend nodes attached to a particular layer node (by default it retur...
A helper class that centralizes restrictions given by all the access control filter plugins...
ImageOutputFormat
Supported image output format.
QString rule() const
Returns RULE parameter or an empty string if none is defined.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
Represents a vector layer which manages a vector based data sets.
Defines a QGIS exception class.
ImageOutputFormat parseImageFormat(const QString &format)
Parse image format parameter.
virtual void setUserLabel(const QString &userLabel)
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file...
Layer tree node points to a map layer.
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
QByteArray getCachedImage(const QgsProject *project, const QgsServerRequest &request, QgsAccessControl *accessControl) const
Returns cached image (or 0 if image not in cache) like tiles.