26using namespace Qt::StringLiterals;
36 : mFlags( other.mFlags )
37 , mSearchMethod( other.mSearchMethod )
38 , mMaxLineCandidatesPerCm( other.mMaxLineCandidatesPerCm )
39 , mMaxPolygonCandidatesPerCmSquared( other.mMaxPolygonCandidatesPerCmSquared )
40 , mUnplacedLabelColor( other.mUnplacedLabelColor )
41 , mPlacementVersion( other.mPlacementVersion )
42 , mDefaultTextRenderFormat( other.mDefaultTextRenderFormat )
45 mEngineRules.reserve( other.mEngineRules.size() );
46 for (
const auto &rule : other.mEngineRules )
48 mEngineRules.emplace_back( rule->clone() );
53 : mFlags( other.mFlags )
54 , mSearchMethod( other.mSearchMethod )
55 , mMaxLineCandidatesPerCm( other.mMaxLineCandidatesPerCm )
56 , mMaxPolygonCandidatesPerCmSquared( other.mMaxPolygonCandidatesPerCmSquared )
57 , mUnplacedLabelColor( std::move( other.mUnplacedLabelColor ) )
58 , mPlacementVersion( other.mPlacementVersion )
59 , mDefaultTextRenderFormat( other.mDefaultTextRenderFormat )
60 , mEngineRules( std::move( other.mEngineRules ) )
70 mFlags = other.mFlags;
71 mSearchMethod = other.mSearchMethod;
72 mMaxLineCandidatesPerCm = other.mMaxLineCandidatesPerCm;
73 mMaxPolygonCandidatesPerCmSquared = other.mMaxPolygonCandidatesPerCmSquared;
74 mUnplacedLabelColor = other.mUnplacedLabelColor;
75 mPlacementVersion = other.mPlacementVersion;
76 mDefaultTextRenderFormat = other.mDefaultTextRenderFormat;
78 mEngineRules.reserve( other.mEngineRules.size() );
79 for (
const auto &rule : other.mEngineRules )
81 mEngineRules.emplace_back( rule->clone() );
92 mFlags = other.mFlags;
93 mSearchMethod = other.mSearchMethod;
94 mMaxLineCandidatesPerCm = other.mMaxLineCandidatesPerCm;
95 mMaxPolygonCandidatesPerCmSquared = other.mMaxPolygonCandidatesPerCmSquared;
96 mUnplacedLabelColor = std::move( other.mUnplacedLabelColor );
97 mPlacementVersion = other.mPlacementVersion;
98 mDefaultTextRenderFormat = other.mDefaultTextRenderFormat;
99 mEngineRules = std::move( other.mEngineRules );
111 mSearchMethod =
static_cast< Search >( prj->
readNumEntry( u
"PAL"_s, u
"/SearchMethod"_s,
static_cast< int >(
Chain ), &saved ) );
112 mMaxLineCandidatesPerCm = prj->
readDoubleEntry( u
"PAL"_s, u
"/CandidatesLinePerCM"_s, 5, &saved );
113 mMaxPolygonCandidatesPerCmSquared = prj->
readDoubleEntry( u
"PAL"_s, u
"/CandidatesPolygonPerCM"_s, 2.5, &saved );
125 if ( !prj->
readBoolEntry( u
"PAL"_s, u
"/DrawOutlineLabels"_s,
true ) )
128 const int projectTextFormat = prj->
readNumEntry( u
"PAL"_s, u
"/TextFormat"_s, -1 );
129 if ( projectTextFormat >= 0 )
139 project->
writeEntry( u
"PAL"_s, u
"/SearchMethod"_s,
static_cast< int >( mSearchMethod ) );
140 project->
writeEntry( u
"PAL"_s, u
"/CandidatesLinePerCM"_s, mMaxLineCandidatesPerCm );
141 project->
writeEntry( u
"PAL"_s, u
"/CandidatesPolygonPerCM"_s, mMaxPolygonCandidatesPerCmSquared );
150 project->
writeEntry( u
"PAL"_s, u
"/TextFormat"_s,
static_cast< int >( mDefaultTextRenderFormat ) );
154 project->
writeEntry( u
"PAL"_s, u
"/PlacementEngineVersion"_s,
static_cast< int >( mPlacementVersion ) );
159 if ( !mEngineRules.empty() )
161 QDomElement rulesElement = doc.createElement( u
"rules"_s );
162 for (
const auto &rule : mEngineRules )
164 QDomElement ruleElement = doc.createElement( u
"rule"_s );
165 ruleElement.setAttribute( u
"id"_s, rule->id() );
166 if ( !rule->name().isEmpty() )
167 ruleElement.setAttribute( u
"name"_s, rule->name() );
168 if ( !rule->active() )
169 ruleElement.setAttribute( u
"active"_s, u
"0"_s );
170 rule->writeXml( doc, ruleElement, context );
171 rulesElement.appendChild( ruleElement );
173 element.appendChild( rulesElement );
179 mEngineRules.clear();
181 const QDomElement rulesElement = element.firstChildElement( u
"rules"_s );
182 const QDomNodeList
rules = rulesElement.childNodes();
183 for (
int i = 0; i <
rules.length(); i++ )
185 const QDomElement ruleElement =
rules.at( i ).toElement();
186 const QString
id = ruleElement.attribute( u
"id"_s );
187 const QString name = ruleElement.attribute( u
"name"_s );
188 const bool active = ruleElement.attribute( u
"active"_s, u
"1"_s ).toInt();
192 rule->setName( name );
193 rule->setActive( active );
194 rule->readXml( ruleElement, context );
195 mEngineRules.emplace_back( std::move( rule ) );
203 for (
const auto &rule : mEngineRules )
205 rule->resolveReferences( project );
211 return mUnplacedLabelColor;
221 return mPlacementVersion;
231 QList<QgsAbstractLabelingEngineRule *> res;
232 for (
const auto &it : mEngineRules )
241 QList<const QgsAbstractLabelingEngineRule *> res;
242 for (
const auto &it : mEngineRules )
251 mEngineRules.emplace_back( rule );
256 mEngineRules.clear();
259 mEngineRules.emplace_back( rule );
@ DrawCandidates
Whether to draw rectangles of generated candidates (good for debugging).
@ DrawLabelMetrics
Whether to render label metric guides (for debugging).
@ DrawUnplacedLabels
Whether to render unplaced labels as an indicator/warning for users.
@ UseAllLabels
Whether to draw all labels even if there would be collisions.
@ DrawLabelRectOnly
Whether to only draw the label rect and not the actual label text (used for unit tests).
@ UsePartialCandidates
Whether to use also label candidates that are partially outside of the map view.
TextRenderFormat
Options for rendering text.
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
@ AlwaysText
Always render text as text objects. While this mode preserves text objects as text for post-processin...
QFlags< LabelingFlag > LabelingFlags
Flags that affect drawing and placement of labels.
LabelPlacementEngineVersion
Labeling placement engine version.
@ Version1
Version 1, matches placement from QGIS <= 3.10.1.
Abstract base class for labeling engine rules.
static QgsLabelingEngineRuleRegistry * labelingEngineRuleRegistry()
Gets the registry of available labeling engine rules.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID.
void writeSettingsToProject(QgsProject *project)
Write configuration of the labeling engine to a project.
void setPlacementVersion(Qgis::LabelPlacementEngineVersion version)
Sets the placement engine version, which dictates how the label placement problem is solved.
void setRules(const QList< QgsAbstractLabelingEngineRule * > &rules)
Sets the labeling engine rules which must be satisfied while placing labels.
QgsLabelingEngineSettings()
Search
Search methods in the PAL library to remove colliding labels (methods have different processing speed...
QColor unplacedLabelColor() const
Returns the color to use when rendering unplaced labels.
Qgis::LabelPlacementEngineVersion placementVersion() const
Returns the placement engine version, which dictates how the label placement problem is solved.
void clear()
Returns the configuration to the defaults.
void setUnplacedLabelColor(const QColor &color)
Sets the color to use when rendering unplaced labels.
void addRule(QgsAbstractLabelingEngineRule *rule)
Adds a labeling engine rule which must be satisfied while placing labels.
~QgsLabelingEngineSettings()
QList< QgsAbstractLabelingEngineRule * > rules()
Returns a list of labeling engine rules which must be satisfied while placing labels.
void writeXml(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context) const
Writes the label engine settings to an XML element.
QgsLabelingEngineSettings & operator=(const QgsLabelingEngineSettings &other)
void readSettingsFromProject(QgsProject *project)
Read configuration of the labeling engine from a project.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads the label engine settings from an XML element.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
Reads an integer from the specified scope and key.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
Reads a boolean from the specified scope and key.
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
Reads a double from the specified scope and key.
bool writeEntry(const QString &scope, const QString &key, bool value)
Write a boolean value to the project file.
A container for the context for various read/write operations on objects.