/
qgslabelingenginesettings.h
184 lines (157 loc) · 6.76 KB
/
qgslabelingenginesettings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/***************************************************************************
qgslabelingenginesettings.h
---------------------
begin : April 2017
copyright : (C) 2017 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSLABELINGENGINESETTINGS_H
#define QGSLABELINGENGINESETTINGS_H
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgsrendercontext.h"
#include <QFlags>
class QgsProject;
/**
* \ingroup core
* Stores global configuration for labeling engine
* \since QGIS 3.0
*/
class CORE_EXPORT QgsLabelingEngineSettings
{
public:
//! Various flags that affect drawing and placement of labels
enum Flag
{
UseAllLabels = 1 << 1, //!< Whether to draw all labels even if there would be collisions
UsePartialCandidates = 1 << 2, //!< Whether to use also label candidates that are partially outside of the map view
// TODO QGIS 4.0: remove
RenderOutlineLabels = 1 << 3, //!< Whether to render labels as text or outlines. Deprecated and of QGIS 3.4.3 - use defaultTextRenderFormat() instead.
DrawLabelRectOnly = 1 << 4, //!< Whether to only draw the label rect and not the actual label text (used for unit tests)
DrawCandidates = 1 << 5, //!< Whether to draw rectangles of generated candidates (good for debugging)
DrawUnplacedLabels = 1 << 6, //!< Whether to render unplaced labels as an indicator/warning for users
};
Q_DECLARE_FLAGS( Flags, Flag )
// TODO QGIS 4 - remove
/**
* Search methods in the PAL library to remove colliding labels
* (methods have different processing speed and number of labels placed)
*/
enum Search
{
Chain,
Popmusic_Tabu,
Popmusic_Chain,
Popmusic_Tabu_Chain,
Falp
};
/**
* Placement engine version.
*
* \since QGIS 3.10.2
*/
enum PlacementEngineVersion
{
PlacementEngineVersion1, //!< Version 1, matches placement from QGIS <= 3.10.1
PlacementEngineVersion2, //!< Version 2 (default for new projects since QGIS 3.12)
};
QgsLabelingEngineSettings();
//! Returns the configuration to the defaults
void clear();
//! Sets flags of the labeling engine
void setFlags( Flags flags ) { mFlags = flags; }
//! Gets flags of the labeling engine
Flags flags() const { return mFlags; }
//! Test whether a particular flag is enabled
bool testFlag( Flag f ) const { return mFlags.testFlag( f ); }
//! Sets whether a particual flag is enabled
void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }
//! Gets number of candidate positions that will be generated for each label feature (default to 8)
void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const { candPoint = mCandPoint; candLine = mCandLine; candPolygon = mCandPolygon; }
//! Sets number of candidate positions that will be generated for each label feature
void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) { mCandPoint = candPoint; mCandLine = candLine; mCandPolygon = candPolygon; }
/**
* Used to set which search method to use for removal collisions between labels
* \deprecated since QGIS 3.10 - Chain is always used.
*/
Q_DECL_DEPRECATED void setSearchMethod( Search s ) SIP_DEPRECATED { Q_UNUSED( s ) }
/**
* Which search method to use for removal collisions between labels
* \deprecated since QGIS 3.10 - Chain is always used.
*/
Q_DECL_DEPRECATED Search searchMethod() const SIP_DEPRECATED { return Chain; }
//! Read configuration of the labeling engine from a project
void readSettingsFromProject( QgsProject *project );
//! Write configuration of the labeling engine to a project
void writeSettingsToProject( QgsProject *project );
// TODO QGIS 4.0: In reality the text render format settings don't only apply to labels, but also
// ANY text rendered using QgsTextRenderer (including some non-label text items in layouts).
// These methods should possibly be moved out of here and into the general QgsProject settings.
/**
* Returns the default text rendering format for the labels.
*
* \see setDefaultTextRenderFormat()
* \since QGIS 3.4.3
*/
QgsRenderContext::TextRenderFormat defaultTextRenderFormat() const
{
return mDefaultTextRenderFormat;
}
/**
* Sets the default text rendering \a format for the labels.
*
* \see defaultTextRenderFormat()
* \since QGIS 3.4.3
*/
void setDefaultTextRenderFormat( QgsRenderContext::TextRenderFormat format )
{
mDefaultTextRenderFormat = format;
}
/**
* Returns the color to use when rendering unplaced labels.
*
* \see setUnplacedLabelColor()
* \since QGIS 3.10
*/
QColor unplacedLabelColor() const;
/**
* Sets the \a color to use when rendering unplaced labels.
*
* \see unplacedLabelColor()
* \since QGIS 3.10
*/
void setUnplacedLabelColor( const QColor &color );
/**
* Returns the placement engine version, which dictates how the label placement problem is solved.
*
* \see setPlacementVersion()
* \since QGIS 3.10.2
*/
PlacementEngineVersion placementVersion() const;
/**
* Sets the placement engine \a version, which dictates how the label placement problem is solved.
*
* \see placementVersion()
* \since QGIS 3.10.2
*/
void setPlacementVersion( PlacementEngineVersion version );
private:
//! Flags
Flags mFlags;
//! search method to use for removal collisions between labels
Search mSearchMethod = Chain;
//! Number of candedate positions that will be generated for features
int mCandPoint = 16, mCandLine = 50, mCandPolygon = 30;
QColor mUnplacedLabelColor = QColor( 255, 0, 0 );
PlacementEngineVersion mPlacementVersion = PlacementEngineVersion2;
QgsRenderContext::TextRenderFormat mDefaultTextRenderFormat = QgsRenderContext::TextFormatAlwaysOutlines;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLabelingEngineSettings::Flags )
#endif // QGSLABELINGENGINESETTINGS_H