QGIS API Documentation 3.43.0-Master (0cdc48caa8d)
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"
25#include "qgstextformat.h"
28
29class QgsRasterLayer;
31class QgsRasterPipe;
33class QgsRasterLayerRendererFeedback;
34
35#ifndef SIP_RUN
36
46{
47 public:
48
53
55 QList<QgsLabelFeature *> labelFeatures( QgsRenderContext & ) final;
56 void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const final;
57 void startRender( QgsRenderContext &context ) final;
58
62 void generateLabels( QgsRenderContext &context, QgsRasterPipe *pipe, QgsRasterViewPort *rasterViewPort, QgsRasterLayerRendererFeedback *feedback );
63
67 void addLabel( const QgsPoint &mapPoint, const QString &text, QgsRenderContext &context );
68
72 void setTextFormat( const QgsTextFormat &format );
73
79 void setNumericFormat( std::unique_ptr< QgsNumericFormat > format );
80
86 QgsNumericFormat *numericFormat();
87
93 int band() const { return mBandNumber; }
94
100 void setBand( int band ) { mBandNumber = band; }
101
107 void setPriority( double priority ) { mPriority = priority; }
108
112 void setPlacementSettings( const QgsLabelPlacementSettings &settings ) { mPlacementSettings = settings; }
113
119 void setZIndex( double index ) { mZIndex = index; }
120
124 void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
125
132 void setResampleMethod( Qgis::RasterResamplingMethod method );
133
140 void setResampleOver( int pixels );
141
142 private:
143 QgsTextFormat mFormat;
144 int mBandNumber = 1;
145 std::unique_ptr< QgsNumericFormat > mNumericFormat;
146
147 QgsLabelPlacementSettings mPlacementSettings;
148 QgsLabelThinningSettings mThinningSettings;
149 double mZIndex = 0;
150
152 int mResampleOver = 1;
153
154 QList<QgsLabelFeature *> mLabels;
155
156};
157
158#endif
159
160
161
169{
170 public:
171
172#ifdef SIP_RUN
174 if ( sipCpp->type() == "simple" )
175 sipType = sipType_QgsRasterLayerSimpleLabeling;
176 else
177 sipType = 0;
178 SIP_END
179#endif
180
183#ifndef SIP_RUN
188#endif
189
193 static QgsAbstractRasterLayerLabeling *defaultLabelingForLayer( QgsRasterLayer *layer ) SIP_FACTORY;
194
196 virtual QString type() const = 0;
197
200
206 virtual std::unique_ptr< QgsRasterLayerLabelProvider > provider( QgsRasterLayer *layer ) const = 0 SIP_SKIP;
207
213 virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0;
214
220 virtual bool requiresAdvancedEffects() const = 0;
221
233 virtual bool hasNonDefaultCompositionMode() const = 0;
234
241 virtual void multiplyOpacity( double opacityFactor );
242
248 virtual bool isInScaleRange( double scale ) const;
249
250 // static stuff
251
255 static QgsAbstractRasterLayerLabeling *createFromElement( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
256
260 virtual void toSld( QDomNode &parent, const QVariantMap &props ) const;
261
269 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
270
271 private:
272
273#ifdef SIP_RUN
275#endif
276
277};
278
279
287{
288 public:
289
292
293 QString type() const override;
294 QgsRasterLayerSimpleLabeling *clone() const override SIP_FACTORY;
295 std::unique_ptr< QgsRasterLayerLabelProvider > provider( QgsRasterLayer *layer ) const override SIP_SKIP;
296 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
297 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
298 bool requiresAdvancedEffects() const override;
299 bool hasNonDefaultCompositionMode() const override;
300 void multiplyOpacity( double opacityFactor ) override;
301
303 static QgsRasterLayerSimpleLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
304
310 QgsTextFormat textFormat() const;
311
317 void setTextFormat( const QgsTextFormat &format );
318
324 const QgsNumericFormat *numericFormat() const;
325
333 void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
334
340 int band() const { return mBandNumber; }
341
347 void setBand( int band ) { mBandNumber = band; }
348
358 double priority() const { return mPriority; }
359
367 void setPriority( double priority ) { mPriority = priority; }
368
374 const QgsLabelPlacementSettings &placementSettings() const { return mPlacementSettings; } SIP_SKIP
375
380 QgsLabelPlacementSettings &placementSettings() { return mPlacementSettings; }
381
386 void setPlacementSettings( const QgsLabelPlacementSettings &settings ) { mPlacementSettings = settings; }
387
393 const QgsLabelThinningSettings &thinningSettings() const { return mThinningSettings; } SIP_SKIP
394
399 QgsLabelThinningSettings &thinningSettings() { return mThinningSettings; }
400
405 void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
406
414 double zIndex() const;
415
423 void setZIndex( double index );
424
437 double maximumScale() const;
438
451 void setMaximumScale( double scale );
452
465 double minimumScale() const;
466
479 void setMinimumScale( double scale );
480
487 void setScaleBasedVisibility( bool enabled );
488
496 bool hasScaleBasedVisibility() const;
497
498 bool isInScaleRange( double scale ) const override;
499
507 Qgis::RasterResamplingMethod resampleMethod() const;
508
516 void setResampleMethod( Qgis::RasterResamplingMethod method );
517
525 int resampleOver() const;
526
534 void setResampleOver( int pixels );
535
536 private:
537 int mBandNumber = 1;
538
539 QgsTextFormat mTextFormat;
540
541 std::unique_ptr< QgsNumericFormat > mNumericFormat;
542
544 double mPriority = 0.5;
545
546 QgsLabelPlacementSettings mPlacementSettings;
547 QgsLabelThinningSettings mThinningSettings;
548
549 double mZIndex = 0;
550
551 bool mScaleVisibility = false;
552 double mMaximumScale = 0;
553 double mMinimumScale = 0;
554
556 int mResampleOver = 1;
557
558};
559
560
561
562#endif // QGSRASTERLABELING_H
RasterResamplingMethod
Resampling method for raster provider-level resampling.
Definition qgis.h:1447
@ Average
Average resampling.
An abstract interface class for label providers.
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.
virtual void startRender(QgsRenderContext &context)
To be called before rendering of labels begins.
Abstract base class for labeling settings for raster layers.
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 ...
QgsAbstractRasterLayerLabeling(const QgsAbstractRasterLayerLabeling &rhs)=delete
QgsAbstractRasterLayerLabeling cannot be copied, use clone() instead.
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:49
Implements labeling support for raster layers.
void setZIndex(double index)
Sets the Z-Index of the labels.
void setBand(int band)
Sest the raster band to use for label values.
void setPlacementSettings(const QgsLabelPlacementSettings &settings)
Sets the label placement settings.
void setPriority(double priority)
Sets the priority of labels.
int band() const
Returns the raster band to use for label values.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
Basic implementation of the labeling interface for raster layers.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
double priority() const
Returns the priority of labels.
~QgsRasterLayerSimpleLabeling() override
QgsLabelPlacementSettings & placementSettings()
Returns the label placement settings.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
void setPriority(double priority)
Sets the priority of labels.
QgsLabelThinningSettings & thinningSettings()
Returns the label thinning settings.
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.
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:191
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_ABSTRACT
Definition qgis_sip.h:213
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
This class provides details of the viewable area that a raster will be rendered into.