QGIS API Documentation  3.9.0-Master (224899f119)
Public Types | Public Member Functions | Friends | List of all members
pal::Pal Class Reference

Main Pal labeling class. More...

#include <pal.h>

Public Types

typedef bool(* FnIsCanceled) (void *ctx)
 

Public Member Functions

 Pal ()
 Create an new pal instance. More...
 
 Pal (const Pal &other)=delete
 Pal cannot be copied. More...
 
 ~Pal ()
 
LayeraddLayer (QgsAbstractLabelProvider *provider, const QString &layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll=false)
 add a new layer More...
 
std::unique_ptr< ProblemextractProblem (const QgsRectangle &extent, const QgsGeometry &mapBoundary)
 Extracts the labeling problem for the specified map extent - only features within this extent will be considered. More...
 
int getLineP ()
 Returns the number of candidates to generate for line features. More...
 
int getPointP ()
 Returns the number of candidates to generate for point features. More...
 
int getPolyP ()
 Returns the number of candidates to generate for polygon features. More...
 
bool getShowPartial ()
 Returns whether partial labels should be allowed. More...
 
bool isCanceled ()
 Check whether the job has been canceled. More...
 
Paloperator= (const Pal &other)=delete
 Pal cannot be copied. More...
 
void registerCancellationCallback (FnIsCanceled fnCanceled, void *context)
 Register a function that returns whether this job has been canceled - PAL calls it during the computation. More...
 
void removeLayer (Layer *layer)
 remove a layer More...
 
void setLineP (int line_p)
 set maximum # candidates to generate for lines features Higher the value is, longer Pal::labeller will spend time More...
 
void setPointP (int point_p)
 set # candidates to generate for points features Higher the value is, longer Pal::labeller will spend time More...
 
void setPolyP (int poly_p)
 set maximum # candidates to generate for polygon features Higher the value is, longer Pal::labeller will spend time More...
 
void setShowPartial (bool show)
 Set flag show partial label. More...
 
QList< LabelPosition * > solveProblem (Problem *prob, 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. More...
 

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 87 of file pal.h.

Member Typedef Documentation

◆ FnIsCanceled

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

Definition at line 129 of file pal.h.

Constructor & Destructor Documentation

◆ Pal() [1/2]

Pal::Pal ( )

Create an new pal instance.

Definition at line 48 of file pal.cpp.

◆ ~Pal()

Pal::~Pal ( )

Definition at line 68 of file pal.cpp.

◆ Pal() [2/2]

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

Pal cannot be copied.

Member Function Documentation

◆ addLayer()

Layer * Pal::addLayer ( QgsAbstractLabelProvider provider,
const QString &  layerName,
QgsPalLayerSettings::Placement  arrangement,
double  defaultPriority,
bool  active,
bool  toLabel,
bool  displayAll = false 
)

add a new layer

Parameters
providerProvider associated with the layer
layerNamelayer's name
arrangementHowto place candidates
defaultPrioritylayer's prioriry (0 is the best, 1 the worst)
activeis the layer is active (currently displayed)
toLabelthe layer will be labeled only if toLablel is true
displayAllif true, all features will be labelled even though overlaps occur
Exceptions
PalException::LayerExists

Definition at line 81 of file pal.cpp.

◆ extractProblem()

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

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.

Definition at line 420 of file pal.cpp.

◆ getLineP()

int Pal::getLineP ( )

Returns the number of candidates to generate for line features.

Definition at line 507 of file pal.cpp.

◆ getPointP()

int Pal::getPointP ( )

Returns the number of candidates to generate for point features.

Definition at line 502 of file pal.cpp.

◆ getPolyP()

int Pal::getPolyP ( )

Returns the number of candidates to generate for polygon features.

Definition at line 512 of file pal.cpp.

◆ getShowPartial()

bool Pal::getShowPartial ( )

Returns whether partial labels should be allowed.

Definition at line 527 of file pal.cpp.

◆ isCanceled()

bool pal::Pal::isCanceled ( )
inline

Check whether the job has been canceled.

Definition at line 135 of file pal.h.

◆ operator=()

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

Pal cannot be copied.

◆ 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 414 of file pal.cpp.

◆ removeLayer()

void Pal::removeLayer ( Layer layer)

remove a layer

Parameters
layerlayer to remove

Definition at line 54 of file pal.cpp.

◆ setLineP()

void Pal::setLineP ( int  line_p)

set maximum # candidates to generate for lines features Higher the value is, longer Pal::labeller will spend time

Parameters
line_pmaximum # candidates for a line

Definition at line 451 of file pal.cpp.

◆ setPointP()

void Pal::setPointP ( int  point_p)

set # candidates to generate for points features Higher the value is, longer Pal::labeller will spend time

Parameters
point_p# candidates for a point

Definition at line 445 of file pal.cpp.

◆ setPolyP()

void Pal::setPolyP ( int  poly_p)

set maximum # candidates to generate for polygon features Higher the value is, longer Pal::labeller will spend time

Parameters
poly_pmaximum # candidate for a polygon

Definition at line 457 of file pal.cpp.

◆ setShowPartial()

void Pal::setShowPartial ( bool  show)

Set flag show partial label.

Parameters
showflag value

Definition at line 497 of file pal.cpp.

◆ solveProblem()

QList< LabelPosition * > Pal::solveProblem ( Problem prob,
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 425 of file pal.cpp.

Friends And Related Function Documentation

◆ FeaturePart

friend class FeaturePart
friend

Definition at line 90 of file pal.h.

◆ Layer

friend class Layer
friend

Definition at line 91 of file pal.h.

◆ Problem

friend class Problem
friend

Definition at line 89 of file pal.h.


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