QGIS API Documentation 3.99.0-Master (752b475928d)
Loading...
Searching...
No Matches
pal::Pal Class Reference

Main Pal labeling class. More...

#include <pal.h>

Public Types

typedef bool(* FnIsCanceled) (void *ctx)
 Cancellation check callback function.

Public Member Functions

 Pal ()
 Pal (const Pal &other)=delete
 ~Pal ()
LayeraddLayer (QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel)
 add a new layer
bool candidatesAreConflicting (const LabelPosition *lp1, const LabelPosition *lp2) const
 Returns true if a labelling candidate lp1 conflicts with lp2.
std::unique_ptr< ProblemextractProblem (const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context)
 Extracts the labeling problem for the specified map extent - only features within this extent will be considered.
int globalCandidatesLimitLine () const
 Returns the global candidates limit for line features, or 0 if no global limit is in effect.
int globalCandidatesLimitPoint () const
 Returns the global candidates limit for point features, or 0 if no global limit is in effect.
int globalCandidatesLimitPolygon () const
 Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
bool isCanceled ()
 Check whether the job has been canceled.
double maximumLineCandidatesPerMapUnit () const
 Returns the maximum number of line label candidate positions per map unit.
double maximumPolygonCandidatesPerMapUnitSquared () const
 Returns the maximum number of polygon label candidate positions per map unit squared.
Paloperator= (const Pal &other)=delete
Qgis::LabelPlacementEngineVersion placementVersion () const
 Returns the placement engine version, which dictates how the label placement problem is solved.
void registerCancellationCallback (FnIsCanceled fnCanceled, void *context)
 Register a function that returns whether this job has been canceled - PAL calls it during the computation.
void removeLayer (Layer *layer)
 remove a layer
QList< QgsAbstractLabelingEngineRule * > rules () const
 Returns the rules which the labeling solution must satisfy.
void setMaximumLineCandidatesPerMapUnit (double candidates)
 Sets the maximum number of line label candidates per map unit.
void setMaximumPolygonCandidatesPerMapUnitSquared (double candidates)
 Sets the maximum number of polygon label candidates per map unit squared.
void setPlacementVersion (Qgis::LabelPlacementEngineVersion placementVersion)
 Sets the placement engine version, which dictates how the label placement problem is solved.
void setRules (const QList< QgsAbstractLabelingEngineRule * > &rules)
 Sets rules which the labeling solution must satisfy.
void setShowPartialLabels (bool show)
 Sets whether partial labels show be allowed.
bool showPartialLabels () const
 Returns whether partial labels should be allowed.
QList< LabelPosition * > solveProblem (Problem *prob, QgsRenderContext &context, bool displayAll, QList< pal::LabelPosition * > *unlabeled=nullptr)
 Solves the labeling problem, selecting the best candidate locations for all labels and returns a list of these calculated label positions.

Static Public Attributes

static const QgsSettingsEntryIntegersettingsRenderingLabelCandidatesLimitLines = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-lines" ), sTreePal, 0 )
static const QgsSettingsEntryIntegersettingsRenderingLabelCandidatesLimitPoints = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-points" ), sTreePal, 0 )
static const QgsSettingsEntryIntegersettingsRenderingLabelCandidatesLimitPolygons = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-polygons" ), sTreePal, 0 )
static QgsSettingsTreeNodesTreePal = QgsSettingsTree::sTreeRendering->createChildNode( QStringLiteral( "pal" ) )

Friends

class FeaturePart
class Layer
class Problem

Detailed Description

Main Pal labeling class.

A pal object will contains layers and global information such as which search method will be used.

Note
not available in Python bindings

Definition at line 83 of file pal.h.

Member Typedef Documentation

◆ FnIsCanceled

typedef bool(* pal::Pal::FnIsCanceled) (void *ctx)

Cancellation check callback function.

Definition at line 124 of file pal.h.

Constructor & Destructor Documentation

◆ Pal() [1/2]

Pal::Pal ( )

Definition at line 63 of file pal.cpp.

◆ ~Pal()

Pal::~Pal ( )
default

◆ Pal() [2/2]

pal::Pal::Pal ( const Pal & other)
delete

Member Function Documentation

◆ addLayer()

