31 : mFlags( other.mFlags )
32 , mSearchMethod( other.mSearchMethod )
33 , mMaxLineCandidatesPerCm( other.mMaxLineCandidatesPerCm )
34 , mMaxPolygonCandidatesPerCmSquared( other.mMaxPolygonCandidatesPerCmSquared )
35 , mUnplacedLabelColor( other.mUnplacedLabelColor )
36 , mPlacementVersion( other.mPlacementVersion )
37 , mDefaultTextRenderFormat( other.mDefaultTextRenderFormat )
39 mEngineRules.reserve( other.mEngineRules.size() );
40 for (
const auto &rule : other.mEngineRules )
42 mEngineRules.emplace_back( rule->clone() );
48 mFlags = other.mFlags;
49 mSearchMethod = other.mSearchMethod;
50 mMaxLineCandidatesPerCm = other.mMaxLineCandidatesPerCm;
51 mMaxPolygonCandidatesPerCmSquared = other.mMaxPolygonCandidatesPerCmSquared;
52 mUnplacedLabelColor = other.mUnplacedLabelColor;
53 mPlacementVersion = other.mPlacementVersion;
54 mDefaultTextRenderFormat = other.mDefaultTextRenderFormat;
56 mEngineRules.reserve( other.mEngineRules.size() );
57 for (
const auto &rule : other.mEngineRules )
59 mEngineRules.emplace_back( rule->clone() );
72 mSearchMethod =
static_cast< Search >( prj->
readNumEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/SearchMethod" ),
static_cast< int >(
Chain ), &saved ) );
73 mMaxLineCandidatesPerCm = prj->
readDoubleEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesLinePerCM" ), 5, &saved );
74 mMaxPolygonCandidatesPerCmSquared = prj->
readDoubleEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesPolygonPerCM" ), 2.5, &saved );
86 if ( !prj->
readBoolEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/DrawOutlineLabels" ),
true ) )
89 const int projectTextFormat = prj->
readNumEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/TextFormat" ), -1 );
90 if ( projectTextFormat >= 0 )
100 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/SearchMethod" ),
static_cast< int >( mSearchMethod ) );
101 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesLinePerCM" ), mMaxLineCandidatesPerCm );
102 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesPolygonPerCM" ), mMaxPolygonCandidatesPerCmSquared );
111 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/TextFormat" ),
static_cast< int >( mDefaultTextRenderFormat ) );
115 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/PlacementEngineVersion" ),
static_cast< int >( mPlacementVersion ) );
120 if ( !mEngineRules.empty() )
122 QDomElement rulesElement = doc.createElement( QStringLiteral(
"rules" ) );
123 for (
const auto &rule : mEngineRules )
125 QDomElement ruleElement = doc.createElement( QStringLiteral(
"rule" ) );
126 ruleElement.setAttribute( QStringLiteral(
"id" ), rule->id() );
127 if ( !rule->name().isEmpty() )
128 ruleElement.setAttribute( QStringLiteral(
"name" ), rule->name() );
129 if ( !rule->active() )
130 ruleElement.setAttribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) );
131 rule->writeXml( doc, ruleElement, context );
132 rulesElement.appendChild( ruleElement );
134 element.appendChild( rulesElement );
140 mEngineRules.clear();
142 const QDomElement rulesElement = element.firstChildElement( QStringLiteral(
"rules" ) );
143 const QDomNodeList
rules = rulesElement.childNodes();
144 for (
int i = 0; i <
rules.length(); i++ )
146 const QDomElement ruleElement =
rules.at( i ).toElement();
147 const QString
id = ruleElement.attribute( QStringLiteral(
"id" ) );
148 const QString name = ruleElement.attribute( QStringLiteral(
"name" ) );
149 const bool active = ruleElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"1" ) ).toInt();
153 rule->setName( name );
154 rule->setActive( active );
155 rule->readXml( ruleElement, context );
156 mEngineRules.emplace_back( std::move( rule ) );
164 for (
const auto &rule : mEngineRules )
166 rule->resolveReferences( project );
172 return mUnplacedLabelColor;
182 return mPlacementVersion;
192 QList<QgsAbstractLabelingEngineRule *> res;
193 for (
const auto &it : mEngineRules )
202 QList<const QgsAbstractLabelingEngineRule *> res;
203 for (
const auto &it : mEngineRules )
212 mEngineRules.emplace_back( rule );
217 mEngineRules.clear();
220 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.
Stores global configuration for labeling engine.
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.
The class is used as a container of context for various read/write operations on other objects.