32 : mFlags( other.mFlags )
33 , mSearchMethod( other.mSearchMethod )
34 , mMaxLineCandidatesPerCm( other.mMaxLineCandidatesPerCm )
35 , mMaxPolygonCandidatesPerCmSquared( other.mMaxPolygonCandidatesPerCmSquared )
36 , mUnplacedLabelColor( other.mUnplacedLabelColor )
37 , mPlacementVersion( other.mPlacementVersion )
38 , mDefaultTextRenderFormat( other.mDefaultTextRenderFormat )
41 mEngineRules.reserve( other.mEngineRules.size() );
42 for (
const auto &rule : other.mEngineRules )
44 mEngineRules.emplace_back( rule->clone() );
49 : mFlags( other.mFlags )
50 , mSearchMethod( other.mSearchMethod )
51 , mMaxLineCandidatesPerCm( other.mMaxLineCandidatesPerCm )
52 , mMaxPolygonCandidatesPerCmSquared( other.mMaxPolygonCandidatesPerCmSquared )
53 , mUnplacedLabelColor( std::move( other.mUnplacedLabelColor ) )
54 , mPlacementVersion( other.mPlacementVersion )
55 , mDefaultTextRenderFormat( other.mDefaultTextRenderFormat )
56 , mEngineRules( std::move( other.mEngineRules ) )
66 mFlags = other.mFlags;
67 mSearchMethod = other.mSearchMethod;
68 mMaxLineCandidatesPerCm = other.mMaxLineCandidatesPerCm;
69 mMaxPolygonCandidatesPerCmSquared = other.mMaxPolygonCandidatesPerCmSquared;
70 mUnplacedLabelColor = other.mUnplacedLabelColor;
71 mPlacementVersion = other.mPlacementVersion;
72 mDefaultTextRenderFormat = other.mDefaultTextRenderFormat;
74 mEngineRules.reserve( other.mEngineRules.size() );
75 for (
const auto &rule : other.mEngineRules )
77 mEngineRules.emplace_back( rule->clone() );
88 mFlags = other.mFlags;
89 mSearchMethod = other.mSearchMethod;
90 mMaxLineCandidatesPerCm = other.mMaxLineCandidatesPerCm;
91 mMaxPolygonCandidatesPerCmSquared = other.mMaxPolygonCandidatesPerCmSquared;
92 mUnplacedLabelColor = std::move( other.mUnplacedLabelColor );
93 mPlacementVersion = other.mPlacementVersion;
94 mDefaultTextRenderFormat = other.mDefaultTextRenderFormat;
95 mEngineRules = std::move( other.mEngineRules );
107 mSearchMethod =
static_cast< Search >( prj->
readNumEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/SearchMethod" ),
static_cast< int >(
Chain ), &saved ) );
108 mMaxLineCandidatesPerCm = prj->
readDoubleEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesLinePerCM" ), 5, &saved );
109 mMaxPolygonCandidatesPerCmSquared = prj->
readDoubleEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesPolygonPerCM" ), 2.5, &saved );
121 if ( !prj->
readBoolEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/DrawOutlineLabels" ),
true ) )
124 const int projectTextFormat = prj->
readNumEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/TextFormat" ), -1 );
125 if ( projectTextFormat >= 0 )
135 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/SearchMethod" ),
static_cast< int >( mSearchMethod ) );
136 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesLinePerCM" ), mMaxLineCandidatesPerCm );
137 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/CandidatesPolygonPerCM" ), mMaxPolygonCandidatesPerCmSquared );
146 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/TextFormat" ),
static_cast< int >( mDefaultTextRenderFormat ) );
150 project->
writeEntry( QStringLiteral(
"PAL" ), QStringLiteral(
"/PlacementEngineVersion" ),
static_cast< int >( mPlacementVersion ) );
155 if ( !mEngineRules.empty() )
157 QDomElement rulesElement = doc.createElement( QStringLiteral(
"rules" ) );
158 for (
const auto &rule : mEngineRules )
160 QDomElement ruleElement = doc.createElement( QStringLiteral(
"rule" ) );
161 ruleElement.setAttribute( QStringLiteral(
"id" ), rule->id() );
162 if ( !rule->name().isEmpty() )
163 ruleElement.setAttribute( QStringLiteral(
"name" ), rule->name() );
164 if ( !rule->active() )
165 ruleElement.setAttribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) );
166 rule->writeXml( doc, ruleElement, context );
167 rulesElement.appendChild( ruleElement );
169 element.appendChild( rulesElement );
175 mEngineRules.clear();
177 const QDomElement rulesElement = element.firstChildElement( QStringLiteral(
"rules" ) );
178 const QDomNodeList
rules = rulesElement.childNodes();
179 for (
int i = 0; i <
rules.length(); i++ )
181 const QDomElement ruleElement =
rules.at( i ).toElement();
182 const QString
id = ruleElement.attribute( QStringLiteral(
"id" ) );
183 const QString name = ruleElement.attribute( QStringLiteral(
"name" ) );
184 const bool active = ruleElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"1" ) ).toInt();
188 rule->setName( name );
189 rule->setActive( active );
190 rule->readXml( ruleElement, context );
191 mEngineRules.emplace_back( std::move( rule ) );
199 for (
const auto &rule : mEngineRules )
201 rule->resolveReferences( project );
207 return mUnplacedLabelColor;
217 return mPlacementVersion;
227 QList<QgsAbstractLabelingEngineRule *> res;
228 for (
const auto &it : mEngineRules )
237 QList<const QgsAbstractLabelingEngineRule *> res;
238 for (
const auto &it : mEngineRules )
247 mEngineRules.emplace_back( rule );
252 mEngineRules.clear();
255 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.