Layer * Pal::addLayer ( QgsAbstractLabelProvider * provider,
const QString & layerName,
Qgis::LabelPlacement arrangement,
double defaultPriority,
bool active,
bool toLabel )

add a new layer

Parameters
providerProvider associated with the layer
layerNamelayer's name
arrangementHowto place candidates
defaultPrioritylayer's priority (0 is the best, 1 the worst)
activeis the layer is active (currently displayed)
toLabelthe layer will be labeled only if toLablel is true
Exceptions
PalException::LayerExists

Definition at line 90 of file pal.cpp.

◆ candidatesAreConflicting()

bool Pal::candidatesAreConflicting ( const LabelPosition * lp1,
const LabelPosition * lp2 ) const

Returns true if a labelling candidate lp1 conflicts with lp2.

Definition at line 760 of file pal.cpp.

◆ extractProblem()

std::unique_ptr< Problem > Pal::extractProblem ( const QgsRectangle & extent,
const QgsGeometry & mapBoundary,
QgsRenderContext & context )

Extracts the labeling problem for the specified map extent - only features within this extent will be considered.

The mapBoundary argument specifies the actual geometry of the map boundary, which will be used to detect whether a label is visible (or partially visible) in the rendered map. This may differ from extent in the case of rotated or non-rectangular maps.

This method:

  • preprocesses features, eg merging connected lines, chopping features at repeat distances
  • creates label candidates for every feature
  • purges candidates outside the map extent (respecting whether partial labels should be shown at the map boundary)
  • creates default fallback candidates for features with no valid candidates
  • collects obstacles
  • calculates candidate costs
  • calculates overlaps/conflicts
  • eliminates hard conflicts (forbidden placement)

Definition at line 110 of file pal.cpp.

◆ globalCandidatesLimitLine()

int pal::Pal::globalCandidatesLimitLine ( ) const
inline

Returns the global candidates limit for line features, or 0 if no global limit is in effect.

This is an installation-wide setting which applies to all projects, and is set via QSettings. It can be used to place global limits on the number of candidates generated for line features in order to optimise map rendering speeds.

See also
globalCandidatesLimitPolygon()
globalCandidatesLimitPoint()

Definition at line 244 of file pal.h.

◆ globalCandidatesLimitPoint()

int pal::Pal::globalCandidatesLimitPoint ( ) const
inline

Returns the global candidates limit for point features, or 0 if no global limit is in effect.

This is an installation-wide setting which applies to all projects, and is set via QSettings. It can be used to place global limits on the number of candidates generated for point features in order to optimise map rendering speeds.

See also
globalCandidatesLimitLine()
globalCandidatesLimitPolygon()

Definition at line 232 of file pal.h.

◆ globalCandidatesLimitPolygon()

int pal::Pal::globalCandidatesLimitPolygon ( ) const
inline

Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.

This is an installation-wide setting which applies to all projects, and is set via QSettings. It can be used to place global limits on the number of candidates generated for polygon features in order to optimise map rendering speeds.

See also
globalCandidatesLimitLine()
globalCandidatesLimitPoint()

Definition at line 256 of file pal.h.

◆ isCanceled()

bool pal::Pal::isCanceled ( )
inline

Check whether the job has been canceled.

Definition at line 130 of file pal.h.

◆ maximumLineCandidatesPerMapUnit()

double pal::Pal::maximumLineCandidatesPerMapUnit ( ) const
inline

Returns the maximum number of line label candidate positions per map unit.

See also
setMaximumLineCandidatesPerMapUnit()

Definition at line 185 of file pal.h.

◆ maximumPolygonCandidatesPerMapUnitSquared()

double pal::Pal::maximumPolygonCandidatesPerMapUnitSquared ( ) const
inline

Returns the maximum number of polygon label candidate positions per map unit squared.

See also
setMaximumPolygonCandidatesPerMapUnitSquared()

Definition at line 199 of file pal.h.

◆ operator=()

Pal & pal::Pal::operator= ( const Pal & other)
delete

◆ placementVersion()

Qgis::LabelPlacementEngineVersion Pal::placementVersion ( ) const

Returns the placement engine version, which dictates how the label placement problem is solved.

See also
setPlacementVersion()

Definition at line 750 of file pal.cpp.

◆ registerCancellationCallback()

void Pal::registerCancellationCallback ( Pal::FnIsCanceled fnCanceled,
void * context )

