QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  };
44  Q_DECLARE_FLAGS( Flags, Flag )
45 
46  // TODO QGIS 4 - remove
47 
48 
52  enum Search
53  {
58  Falp
59  };
60 
67  {
70  };
71 
73 
75  void clear();
76 
78  void setFlags( Flags flags ) { mFlags = flags; }
80  Flags flags() const { return mFlags; }
82  bool testFlag( Flag f ) const { return mFlags.testFlag( f ); }
84  void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }
85 
92  double maximumLineCandidatesPerCm() const { return mMaxLineCandidatesPerCm; }
93 
100  void setMaximumLineCandidatesPerCm( double candidates ) { mMaxLineCandidatesPerCm = candidates; }
101 
108  double maximumPolygonCandidatesPerCmSquared() const { return mMaxPolygonCandidatesPerCmSquared; }
109 
116  void setMaximumPolygonCandidatesPerCmSquared( double candidates ) { mMaxPolygonCandidatesPerCmSquared = candidates; }
117 
122  Q_DECL_DEPRECATED void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const SIP_DEPRECATED
123  {
124  Q_UNUSED( candPoint )
125  Q_UNUSED( candLine )
126  Q_UNUSED( candPolygon )
127  }
128 
133  Q_DECL_DEPRECATED void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) SIP_DEPRECATED
134  {
135  Q_UNUSED( candPoint )
136  Q_UNUSED( candLine )
137  Q_UNUSED( candPolygon )
138  }
139 
144  Q_DECL_DEPRECATED void setSearchMethod( Search s ) SIP_DEPRECATED { Q_UNUSED( s ) }
145 
150  Q_DECL_DEPRECATED Search searchMethod() const SIP_DEPRECATED { return Chain; }
151 
153  void readSettingsFromProject( QgsProject *project );
155  void writeSettingsToProject( QgsProject *project );
156 
157  // TODO QGIS 4.0: In reality the text render format settings don't only apply to labels, but also
158  // ANY text rendered using QgsTextRenderer (including some non-label text items in layouts).
159  // These methods should possibly be moved out of here and into the general QgsProject settings.
160 
168  {
169  return mDefaultTextRenderFormat;
170  }
171 
179  {
180  mDefaultTextRenderFormat = format;
181  }
182 
189  QColor unplacedLabelColor() const;
190 
197  void setUnplacedLabelColor( const QColor &color );
198 
205  PlacementEngineVersion placementVersion() const;
206 
213  void setPlacementVersion( PlacementEngineVersion version );
214 
215  private:
217  Flags mFlags;
219  Search mSearchMethod = Chain;
220 
221  // maximum density of line/polygon candidates per mm
222  double mMaxLineCandidatesPerCm = 5;
223  double mMaxPolygonCandidatesPerCmSquared = 2.5;
224 
225  QColor mUnplacedLabelColor = QColor( 255, 0, 0 );
226 
227  PlacementEngineVersion mPlacementVersion = PlacementEngineVersion2;
228 
230 
231 };
232 
233 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLabelingEngineSettings::Flags )
234 
235 #endif // QGSLABELINGENGINESETTINGS_H
QgsLabelingEngineSettings::Popmusic_Tabu
@ Popmusic_Tabu
Definition: qgslabelingenginesettings.h:55
QgsLabelingEngineSettings::setNumCandidatePositions
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.
Definition: qgslabelingenginesettings.h:133
QgsLabelingEngineSettings::searchMethod
Q_DECL_DEPRECATED Search searchMethod() const
Which search method to use for removal collisions between labels.
Definition: qgslabelingenginesettings.h:150
QgsRenderContext::TextRenderFormat
TextRenderFormat
Options for rendering text.
Definition: qgsrendercontext.h:96
QgsLabelingEngineSettings::Popmusic_Tabu_Chain
@ Popmusic_Tabu_Chain
Definition: qgslabelingenginesettings.h:57
QgsLabelingEngineSettings::flags
Flags flags() const
Gets flags of the labeling engine.
Definition: qgslabelingenginesettings.h:80
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsLabelingEngineSettings::PlacementEngineVersion
PlacementEngineVersion
Placement engine version.
Definition: qgslabelingenginesettings.h:67
QgsLabelingEngineSettings
Stores global configuration for labeling engine.
Definition: qgslabelingenginesettings.h:31
QgsLabelingEngineSettings::testFlag
bool testFlag(Flag f) const
Test whether a particular flag is enabled.
Definition: qgslabelingenginesettings.h:82
qgis_sip.h
qgsrendercontext.h
Q_DECLARE_OPERATORS_FOR_FLAGS
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.
QgsLabelingEngineSettings::setFlags
void setFlags(Flags flags)
Sets flags of the labeling engine.
Definition: qgslabelingenginesettings.h:78
QgsLabelingEngineSettings::Flag
Flag
Various flags that affect drawing and placement of labels.
Definition: qgslabelingenginesettings.h:35
QgsLabelingEngineSettings::PlacementEngineVersion1
@ PlacementEngineVersion1
Version 1, matches placement from QGIS <= 3.10.1.
Definition: qgslabelingenginesettings.h:68
QgsLabelingEngineSettings::Popmusic_Chain
@ Popmusic_Chain
Definition: qgslabelingenginesettings.h:56
QgsLabelingEngineSettings::numCandidatePositions
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.
Definition: qgslabelingenginesettings.h:122
QgsLabelingEngineSettings::Search
Search
Search methods in the PAL library to remove colliding labels (methods have different processing speed...
Definition: qgslabelingenginesettings.h:53
QgsLabelingEngineSettings::defaultTextRenderFormat
QgsRenderContext::TextRenderFormat defaultTextRenderFormat() const
Returns the default text rendering format for the labels.
Definition: qgslabelingenginesettings.h:167
QgsLabelingEngineSettings::setMaximumPolygonCandidatesPerCmSquared
void setMaximumPolygonCandidatesPerCmSquared(double candidates)
Sets the maximum number of polygon label candidates per centimeter squared.
Definition: qgslabelingenginesettings.h:116
QgsLabelingEngineSettings::setFlag
void setFlag(Flag f, bool enabled=true)
Sets whether a particual flag is enabled.
Definition: qgslabelingenginesettings.h:84
QgsLabelingEngineSettings::maximumPolygonCandidatesPerCmSquared
double maximumPolygonCandidatesPerCmSquared() const
Returns the maximum number of polygon label candidate positions per centimeter squared.
Definition: qgslabelingenginesettings.h:108
QgsLabelingEngineSettings::setMaximumLineCandidatesPerCm
void setMaximumLineCandidatesPerCm(double candidates)
Sets the maximum number of line label candidates per centimeter.
Definition: qgslabelingenginesettings.h:100
QgsLabelingEngineSettings::Chain
@ Chain
Definition: qgslabelingenginesettings.h:54
QgsLabelingEngineSettings::setDefaultTextRenderFormat
void setDefaultTextRenderFormat(QgsRenderContext::TextRenderFormat format)
Sets the default text rendering format for the labels.
Definition: qgslabelingenginesettings.h:178
QgsLabelingEngineSettings::maximumLineCandidatesPerCm
double maximumLineCandidatesPerCm() const
Returns the maximum number of line label candidate positions per centimeter.
Definition: qgslabelingenginesettings.h:92
QgsLabelingEngineSettings::PlacementEngineVersion2
@ PlacementEngineVersion2
Version 2 (default for new projects since QGIS 3.12)
Definition: qgslabelingenginesettings.h:69
QgsRenderContext::TextFormatAlwaysOutlines
@ TextFormatAlwaysOutlines
Always render text using path objects (AKA outlines/curves).
Definition: qgsrendercontext.h:116
QgsLabelingEngineSettings::setSearchMethod
Q_DECL_DEPRECATED void setSearchMethod(Search s)
Used to set which search method to use for removal collisions between labels.
Definition: qgslabelingenginesettings.h:144