QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsrasterlabeling.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterlabeling.h
3 ---------------
4 begin : December 2024
5 copyright : (C) 2024 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
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
19#ifndef QGSRASTERLABELING_H
20#define QGSRASTERLABELING_H
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgslabelingengine.h"
27#include "qgstextformat.h"
28
29class QgsRasterLayer;
31class QgsRasterPipe;
33class QgsRasterLayerRendererFeedback;
34
35#ifndef SIP_RUN
36
46{
47 public:
52
54 QList<QgsLabelFeature *> labelFeatures( QgsRenderContext & ) final;
55 void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const final;
56 void startRender( QgsRenderContext &context ) final;
57
61 void generateLabels( QgsRenderContext &context, QgsRasterPipe *pipe, QgsRasterViewPort *rasterViewPort, QgsRasterLayerRendererFeedback *feedback );
62
66 void addLabel( const QgsPoint &mapPoint, const QString &text, QgsRenderContext &context );
67
71 void setTextFormat( const QgsTextFormat &format );
72
78 void setNumericFormat( std::unique_ptr< QgsNumericFormat > format );
79
86
92 int band() const { return mBandNumber; }
93
99 void setBand( int band ) { mBandNumber = band; }
100
107
111 void setPlacementSettings( const QgsLabelPlacementSettings &settings ) { mPlacementSettings = settings; }
112
118 void setZIndex( double index ) { mZIndex = index; }
119
123 void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
124
131 void setResampleMethod( Qgis::RasterResamplingMethod method );
132
139 void setResampleOver( int pixels );
140
141 private:
142 QgsTextFormat mFormat;
143 int mBandNumber = 1;
144 std::unique_ptr< QgsNumericFormat > mNumericFormat;
145
146 QgsLabelPlacementSettings mPlacementSettings;
147 QgsLabelThinningSettings mThinningSettings;
148 double mZIndex = 0;
149
151 int mResampleOver = 1;
152
153 QList<QgsLabelFeature *> mLabels;
154};
155
156#endif
157
158
166{
167 public:
168#ifdef SIP_RUN
170 if ( sipCpp->type() == "simple" )
171 sipType = sipType_QgsRasterLayerSimpleLabeling;
172 else
173 sipType = 0;
174 SIP_END
175#endif
176
178 = default;
180#ifndef SIP_RUN
185#endif
186
191
193 virtual QString type() const = 0;
194
197
203 virtual std::unique_ptr< QgsRasterLayerLabelProvider > provider( QgsRasterLayer *layer ) const SIP_SKIP = 0;
204
210 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
211
217 virtual bool requiresAdvancedEffects() const = 0;
218
230 virtual bool hasNonDefaultCompositionMode() const = 0;
231
238 virtual void multiplyOpacity( double opacityFactor );
239
245 virtual bool isInScaleRange( double scale ) const;
246
247 // static stuff
248
252 static QgsAbstractRasterLayerLabeling *createFromElement( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
253
257 virtual void toSld( QDomNode &parent, const QVariantMap &props ) const;
258
266 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
267
268 private:
269#ifdef SIP_RUN
271#endif
272};
273
274
282{
283 public:
286
287 QString type() const override;
289 std::unique_ptr< QgsRasterLayerLabelProvider > provider( QgsRasterLayer *layer ) const override SIP_SKIP;
290 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
291 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
292 bool requiresAdvancedEffects() const override;
293 bool hasNonDefaultCompositionMode() const override;
294 void multiplyOpacity( double opacityFactor ) override;
295
297 static QgsRasterLayerSimpleLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
298
305
311 void setTextFormat( const QgsTextFormat &format );
312
318 const QgsNumericFormat *numericFormat() const;
319
328
334 int band() const { return mBandNumber; }
335
341 void setBand( int band ) { mBandNumber = band; }
342
352 double priority() const { return mPriority; }
353
361 void setPriority( double priority ) { mPriority = priority; }
362
368 const QgsLabelPlacementSettings &placementSettings() const { return mPlacementSettings; }
370
377 {
378 return mPlacementSettings;
379 }
380
385 void setPlacementSettings( const QgsLabelPlacementSettings &settings ) { mPlacementSettings = settings; }
386
392 const QgsLabelThinningSettings &thinningSettings() const { return mThinningSettings; }
394
401 {
402 return mThinningSettings;
403 }
404
409 void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
410
418 double zIndex() const;
419
427 void setZIndex( double index );
428
441 double maximumScale() const;
442
455 void setMaximumScale( double scale );
456
469 double minimumScale() const;
470
483 void setMinimumScale( double scale );
484
491 void setScaleBasedVisibility( bool enabled );
492
500 bool hasScaleBasedVisibility() const;
501
502 bool isInScaleRange( double scale ) const override;
503
511 Qgis::RasterResamplingMethod resampleMethod() const;
512
520 void setResampleMethod( Qgis::RasterResamplingMethod method );
521
529 int resampleOver() const;
530
538 void setResampleOver( int pixels );
539
540 private:
541 int mBandNumber = 1;
542
543 QgsTextFormat mTextFormat;
544
545 std::unique_ptr< QgsNumericFormat > mNumericFormat;
546
548 double mPriority = 0.5;
549
550 QgsLabelPlacementSettings mPlacementSettings;
551 QgsLabelThinningSettings mThinningSettings;
552
553 double mZIndex = 0;
554
555 bool mScaleVisibility = false;
556 double mMaximumScale = 0;
557 double mMinimumScale = 0;
558
560 int mResampleOver = 1;
561};
562
563
564#endif // QGSRASTERLABELING_H
RasterResamplingMethod
Resampling method for raster provider-level resampling.
Definition qgis.h:1562
@ Average
Average resampling.
Definition qgis.h:1568
virtual QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context)=0
Returns list of label features (they are owned by the provider and thus deleted on its destruction).
virtual void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const =0
Draw this label at the position determined by the labeling engine.
double priority() const
Default priority of labels (may be overridden by individual labels).
double mPriority
Default priority of labels. 0 = highest priority, 1 = lowest priority.
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
virtual void startRender(QgsRenderContext &context)
To be called before rendering of labels begins.
QgsAbstractLabelProvider(QgsMapLayer *layer, const QString &providerId=QString())
Construct the provider with default values.
virtual std::unique_ptr< QgsRasterLayerLabelProvider > provider(QgsRasterLayer *layer) const =0
Creates a raster label provider corresponding to this object's configuration.
virtual bool hasNonDefaultCompositionMode() const =0
Returns true the labeling requires a non-default composition mode.
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
QgsAbstractRasterLayerLabeling & operator=(const QgsAbstractRasterLayerLabeling &rhs)=delete
QgsAbstractRasterLayerLabeling cannot be copied, use clone() instead.
virtual QgsAbstractRasterLayerLabeling * clone() const =0
Returns a new copy of the object.
virtual ~QgsAbstractRasterLayerLabeling()=default
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const =0
Saves the labeling configuration to an XML element.
virtual bool requiresAdvancedEffects() const =0
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
virtual bool isInScaleRange(double scale) const
Tests whether the labels should be visible at the specified scale.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
virtual void toSld(QDomNode &parent, const QVariantMap &props) const
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
static QgsAbstractRasterLayerLabeling * createFromElement(const QDomElement &element, const QgsReadWriteContext &context)
Tries to create an instance of an implementation based on the XML data.
QgsAbstractRasterLayerLabeling(const QgsAbstractRasterLayerLabeling &rhs)=delete
QgsAbstractRasterLayerLabeling cannot be copied, use clone() instead.
virtual void multiplyOpacity(double opacityFactor)
Multiply opacity by opacityFactor.
static QgsAbstractRasterLayerLabeling * defaultLabelingForLayer(QgsRasterLayer *layer)
Creates default labeling for a raster layer.
Contains general settings related to how labels are placed.
Contains settings related to how the label engine removes candidate label positions and reduces the n...
Abstract base class for numeric formatters, which allow for formatting a numeric value for display.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Implements labeling support for raster layers.
void setZIndex(double index)
Sets the Z-Index of the labels.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for rendering the labels.
QgsRasterLayerLabelProvider(QgsRasterLayer *layer)
Constructor for QgsRasterLayerLabelProvider.
void setBand(int band)
Sest the raster band to use for label values.
void addLabel(const QgsPoint &mapPoint, const QString &text, QgsRenderContext &context)
Adds a label at the specified point in map coordinates.
QgsNumericFormat * numericFormat()
Returns the numeric format to be used for the labels.
void setPlacementSettings(const QgsLabelPlacementSettings &settings)
Sets the label placement settings.
void generateLabels(QgsRenderContext &context, QgsRasterPipe *pipe, QgsRasterViewPort *rasterViewPort, QgsRasterLayerRendererFeedback *feedback)
Generates the labels, given a render context and input pipe.
void setPriority(double priority)
Sets the priority of labels.
int band() const
Returns the raster band to use for label values.
void setNumericFormat(std::unique_ptr< QgsNumericFormat > format)
Sets the numeric format used for the labels.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for rendering the labels.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
int band() const
Returns the raster band to use for label values.
static QgsRasterLayerSimpleLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Creates a QgsRasterLayerSimpleLabeling from a DOM element with saved configuration.
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for the labels.
double priority() const
Returns the priority of labels.
~QgsRasterLayerSimpleLabeling() override
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
std::unique_ptr< QgsRasterLayerLabelProvider > provider(QgsRasterLayer *layer) const override
Creates a raster label provider corresponding to this object's configuration.
QgsLabelPlacementSettings & placementSettings()
Returns the label placement settings.
QgsTextFormat textFormat() const
Returns the text format used for rendering the labels.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
void setPriority(double priority)
Sets the priority of labels.
void multiplyOpacity(double opacityFactor) override
Multiply opacity by opacityFactor.
QString type() const override
Unique type string of the labeling configuration implementation.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Saves the labeling configuration to an XML element.
QgsRasterLayerSimpleLabeling * clone() const override
Returns a new copy of the object.
QgsLabelThinningSettings & thinningSettings()
Returns the label thinning settings.
bool hasNonDefaultCompositionMode() const override
Returns true the labeling requires a non-default composition mode.
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for the labels.
void setPlacementSettings(const QgsLabelPlacementSettings &settings)
Sets the label placement settings.
void setBand(int band)
Sest the raster band to use for label values.
const QgsLabelThinningSettings & thinningSettings() const
Returns the label thinning settings.
bool requiresAdvancedEffects() const override
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
Represents a raster layer.
Contains a pipeline of raster interfaces for sequential raster processing.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
Container for all settings relating to text rendering.
LabelPosition is a candidate feature label position.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_ABSTRACT
Definition qgis_sip.h:220
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
This class provides details of the viewable area that a raster will be rendered into.