Register a function that returns whether this job has been canceled - PAL calls it during the computation.

Definition at line 651 of file pal.cpp.

◆ removeLayer()

void Pal::removeLayer ( Layer * layer)

remove a layer

Parameters
layerlayer to remove

Definition at line 72 of file pal.cpp.

◆ rules()

QList< QgsAbstractLabelingEngineRule * > pal::Pal::rules ( ) const
inline

Returns the rules which the labeling solution must satisfy.

See also
setRules()
Since
QGIS 3.40

Definition at line 280 of file pal.h.

◆ setMaximumLineCandidatesPerMapUnit()

void pal::Pal::setMaximumLineCandidatesPerMapUnit ( double candidates)
inline

Sets the maximum number of line label candidates per map unit.

See also
maximumLineCandidatesPerMapUnit()

Definition at line 192 of file pal.h.

◆ setMaximumPolygonCandidatesPerMapUnitSquared()

void pal::Pal::setMaximumPolygonCandidatesPerMapUnitSquared ( double candidates)
inline

Sets the maximum number of polygon label candidates per map unit squared.

See also
maximumPolygonCandidatesPerMapUnitSquared()

Definition at line 206 of file pal.h.

◆ setPlacementVersion()

void Pal::setPlacementVersion ( Qgis::LabelPlacementEngineVersion placementVersion)

Sets the placement engine version, which dictates how the label placement problem is solved.

See also
placementVersion()

Definition at line 755 of file pal.cpp.

◆ setRules()

void Pal::setRules ( const QList< QgsAbstractLabelingEngineRule * > & rules)

Sets rules which the labeling solution must satisfy.

Ownership of the rules are not transferred to the engine, and it is the caller's responsibility to ensure that the lifetime of the rules exceeds that of the pal job.

See also
rules()
Since
QGIS 3.40

Definition at line 819 of file pal.cpp.

◆ setShowPartialLabels()

void Pal::setShowPartialLabels ( bool show)

Sets whether partial labels show be allowed.

See also
showPartialLabels()

Definition at line 745 of file pal.cpp.

◆ showPartialLabels()

bool Pal::showPartialLabels ( ) const

Returns whether partial labels should be allowed.

See also
setShowPartialLabels()

Definition at line 834 of file pal.cpp.

◆ solveProblem()

QList< LabelPosition * > Pal::solveProblem ( Problem * prob,
QgsRenderContext & context,
bool displayAll,
QList< pal::LabelPosition * > * unlabeled = nullptr )

Solves the labeling problem, selecting the best candidate locations for all labels and returns a list of these calculated label positions.

If displayAll is true, then the best positions for ALL labels will be returned, regardless of whether these labels overlap other labels.

If the optional unlabeled list is specified, it will be filled with a list of all feature labels which could not be placed in the returned solution (e.g. due to overlaps or other constraints).

Ownership of the returned labels is not transferred - it resides with the pal object.

Definition at line 658 of file pal.cpp.

◆ FeaturePart

friend class FeaturePart
friend

Definition at line 86 of file pal.h.

◆ Layer

friend class Layer
friend

Definition at line 87 of file pal.h.

◆ Problem

friend class Problem
friend

Definition at line 85 of file pal.h.

Member Data Documentation

◆ settingsRenderingLabelCandidatesLimitLines

const QgsSettingsEntryInteger * Pal::settingsRenderingLabelCandidatesLimitLines = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-lines" ), sTreePal, 0 )
static

Definition at line 93 of file pal.h.

◆ settingsRenderingLabelCandidatesLimitPoints

const QgsSettingsEntryInteger * Pal::settingsRenderingLabelCandidatesLimitPoints = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-points" ), sTreePal, 0 )
static

Definition at line 92 of file pal.h.

◆ settingsRenderingLabelCandidatesLimitPolygons

const QgsSettingsEntryInteger * Pal::settingsRenderingLabelCandidatesLimitPolygons = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-polygons" ), sTreePal, 0 )
static

Definition at line 94 of file pal.h.

◆ sTreePal

QgsSettingsTreeNode* pal::Pal::sTreePal = QgsSettingsTree::sTreeRendering->createChildNode( QStringLiteral( "pal" ) )
inlinestatic

Definition at line 90 of file pal.h.


The documentation for this class was generated from the following files: