26using namespace Qt::StringLiterals;
35 : mFlags( other.mFlags )
36 , mSearchMethod( other.mSearchMethod )
37 , mMaxLineCandidatesPerCm( other.mMaxLineCandidatesPerCm )
38 , mMaxPolygonCandidatesPerCmSquared( other.mMaxPolygonCandidatesPerCmSquared )
39 , mUnplacedLabelColor( other.mUnplacedLabelColor )
40 , mPlacementVersion( other.mPlacementVersion )
41 , mDefaultTextRenderFormat( other.mDefaultTextRenderFormat )
44 mEngineRules.reserve( other.mEngineRules.size() );
45 for (
const auto &rule : other.mEngineRules )
47 mEngineRules.emplace_back( rule->clone() );
52 : mFlags( other.mFlags )
53 , mSearchMethod( other.mSearchMethod )
54 , mMaxLineCandidatesPerCm( other.mMaxLineCandidatesPerCm )
55 , mMaxPolygonCandidatesPerCmSquared( other.mMaxPolygonCandidatesPerCmSquared )
56 , mUnplacedLabelColor( std::move( other.mUnplacedLabelColor ) )
57 , mPlacementVersion( other.mPlacementVersion )
58 , mDefaultTextRenderFormat( other.mDefaultTextRenderFormat )
59 , mEngineRules( std::move( other.mEngineRules ) )
68 mFlags = other.mFlags;
69 mSearchMethod = other.mSearchMethod;
70 mMaxLineCandidatesPerCm = other.mMaxLineCandidatesPerCm;
71 mMaxPolygonCandidatesPerCmSquared = other.mMaxPolygonCandidatesPerCmSquared;
72 mUnplacedLabelColor = other.mUnplacedLabelColor;
73 mPlacementVersion = other.mPlacementVersion;
74 mDefaultTextRenderFormat = other.mDefaultTextRenderFormat;
76 mEngineRules.reserve( other.mEngineRules.size() );
77 for (
const auto &rule : other.mEngineRules )
79 mEngineRules.emplace_back( rule->clone() );
90 mFlags = other.mFlags;
91 mSearchMethod = other.mSearchMethod;
92 mMaxLineCandidatesPerCm = other.mMaxLineCandidatesPerCm;
93 mMaxPolygonCandidatesPerCmSquared = other.mMaxPolygonCandidatesPerCmSquared;
94 mUnplacedLabelColor = std::move( other.mUnplacedLabelColor );
95 mPlacementVersion = other.mPlacementVersion;
96 mDefaultTextRenderFormat = other.mDefaultTextRenderFormat;
97 mEngineRules = std::move( other.mEngineRules );
109 mSearchMethod =
static_cast< Search >( prj->
readNumEntry( u
"PAL"_s, u
"/SearchMethod"_s,
static_cast< int >(
Chain ), &saved ) );
110 mMaxLineCandidatesPerCm = prj->
readDoubleEntry( u
"PAL"_s, u
"/CandidatesLinePerCM"_s, 5, &saved );
111 mMaxPolygonCandidatesPerCmSquared = prj->
readDoubleEntry( u
"PAL"_s, u
"/CandidatesPolygonPerCM"_s, 2.5, &saved );
114 if ( prj->
readBoolEntry( u
"PAL"_s, u
"/ShowingCandidates"_s,
false, &saved ) )
116 if ( prj->
readBoolEntry( u
"PAL"_s, u
"/DrawRectOnly"_s,
false, &saved ) )
118 if ( prj->
readBoolEntry( u
"PAL"_s, u
"/ShowingAllLabels"_s,
false, &saved ) )
120 if ( prj->
readBoolEntry( u
"PAL"_s, u
"/ShowingPartialsLabels"_s,
true, &saved ) )
122 if ( prj->
readBoolEntry( u
"PAL"_s, u
"/DrawUnplaced"_s,
false, &saved ) )
124 if ( prj->
readBoolEntry( u
"PAL"_s, u
"/DrawLabelMetrics"_s,
false, &saved ) )
129 if ( !prj->
readBoolEntry( u
"PAL"_s, u
"/DrawOutlineLabels"_s,
true ) )
132 const int projectTextFormat = prj->
readNumEntry( u
"PAL"_s, u
"/TextFormat"_s, -1 );
133 if ( projectTextFormat >= 0 )
143 project->
writeEntry( u
"PAL"_s, u
"/SearchMethod"_s,
static_cast< int >( mSearchMethod ) );
144 project->
writeEntry( u
"PAL"_s, u
"/CandidatesLinePerCM"_s, mMaxLineCandidatesPerCm );
145 project->
writeEntry( u
"PAL"_s, u
"/CandidatesPolygonPerCM"_s, mMaxPolygonCandidatesPerCmSquared );
154 project->
writeEntry( u
"PAL"_s, u
"/TextFormat"_s,
static_cast< int >( mDefaultTextRenderFormat ) );
158 project->
writeEntry( u
"PAL"_s, u
"/PlacementEngineVersion"_s,
static_cast< int >( mPlacementVersion ) );
163 if ( !mEngineRules.empty() )
165 QDomElement rulesElement = doc.createElement( u
"rules"_s );
166 for (
const auto &rule : mEngineRules )
168 QDomElement ruleElement = doc.createElement( u
"rule"_s );
169 ruleElement.setAttribute( u
"id"_s, rule->id() );
170 if ( !rule->name().isEmpty() )
171 ruleElement.setAttribute( u
"name"_s, rule->name() );
172 if ( !rule->active() )
173 ruleElement.setAttribute( u
"active"_s, u
"0"_s );
174 rule->writeXml( doc, ruleElement, context );
175 rulesElement.appendChild( ruleElement );
177 element.appendChild( rulesElement );
183 mEngineRules.clear();
185 const QDomElement rulesElement = element.firstChildElement( u
"rules"_s );
186 const QDomNodeList
rules = rulesElement.childNodes();
187 for (
int i = 0; i <
rules.length(); i++ )
189 const QDomElement ruleElement =
rules.at( i ).toElement();
190 const QString
id = ruleElement.attribute( u
"id"_s );
191 const QString name = ruleElement.attribute( u
"name"_s );
192 const bool active = ruleElement.attribute( u
"active"_s, u
"1"_s ).toInt();
196 rule->setName( name );
197 rule->setActive( active );
198 rule->readXml( ruleElement, context );
199 mEngineRules.emplace_back( std::move( rule ) );
207 for (
const auto &rule : mEngineRules )
209 rule->resolveReferences( project );
215 return mUnplacedLabelColor;
225 return mPlacementVersion;
235 QList<QgsAbstractLabelingEngineRule *> res;
236 for (
const auto &it : mEngineRules )
245 QList<const QgsAbstractLabelingEngineRule *> res;
246 for (
const auto &it : mEngineRules )
255 mEngineRules.emplace_back( rule );
260 mEngineRules.clear();
263 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.