QGIS API Documentation 3.41.0-Master (af5edcb665c)
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"
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
228 virtual void multiplyOpacity( double opacityFactor );
229
235 virtual bool isInScaleRange( double scale ) const;
236
237 // static stuff
238
242 static QgsAbstractRasterLayerLabeling *createFromElement( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
243
247 virtual void toSld( QDomNode &parent, const QVariantMap &props ) const;
248
256 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
257
258 private:
259
260#ifdef SIP_RUN
262#endif
263
264};
265
266
274{
275 public:
276
279
280 QString type() const override;
281 QgsRasterLayerSimpleLabeling *clone() const override SIP_FACTORY;
282 std::unique_ptr< QgsRasterLayerLabelProvider > provider( QgsRasterLayer *layer ) const override SIP_SKIP;
283 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
284 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
285 bool requiresAdvancedEffects() const override;
286 void multiplyOpacity( double opacityFactor ) override;
287
289 static QgsRasterLayerSimpleLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
290
296 QgsTextFormat textFormat() const;
297
303 void setTextFormat( const QgsTextFormat &format );
304
310 const QgsNumericFormat *numericFormat() const;
311
319 void setNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
320
326 int band() const { return mBandNumber; }
327
333 void setBand( int band ) { mBandNumber = band; }
334
344 double priority() const { return mPriority; }
345
353 void setPriority( double priority ) { mPriority = priority; }
354
360 const QgsLabelPlacementSettings &placementSettings() const { return mPlacementSettings; } SIP_SKIP
361
366 QgsLabelPlacementSettings &placementSettings() { return mPlacementSettings; }
367
372 void setPlacementSettings( const QgsLabelPlacementSettings &settings ) { mPlacementSettings = settings; }
373
379 const QgsLabelThinningSettings &thinningSettings() const { return mThinningSettings; } SIP_SKIP
380
385 QgsLabelThinningSettings &thinningSettings() { return mThinningSettings; }
386
391 void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
392
400 double zIndex() const;
401
409 void setZIndex( double index );
410
423 double maximumScale() const;
424
437 void setMaximumScale( double scale );
438
451 double minimumScale() const;
452
465 void setMinimumScale( double scale );
466
473 void setScaleBasedVisibility( bool enabled );
474
482 bool hasScaleBasedVisibility() const;
483
484 bool isInScaleRange( double scale ) const override;
485
493 Qgis::RasterResamplingMethod resampleMethod() const;
494
502 void setResampleMethod( Qgis::RasterResamplingMethod method );
503
511 int resampleOver() const;
512
520 void setResampleOver( int pixels );
521
522 private:
523 int mBandNumber = 1;
524
525 QgsTextFormat mTextFormat;
526
527 std::unique_ptr< QgsNumericFormat > mNumericFormat;
528
530 double mPriority = 0.5;
531
532 QgsLabelPlacementSettings mPlacementSettings;
533 QgsLabelThinningSettings mThinningSettings;
534
535 double mZIndex = 0;
536
537 bool mScaleVisibility = false;
538 double mMaximumScale = 0;
539 double mMinimumScale = 0;
540
542 int mResampleOver = 1;
543
544};
545
546
547
548#endif // QGSRASTERLABELING_H
RasterResamplingMethod
Resampling method for raster provider-level resampling.
Definition qgis.h:1394
@ Average
Average resampling.
The QgsAbstractLabelProvider class is an interface class.
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 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...
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
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.
The class is used as a container of context for various read/write operations on other 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.