QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
|
The QgsLabelingEngine class provides map labeling functionality. More...
#include <qgslabelingengine.h>
Public Member Functions | |
QgsLabelingEngine () | |
Construct the labeling engine with default settings. | |
QgsLabelingEngine (const QgsLabelingEngine &rh)=delete | |
virtual | ~QgsLabelingEngine () |
Clean up everything (especially the registered providers) | |
QString | addProvider (QgsAbstractLabelProvider *provider) |
Adds a provider of label features. | |
const QgsLabelingEngineSettings & | engineSettings () const |
Gets associated labeling engine settings. | |
const QgsMapSettings & | mapSettings () const |
Gets associated map settings. | |
QgsLabelingEngine & | operator= (const QgsLabelingEngine &rh)=delete |
QStringList | participatingLayerIds () const |
Returns a list of layer IDs for layers with providers in the engine. | |
QList< QgsMapLayer * > | participatingLayers () const |
Returns a list of layers with providers in the engine. | |
bool | prepare (QgsRenderContext &context) |
Prepares the engine for rendering in the specified context. | |
QgsAbstractLabelProvider * | providerById (const QString &id) |
Returns the provider with matching id, where id corresponds to the value returned by the addProvider() call. | |
void | removeProvider (QgsAbstractLabelProvider *provider) |
Remove provider if the provider's initialization failed. Provider instance is deleted. | |
QgsLabelingResults * | results () const |
For internal use by the providers. | |
virtual void | run (QgsRenderContext &context)=0 |
Runs the labeling job. | |
void | setMapSettings (const QgsMapSettings &mapSettings) |
Associate map settings instance. | |
QgsLabelingResults * | takeResults () |
Returns pointer to recently computed results and pass the ownership of results to the caller. | |
Protected Member Functions | |
void | cleanup () |
Cleans up the engine following a call to registerLabels() or solve(). | |
void | drawLabels (QgsRenderContext &context, const QString &layerId=QString()) |
Draws labels to the specified render context. | |
void | processProvider (QgsAbstractLabelProvider *provider, QgsRenderContext &context, pal::Pal &p) |
void | registerLabels (QgsRenderContext &context) |
Runs the label registration step. | |
void | solve (QgsRenderContext &context) |
Solves the label problem. | |
Protected Attributes | |
std::vector< std::unique_ptr< QgsAbstractLabelingEngineRule > > | mEngineRules |
QList< pal::LabelPosition * > | mLabels |
QgsMapSettings | mMapSettings |
Associated map settings instance. | |
std::unique_ptr< pal::Pal > | mPal |
std::unique_ptr< pal::Problem > | mProblem |
QList< QgsAbstractLabelProvider * > | mProviders |
List of providers (the are owned by the labeling engine) | |
QHash< QString, QgsAbstractLabelProvider * > | mProvidersById |
std::unique_ptr< QgsLabelingResults > | mResults |
Resulting labeling layout. | |
QList< QgsAbstractLabelProvider * > | mSubProviders |
List of labeling engine rules (owned by the labeling engine) | |
QList< pal::LabelPosition * > | mUnlabeled |
The QgsLabelingEngine class provides map labeling functionality.
The input for the engine is a list of label provider objects and map settings. Based on the input, the engine computes layout of labels for the given map view with no collisions between the labels. Drawing of resulting labels is done again by label providers.
The labeling engine is used for the map rendering in QgsMapRendererJob instances, individual map layer renderers may add label providers - for example, QgsVectorLayerRenderer may add text label provider and diagram provider (if labeling / diagrams were configured for such vector layer).
The labeling engine may also be used independently from map rendering loop:
Definition at line 340 of file qgslabelingengine.h.
QgsLabelingEngine::QgsLabelingEngine | ( | ) |
Construct the labeling engine with default settings.
Definition at line 88 of file qgslabelingengine.cpp.
|
virtual |
Clean up everything (especially the registered providers)
Definition at line 92 of file qgslabelingengine.cpp.
|
delete |
QString QgsLabelingEngine::addProvider | ( | QgsAbstractLabelProvider * | provider | ) |
Adds a provider of label features.
Takes ownership of the provider.
Returns a generated string uniqueuly identifying the provider, which can be used with the providerById() method to retrieve the provider at a later stage.
Definition at line 214 of file qgslabelingengine.cpp.
|
protected |
Cleans up the engine following a call to registerLabels() or solve().
Definition at line 593 of file qgslabelingengine.cpp.
|
protected |
Draws labels to the specified render context.
If layerId is specified, only labels from the matching layer will be rendered.
Must be preceded by a call to registerLabels() and solve()
Definition at line 458 of file qgslabelingengine.cpp.
|
inline |
Gets associated labeling engine settings.
Definition at line 357 of file qgslabelingengine.h.
|
inline |
Gets associated map settings.
Definition at line 354 of file qgslabelingengine.h.
|
delete |
QStringList QgsLabelingEngine::participatingLayerIds | ( | ) | const |
Returns a list of layer IDs for layers with providers in the engine.
Definition at line 168 of file qgslabelingengine.cpp.
QList< QgsMapLayer * > QgsLabelingEngine::participatingLayers | ( | ) | const |
Returns a list of layers with providers in the engine.
Definition at line 122 of file qgslabelingengine.cpp.
bool QgsLabelingEngine::prepare | ( | QgsRenderContext & | context | ) |
Prepares the engine for rendering in the specified context.
Definition at line 106 of file qgslabelingengine.cpp.
|
protected |
Definition at line 238 of file qgslabelingengine.cpp.
QgsAbstractLabelProvider * QgsLabelingEngine::providerById | ( | const QString & | id | ) |
Returns the provider with matching id, where id corresponds to the value returned by the addProvider() call.
Returns nullptr
if no matching provider is found.
Definition at line 223 of file qgslabelingengine.cpp.
|
protected |
Runs the label registration step.
Must be called by subclasses prior to solve() and drawLabels()
Definition at line 287 of file qgslabelingengine.cpp.
void QgsLabelingEngine::removeProvider | ( | QgsAbstractLabelProvider * | provider | ) |
Remove provider if the provider's initialization failed. Provider instance is deleted.
Definition at line 228 of file qgslabelingengine.cpp.
|
inline |
For internal use by the providers.
Definition at line 412 of file qgslabelingengine.h.
|
pure virtual |
Runs the labeling job.
Depending on the concrete labeling engine class, this will either run the whole labeling job, including rendering the labels themselves, OR possibly just run the labeling job but leave the rendering to a future, deferred stage.
Implemented in QgsDefaultLabelingEngine, and QgsStagedRenderLabelingEngine.
void QgsLabelingEngine::setMapSettings | ( | const QgsMapSettings & | mapSettings | ) |
Associate map settings instance.
Definition at line 98 of file qgslabelingengine.cpp.
|
protected |
Solves the label problem.
Must be called by subclasses prior to drawLabels(), and must be preceded by a call to registerLabels()
Definition at line 342 of file qgslabelingengine.cpp.
QgsLabelingResults * QgsLabelingEngine::takeResults | ( | ) |
Returns pointer to recently computed results and pass the ownership of results to the caller.
Definition at line 601 of file qgslabelingengine.cpp.
|
protected |
Definition at line 464 of file qgslabelingengine.h.
|
protected |
Definition at line 472 of file qgslabelingengine.h.
|
protected |
Associated map settings instance.
Definition at line 456 of file qgslabelingengine.h.
|
protected |
Definition at line 469 of file qgslabelingengine.h.
|
protected |
Definition at line 470 of file qgslabelingengine.h.
|
protected |
List of providers (the are owned by the labeling engine)
Definition at line 459 of file qgslabelingengine.h.
|
protected |
Definition at line 460 of file qgslabelingengine.h.
|
protected |
Resulting labeling layout.
Definition at line 467 of file qgslabelingengine.h.
|
protected |
List of labeling engine rules (owned by the labeling engine)
Definition at line 461 of file qgslabelingengine.h.
|
protected |
Definition at line 471 of file qgslabelingengine.h.