QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgslabelingenginerule.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslabelingenginerule.h
3 ---------------------
4 Date : August 2024
5 Copyright : (C) 2024 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSLABELINGENGINERULE_H
16#define QGSLABELINGENGINERULE_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgis.h"
21#include "qgsgeometry.h"
22
24class QDomDocument;
25class QDomElement;
27class QgsProject;
28#ifndef SIP_RUN
29namespace pal
30{
31 class LabelPosition;
32}
33#endif
34
40class CORE_EXPORT QgsLabelingEngineContext
41{
42 public:
43
48
49#ifndef SIP_RUN
52#endif
53
57 QgsRenderContext &renderContext() { return mRenderContext; }
58
63 const QgsRenderContext &renderContext() const { return mRenderContext; } SIP_SKIP
64
71 QgsRectangle extent() const;
72
79 void setExtent( const QgsRectangle &extent );
80
93 QgsGeometry mapBoundaryGeometry() const;
94
107 void setMapBoundaryGeometry( const QgsGeometry &geometry );
108
109 private:
110
111#ifdef SIP_RUN
113#endif
114
115 QgsRenderContext &mRenderContext;
116 QgsRectangle mExtent;
117 QgsGeometry mMapBoundaryGeometry;
118};
119
133{
134
135#ifdef SIP_RUN
137 if ( sipCpp->id() == "minimumDistanceLabelToFeature" )
138 {
139 sipType = sipType_QgsLabelingEngineRuleMinimumDistanceLabelToFeature;
140 }
141 else if ( sipCpp->id() == "minimumDistanceLabelToLabel" )
142 {
143 sipType = sipType_QgsLabelingEngineRuleMinimumDistanceLabelToLabel;
144 }
145 else if ( sipCpp->id() == "maximumDistanceLabelToFeature" )
146 {
147 sipType = sipType_QgsLabelingEngineRuleMaximumDistanceLabelToFeature;
148 }
149 else if ( sipCpp->id() == "avoidLabelOverlapWithFeature" )
150 {
151 sipType = sipType_QgsLabelingEngineRuleAvoidLabelOverlapWithFeature;
152 }
153 else
154 {
155 sipType = 0;
156 }
157 SIP_END
158#endif
159
160 public:
161
163
170
174 virtual QString id() const = 0;
175
179 virtual QString displayType() const = 0;
180
189 virtual bool isAvailable() const;
190
199 virtual QString description() const;
200
209 QString name() const { return mName; }
210
219 void setName( const QString &name ) { mName = name; }
220
226 bool active() const;
227
233 void setActive( bool active );
234
241 virtual bool prepare( QgsRenderContext &context ) = 0;
242
248 virtual void writeXml( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context ) const = 0;
249
256 virtual void readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
257
263 virtual void resolveReferences( const QgsProject *project );
264
270 virtual bool candidatesAreConflicting( const pal::LabelPosition *lp1, const pal::LabelPosition *lp2 ) const SIP_SKIP;
271
279 virtual QgsRectangle modifyCandidateConflictSearchBoundingBox( const QgsRectangle &candidateBounds ) const SIP_SKIP;
280
286 virtual bool candidateIsIllegal( const pal::LabelPosition *candidate, QgsLabelingEngineContext &context ) const SIP_SKIP;
287
293 virtual void alterCandidateCost( pal::LabelPosition *candidate, QgsLabelingEngineContext &context ) const SIP_SKIP;
294
295 protected:
296
300 virtual void copyCommonProperties( QgsAbstractLabelingEngineRule *other ) const;
301
302 private:
303
304 QString mName;
305 bool mIsActive = true;
306
307};
308
309#endif // QGSLABELINGENGINESETTINGS_H
Abstract base class for labeling engine rules.
virtual bool prepare(QgsRenderContext &context)=0
Prepares the rule.
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads the rule properties from an XML element.
virtual void writeXml(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context) const =0
Writes the rule properties to an XML element.
QString name() const
Returns the name for this instance of the rule.
virtual QgsAbstractLabelingEngineRule * clone() const =0
Creates a clone of this rule.
virtual QString displayType() const =0
Returns a user-friendly, translated string representing the rule type.
void setName(const QString &name)
Sets the name for this instance of the rule.
virtual QString id() const =0
Returns a string uniquely identifying the rule subclass.
A geometry is the spatial representation of a feature.
Encapsulates the context for a labeling engine run.
QgsLabelingEngineContext & operator=(const QgsLabelingEngineContext &other)=delete
QgsLabelingEngineContext(const QgsLabelingEngineContext &other)=delete
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
const QgsRenderContext & renderContext() const
Returns a reference to the context's render context.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
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_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208