QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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.h"
19#include "qgis_core.h"
20#include "qgis_sip.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:
47
48#ifndef SIP_RUN
51#endif
52
56 QgsRenderContext &renderContext() { return mRenderContext; }
57
62 const QgsRenderContext &renderContext() const SIP_SKIP { return mRenderContext; }
63
70 QgsRectangle extent() const;
71
78 void setExtent( const QgsRectangle &extent );
79
92 QgsGeometry mapBoundaryGeometry() const;
93
106 void setMapBoundaryGeometry( const QgsGeometry &geometry );
107
108 private:
109#ifdef SIP_RUN
111#endif
112
113 QgsRenderContext &mRenderContext;
114 QgsRectangle mExtent;
115 QgsGeometry mMapBoundaryGeometry;
116};
117
131{
132#ifdef SIP_RUN
134 if ( sipCpp->id() == "minimumDistanceLabelToFeature" )
135 {
136 sipType = sipType_QgsLabelingEngineRuleMinimumDistanceLabelToFeature;
137 }
138 else if ( sipCpp->id() == "minimumDistanceLabelToLabel" )
139 {
140 sipType = sipType_QgsLabelingEngineRuleMinimumDistanceLabelToLabel;
141 }
142 else if ( sipCpp->id() == "maximumDistanceLabelToFeature" )
143 {
144 sipType = sipType_QgsLabelingEngineRuleMaximumDistanceLabelToFeature;
145 }
146 else if ( sipCpp->id() == "avoidLabelOverlapWithFeature" )
147 {
148 sipType = sipType_QgsLabelingEngineRuleAvoidLabelOverlapWithFeature;
149 }
150 else
151 {
152 sipType = 0;
153 }
154 SIP_END
155#endif
156
157 public:
158
160
167
171 virtual QString id() const = 0;
172
176 virtual QString displayType() const = 0;
177
186 virtual bool isAvailable() const;
187
196 virtual QString description() const;
197
206 QString name() const { return mName; }
207
216 void setName( const QString &name ) { mName = name; }
217
223 bool active() const;
224
230 void setActive( bool active );
231
238 virtual bool prepare( QgsRenderContext &context ) = 0;
239
245 virtual void writeXml( QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context ) const = 0;
246
253 virtual void readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
254
260 virtual void resolveReferences( const QgsProject *project );
261
267 virtual bool candidatesAreConflicting( const pal::LabelPosition *lp1, const pal::LabelPosition *lp2 ) const SIP_SKIP;
268
276 virtual QgsRectangle modifyCandidateConflictSearchBoundingBox( const QgsRectangle &candidateBounds ) const SIP_SKIP;
277
283 virtual bool candidateIsIllegal( const pal::LabelPosition *candidate, QgsLabelingEngineContext &context ) const SIP_SKIP;
284
290 virtual void alterCandidateCost( pal::LabelPosition *candidate, QgsLabelingEngineContext &context ) const SIP_SKIP;
291
292 protected:
296 virtual void copyCommonProperties( QgsAbstractLabelingEngineRule *other ) const;
297
298 private:
299 QString mName;
300 bool mIsActive = true;
301};
302
303#endif // QGSLABELINGENGINESETTINGS_H
Abstract base class for labeling engine rules.
virtual bool prepare(QgsRenderContext &context)=0
Prepares the rule.
virtual void alterCandidateCost(pal::LabelPosition *candidate, QgsLabelingEngineContext &context) const
Provides an opportunity for the rule to alter the cost for a candidate.
virtual void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID.
virtual bool isAvailable() const
Returns true if the rule is available for use within the current QGIS environment.
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads the rule properties from an XML element.
virtual QgsRectangle modifyCandidateConflictSearchBoundingBox(const QgsRectangle &candidateBounds) const
Returns a (possibly expanded) bounding box to use when searching for conflicts for a candidate.
virtual void writeXml(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context) const =0
Writes the rule properties to an XML element.
virtual bool candidatesAreConflicting(const pal::LabelPosition *lp1, const pal::LabelPosition *lp2) const
Returns true if a labeling candidate lp1 conflicts with lp2 after applying the rule.
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.
virtual QString description() const
Returns a user-friendly description of the rule.
void setName(const QString &name)
Sets the name for this instance of the rule.
virtual bool candidateIsIllegal(const pal::LabelPosition *candidate, QgsLabelingEngineContext &context) const
Returns true if a labeling candidate violates the rule and should be eliminated.
virtual QString id() const =0
Returns a string uniquely identifying the rule subclass.
virtual void copyCommonProperties(QgsAbstractLabelingEngineRule *other) const
Copies common properties from this object to an other.
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.
QgsLabelingEngineContext(QgsRenderContext &renderContext)
Constructor for QgsLabelingEngineContext.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
A container for the context for various read/write operations on 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:198
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215