QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgslabelingenginesettings.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslabelingenginesettings.h
3  ---------------------
4  begin : April 2017
5  copyright : (C) 2017 by Martin Dobias
6  email : wonder dot sk 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 QGSLABELINGENGINESETTINGS_H
16 #define QGSLABELINGENGINESETTINGS_H
17 
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgsrendercontext.h"
21 #include <QFlags>
22 
23 class QgsProject;
24 
30 class CORE_EXPORT QgsLabelingEngineSettings
31 {
32  public:
34  enum Flag
35  {
36  UseAllLabels = 1 << 1,
37  UsePartialCandidates = 1 << 2,
38  // TODO QGIS 4.0: remove
39  RenderOutlineLabels = 1 << 3,
40  DrawLabelRectOnly = 1 << 4,
41  DrawCandidates = 1 << 5,
42  DrawUnplacedLabels = 1 << 6,
43  CollectUnplacedLabels = 1 << 7,
44  };
45  Q_DECLARE_FLAGS( Flags, Flag )
46 
47  // TODO QGIS 4 - remove
48 
49 
53  enum Search
54  {
59  Falp
60  };
61 
68  {
71  };
72 
74 
76  void clear();
77 
79  void setFlags( Flags flags ) { mFlags = flags; }
81  Flags flags() const { return mFlags; }
83  bool testFlag( Flag f ) const { return mFlags.testFlag( f ); }
85  void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }
86 
93  double maximumLineCandidatesPerCm() const { return mMaxLineCandidatesPerCm; }
94 
101  void setMaximumLineCandidatesPerCm( double candidates ) { mMaxLineCandidatesPerCm = candidates; }
102 
109  double maximumPolygonCandidatesPerCmSquared() const { return mMaxPolygonCandidatesPerCmSquared; }
110 
117  void setMaximumPolygonCandidatesPerCmSquared( double candidates ) { mMaxPolygonCandidatesPerCmSquared = candidates; }
118 
123  Q_DECL_DEPRECATED void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const SIP_DEPRECATED
124  {
125  Q_UNUSED( candPoint )
126  Q_UNUSED( candLine )
127  Q_UNUSED( candPolygon )
128  }
129 
134  Q_DECL_DEPRECATED void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) SIP_DEPRECATED
135  {
136  Q_UNUSED( candPoint )
137  Q_UNUSED( candLine )
138  Q_UNUSED( candPolygon )
139  }
140 
145  Q_DECL_DEPRECATED void setSearchMethod( Search s ) SIP_DEPRECATED { Q_UNUSED( s ) }
146 
151  Q_DECL_DEPRECATED Search searchMethod() const SIP_DEPRECATED { return Chain; }
152 
154  void readSettingsFromProject( QgsProject *project );
156  void writeSettingsToProject( QgsProject *project );
157 
158  // TODO QGIS 4.0: In reality the text render format settings don't only apply to labels, but also
159  // ANY text rendered using QgsTextRenderer (including some non-label text items in layouts).
160  // These methods should possibly be moved out of here and into the general QgsProject settings.
161 
169  {
170  return mDefaultTextRenderFormat;
171  }
172 
180  {
181  mDefaultTextRenderFormat = format;
182  }
183 
190  QColor unplacedLabelColor() const;
191 
198  void setUnplacedLabelColor( const QColor &color );
199 
206  PlacementEngineVersion placementVersion() const;
207 
214  void setPlacementVersion( PlacementEngineVersion version );
215 
216  private:
218  Flags mFlags;
220  Search mSearchMethod = Chain;
221 
222  // maximum density of line/polygon candidates per mm
223  double mMaxLineCandidatesPerCm = 5;
224  double mMaxPolygonCandidatesPerCmSquared = 2.5;
225 
226  QColor mUnplacedLabelColor = QColor( 255, 0, 0 );
227 
228  PlacementEngineVersion mPlacementVersion = PlacementEngineVersion2;
229 
231 
232 };
233 
234 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLabelingEngineSettings::Flags )
235 
236 #endif // QGSLABELINGENGINESETTINGS_H
Stores global configuration for labeling engine.
Q_DECL_DEPRECATED void numCandidatePositions(int &candPoint, int &candLine, int &candPolygon) const
Gets number of candidate positions that will be generated for each label feature.
bool testFlag(Flag f) const
Test whether a particular flag is enabled.
void setDefaultTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the default text rendering format for the labels.
Flags flags() const
Gets flags of the labeling engine.
Flag
Various flags that affect drawing and placement of labels.
Q_DECL_DEPRECATED Search searchMethod() const
Which search method to use for removal collisions between labels.
void setFlag(Flag f, bool enabled=true)
Sets whether a particual flag is enabled.
QgsRenderContext::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
Search
Search methods in the PAL library to remove colliding labels (methods have different processing speed...
void setMaximumPolygonCandidatesPerCmSquared(double candidates)
Sets the maximum number of polygon label candidates per centimeter squared.
PlacementEngineVersion
Placement engine version.
@ PlacementEngineVersion1
Version 1, matches placement from QGIS <= 3.10.1.
@ PlacementEngineVersion2
Version 2 (default for new projects since QGIS 3.12)
void setFlags(Flags flags)
Sets flags of the labeling engine.
Q_DECL_DEPRECATED void setNumCandidatePositions(int candPoint, int candLine, int candPolygon)
Sets the number of candidate positions that will be generated for each label feature.
double maximumPolygonCandidatesPerCmSquared() const
Returns the maximum number of polygon label candidate positions per centimeter squared.
Q_DECL_DEPRECATED void setSearchMethod(Search s)
Used to set which search method to use for removal collisions between labels.
void setMaximumLineCandidatesPerCm(double candidates)
Sets the maximum number of line label candidates per centimeter.
double maximumLineCandidatesPerCm() const
Returns the maximum number of line label candidate positions per centimeter.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
TextRenderFormat
Options for rendering text.
@ TextFormatAlwaysOutlines
Always render text using path objects (AKA outlines/curves).
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.