39#include "moc_qgslabelingengine.cpp"
41using namespace Qt::StringLiterals;
44static bool _palIsCanceled(
void *ctx )
46 return (
reinterpret_cast< QgsRenderContext *
>( ctx ) )->renderingStopped();
60 explicit QgsLabelSorter(
const QStringList &layerRenderingOrderIds )
61 : mLayerRenderingOrderIds( layerRenderingOrderIds )
64 bool operator()( pal::LabelPosition *lp1, pal::LabelPosition *lp2 )
const
73 int layer1Pos = mLayerRenderingOrderIds.indexOf( lf1->
provider()->
layerId() );
74 int layer2Pos = mLayerRenderingOrderIds.indexOf( lf2->
provider()->
layerId() );
75 if ( layer1Pos != layer2Pos && layer1Pos >= 0 && layer2Pos >= 0 )
76 return layer1Pos > layer2Pos;
79 return lf1->
size().width() * lf1->
size().height() > lf2->
size().width() * lf2->
size().height();
84 const QStringList mLayerRenderingOrderIds;
113 const QList<const QgsAbstractLabelingEngineRule *> rules =
mMapSettings.labelingEngineSettings().rules();
117 if ( !rule->active() || !rule->isAvailable() )
120 std::unique_ptr< QgsAbstractLabelingEngineRule > ruleClone( rule->clone() );
121 res = ruleClone->prepare( context ) && res;
129 QList< QgsMapLayer * > layers;
132 QList< QgsAbstractLabelProvider * > providersByZ =
mProviders;
133 std::sort( providersByZ.begin(), providersByZ.end(),
136 const QgsVectorLayerLabelProvider *providerA = dynamic_cast<const QgsVectorLayerLabelProvider *>( a );
137 const QgsVectorLayerLabelProvider *providerB = dynamic_cast<const QgsVectorLayerLabelProvider *>( b );
139 if ( providerA && providerB )
141 return providerA->settings().zIndex < providerB->settings().zIndex ;
146 QList< QgsAbstractLabelProvider * > subProvidersByZ = mSubProviders;
147 std::sort( subProvidersByZ.begin(), subProvidersByZ.end(),
150 const QgsVectorLayerLabelProvider *providerA = dynamic_cast<const QgsVectorLayerLabelProvider *>( a );
151 const QgsVectorLayerLabelProvider *providerB = dynamic_cast<const QgsVectorLayerLabelProvider *>( b );
153 if ( providerA && providerB )
155 return providerA->settings().zIndex < providerB->settings().zIndex ;
162 if ( provider->layer() && !layers.contains( provider->layer() ) )
163 layers << provider->layer();
167 if ( provider->layer() && !layers.contains( provider->layer() ) )
168 layers << provider->layer();
178 QList< QgsAbstractLabelProvider * > providersByZ =
mProviders;
179 std::sort( providersByZ.begin(), providersByZ.end(),
182 const QgsVectorLayerLabelProvider *providerA = dynamic_cast<const QgsVectorLayerLabelProvider *>( a );
183 const QgsVectorLayerLabelProvider *providerB = dynamic_cast<const QgsVectorLayerLabelProvider *>( b );
185 if ( providerA && providerB )
187 return providerA->settings().zIndex < providerB->settings().zIndex ;
192 QList< QgsAbstractLabelProvider * > subProvidersByZ = mSubProviders;
193 std::sort( subProvidersByZ.begin(), subProvidersByZ.end(),
196 const QgsVectorLayerLabelProvider *providerA = dynamic_cast<const QgsVectorLayerLabelProvider *>( a );
197 const QgsVectorLayerLabelProvider *providerB = dynamic_cast<const QgsVectorLayerLabelProvider *>( b );
199 if ( providerA && providerB )
201 return providerA->settings().zIndex < providerB->settings().zIndex ;
208 if ( !layers.contains( provider->layerId() ) )
209 layers << provider->layerId();
213 if ( !layers.contains( provider->layerId() ) )
214 layers << provider->layerId();
223 const QString
id = QUuid::createUuid().toString( QUuid::WithoutBraces );
267 const QList<QgsLabelFeature *> features = provider->
labelFeatures( context );
275 catch ( std::exception &e )
278 QgsDebugMsgLevel( u
"Ignoring feature %1 due PAL exception:"_s.arg( feature->id() ) + QString::fromLatin1( e.what() ), 4 );
294 std::unique_ptr< QgsScopedRuntimeProfile > registeringProfile;
297 registeringProfile = std::make_unique< QgsScopedRuntimeProfile >( QObject::tr(
"Registering labels" ), u
"rendering"_s );
303 feedback->emit labelRegistrationAboutToBegin();
307 mPal = std::make_unique< pal::Pal >();
315 QList< QgsAbstractLabelingEngineRule * > rules;
316 rules.reserve(
static_cast< int >(
mEngineRules.size() ) );
319 rules.append( it.get() );
321 mPal->setRules( rules );
330 feedback->emit providerRegistrationAboutToBegin( provider );
334 std::unique_ptr< QgsExpressionContextScopePopper > layerScopePopper;
335 if ( provider->layerExpressionContextScope() )
341 feedback->emit providerRegistrationFinished( provider );
344 feedback->emit labelRegistrationFinished();
349 Q_ASSERT(
mPal.get() );
354 QPainter *painter = context.
painter();
360 QPolygonF visiblePoly =
mMapSettings.visiblePolygonWithBuffer();
361 visiblePoly.append( visiblePoly.at( 0 ) );
367 const QList< QgsLabelBlockingRegion > blockingRegions =
mMapSettings.labelBlockingRegions();
370 mapBoundaryGeom = mapBoundaryGeom.
difference( region.geometry );
378 QVariantMap properties;
379 properties.insert( u
"style"_s, u
"no"_s );
380 properties.insert( u
"style_border"_s, u
"solid"_s );
381 properties.insert( u
"color_border"_s, u
"#0000ff"_s );
382 properties.insert( u
"width_border"_s, u
"0.3"_s );
383 properties.insert( u
"joinstyle"_s, u
"miter"_s );
385 boundarySymbol->startRender( context );
386 boundarySymbol->renderFeature( f, context );
387 boundarySymbol->stopRender( context );
400 mPal->registerCancellationCallback( &_palIsCanceled,
reinterpret_cast< void *
>( &context ) );
408 mProblem =
mPal->extractProblem( extent, mapBoundaryGeom, context );
410 catch ( std::exception &e )
413 QgsDebugMsgLevel(
"PAL EXCEPTION :-( " + QString::fromLatin1( e.what() ), 4 );
439 painter->setBrush( Qt::NoBrush );
440 for (
int i = 0; i < static_cast< int >(
mProblem->featureCount() ); i++ )
442 for (
int j = 0; j <
mProblem->featureCandidateCount( i ); j++ )
458 std::sort(
mLabels.begin(),
mLabels.end(), QgsLabelSorter( mLayerRenderingOrderIds ) );
468 std::unique_ptr< QgsScopedRuntimeProfile > drawingProfile;
471 drawingProfile = std::make_unique< QgsScopedRuntimeProfile >( QObject::tr(
"Rendering labels" ), u
"rendering"_s );
477 QPainter *painter = context.
painter();
482 if ( !layerId.isEmpty() && provider->layerId() != layerId )
490 provider->startRender( context );
494 auto symbolScopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.
expressionContext(), symbolScope );
537 QgsPointXY outPt2 = xform.
transform( label->getX() + label->getWidth(), label->getY() + label->getHeight() );
538 QRectF rect( 0, 0, outPt2.
x() - outPt.x(), outPt2.
y() - outPt.y() );
540 painter->setRenderHint( QPainter::Antialiasing,
false );
541 painter->translate( QPointF( outPt.x(), outPt.y() ) );
542 painter->rotate( -label->getAlpha() * 180 / M_PI );
544 if ( label->conflictsWithObstacle() )
546 painter->setBrush( QColor( 255, 0, 0, 100 ) );
547 painter->setPen( QColor( 255, 0, 0, 150 ) );
551 painter->setBrush( QColor( 0, 255, 0, 100 ) );
552 painter->setPen( QColor( 0, 255, 0, 150 ) );
555 painter->drawRect( rect );
559 drawLabelRect( nextPart );
564 drawLabelRect( label );
571 drawLabelRect( label );
587 drawLabelMetricsRecursive = [&xform, &context, &drawLabelMetricsRecursive](
pal::LabelPosition * label )
592 drawLabelMetricsRecursive( nextPart );
597 drawLabelMetricsRecursive( label );
660 symbolScopePopper.reset();
665 if ( !layerId.isEmpty() && provider->layerId() != layerId )
668 provider->stopRender( context );
672 painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
692 QPainter *painter = context.
painter();
701 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
702 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
703 painter->rotate( -lp->
getAlpha() * 180 / M_PI );
707 painter->setPen( QColor( 255, 0, 0, 64 ) );
711 painter->setPen( QColor( 0, 0, 0, 64 ) );
713 painter->drawRect( rect );
717 rect.moveTo( outPt.
x(), outPt.
y() );
728 QPainter *painter = context.
painter();
733 QRectF rect( 0, 0, outPt2.
x() - renderPoint.x(), outPt2.
y() - renderPoint.y() );
735 painter->setRenderHint( QPainter::Antialiasing,
false );
736 painter->translate( QPointF( renderPoint.x(), renderPoint.y() ) );
737 painter->rotate( -label->
getAlpha() * 180 / M_PI );
739 painter->setBrush( Qt::NoBrush );
740 painter->setPen( QColor( 255, 0, 0, 220 ) );
742 painter->drawRect( rect );
744 painter->setPen( QColor( 0, 0, 0, 60 ) );
746 if ( margins.
top() > 0 )
749 painter->drawLine( QPointF( rect.left(), rect.top() - topMargin ), QPointF( rect.right(), rect.top() - topMargin ) );
751 if ( margins.
bottom() > 0 )
754 painter->drawLine( QPointF( rect.left(), rect.bottom() + bottomMargin ), QPointF( rect.right(), rect.bottom() + bottomMargin ) );
758 if ( !outerBounds.isNull() )
760 const QRectF mapOuterBounds = QRectF( label->
getX() + outerBounds.left(),
761 label->
getY() + outerBounds.top(),
762 outerBounds.width(), outerBounds.height() );
764 QgsPointXY outerBoundsPt1 = xform.
transform( mapOuterBounds.left(), mapOuterBounds.top() );
765 QgsPointXY outerBoundsPt2 = xform.
transform( mapOuterBounds.right(), mapOuterBounds.bottom() );
767 const QRectF outerBoundsPixel( outerBoundsPt1.
x() - renderPoint.x(),
768 outerBoundsPt1.
y() - renderPoint.y(),
769 outerBoundsPt2.
x() - outerBoundsPt1.
x(),
770 outerBoundsPt2.
y() - outerBoundsPt1.
y() );
772 QPen pen( QColor( 255, 0, 255, 140 ) );
773 pen.setCosmetic(
true );
775 painter->setPen( pen );
776 painter->drawRect( outerBoundsPixel );
783 const int blockCount = document.
size();
785 double prevBlockBaseline = rect.bottom() - rect.top();
789 for (
int blockIndex = 0; blockIndex < blockCount; ++blockIndex )
794 const int fragmentCount = block.
size();
796 for (
int fragmentIndex = 0; fragmentIndex < fragmentCount; ++fragmentIndex )
801 if ( fragmentIndex > 0 )
803 QPen pen( QColor( 0, 0, 255, 220 ) );
804 pen.setStyle( Qt::PenStyle::DashLine );
806 painter->setPen( pen );
808 painter->drawLine( QPointF( rect.left() + left, rect.top() + blockBaseLine + fragmentVerticalOffset + verticalAlignOffset ),
809 QPointF( rect.left() + left, rect.top() + prevBlockBaseline + verticalAlignOffset ) );
813 painter->setPen( QColor( 0, 0, 255, 220 ) );
814 painter->drawLine( QPointF( rect.left() + left, rect.top() + blockBaseLine + fragmentVerticalOffset + verticalAlignOffset ),
815 QPointF( rect.left() + right, rect.top() + blockBaseLine + fragmentVerticalOffset + verticalAlignOffset ) );
818 prevBlockBaseline = blockBaseLine;
911 mLayerExpressionContextScope.reset( vl->createExpressionContextScope() );
913 mLayerReferenceScale = renderer->referenceScale();
932 subProvider->startRender( context );
941 subProvider->stopRender( context );
947 return mLayerExpressionContextScope.get();
956 QStringList predefinedOrderString;
957 const auto constPositions = positions;
963 predefinedOrderString << u
"TL"_s;
966 predefinedOrderString << u
"TSL"_s;
969 predefinedOrderString << u
"T"_s;
972 predefinedOrderString << u
"TSR"_s;
975 predefinedOrderString << u
"TR"_s;
978 predefinedOrderString << u
"L"_s;
981 predefinedOrderString << u
"R"_s;
984 predefinedOrderString << u
"BL"_s;
987 predefinedOrderString << u
"BSL"_s;
990 predefinedOrderString << u
"B"_s;
993 predefinedOrderString << u
"BSR"_s;
996 predefinedOrderString << u
"BR"_s;
999 predefinedOrderString << u
"O"_s;
1003 return predefinedOrderString.join(
',' );
1008 QVector<Qgis::LabelPredefinedPointPosition> result;
1009 const QStringList predefinedOrderList = positionString.split(
',' );
1010 result.reserve( predefinedOrderList.size() );
1011 for (
const QString &position : predefinedOrderList )
1013 QString cleaned = position.trimmed().toUpper();
1014 if ( cleaned ==
"TL"_L1 )
1016 else if ( cleaned ==
"TSL"_L1 )
1018 else if ( cleaned ==
"T"_L1 )
1020 else if ( cleaned ==
"TSR"_L1 )
1022 else if ( cleaned ==
"TR"_L1 )
1024 else if ( cleaned ==
"L"_L1 )
1026 else if ( cleaned ==
"R"_L1 )
1028 else if ( cleaned ==
"BL"_L1 )
1030 else if ( cleaned ==
"BSL"_L1 )
1032 else if ( cleaned ==
"B"_L1 )
1034 else if ( cleaned ==
"BSR"_L1 )
1036 else if ( cleaned ==
"BR"_L1 )
1038 else if ( cleaned ==
"O"_L1 )
1055 return parts.join(
',' );
1061 const QStringList flagList =
string.split(
',' );
1062 bool foundLineOrientationFlag =
false;
1063 for (
const QString &flag : flagList )
1065 QString cleaned = flag.trimmed().toUpper();
1066 if ( cleaned ==
"OL"_L1 )
1068 else if ( cleaned ==
"AL"_L1 )
1070 else if ( cleaned ==
"BL"_L1 )
1072 else if ( cleaned ==
"LO"_L1 )
1073 foundLineOrientationFlag =
true;
1075 if ( !foundLineOrientationFlag )
@ BelowLine
Labels can be placed below a line feature. Unless MapOrientation is also specified this mode respects...
@ MapOrientation
Signifies that the AboveLine and BelowLine flags should respect the map's orientation rather than the...
@ OnLine
Labels can be placed directly over a line feature.
@ AboveLine
Labels can be placed above a line feature. Unless MapOrientation is also specified this mode respects...
QFlags< LabelLinePlacementFlag > LabelLinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
@ Labeling
Labeling-specific layout mode.
@ DrawCandidates
Whether to draw rectangles of generated candidates (good for debugging).
@ CollectUnplacedLabels
Whether unplaced labels should be collected in the labeling results (regardless of whether they are b...
@ 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.
@ Millimeters
Millimeters.
@ RecordProfile
Enable run-time profiling while rendering.
LabelPredefinedPointPosition
Positions for labels when using the Qgis::LabelPlacement::OrderedPositionsAroundPoint placement mode.
@ OverPoint
Label directly centered over point.
@ MiddleLeft
Label on left of point.
@ TopRight
Label on top-right of point.
@ MiddleRight
Label on right of point.
@ TopSlightlyRight
Label on top of point, slightly right of center.
@ TopMiddle
Label directly above point.
@ BottomSlightlyLeft
Label below point, slightly left of center.
@ BottomRight
Label on bottom right of point.
@ BottomLeft
Label on bottom-left of point.
@ BottomSlightlyRight
Label below point, slightly right of center.
@ TopLeft
Label on top-left of point.
@ BottomMiddle
Label directly below point.
@ TopSlightlyLeft
Label on top of point, slightly left of center.
An abstract interface class for label providers.
QgsExpressionContextScope * layerExpressionContextScope() const
Returns the expression context scope created from the layer associated with this provider.
virtual QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context)=0
Returns list of label features (they are owned by the provider and thus deleted on its destruction).
virtual void drawUnplacedLabel(QgsRenderContext &context, pal::LabelPosition *label) const
Draw an unplaced label.
virtual void stopRender(QgsRenderContext &context)
To be called after rendering is complete.
virtual QList< QgsAbstractLabelProvider * > subProviders()
Returns list of child providers - useful if the provider needs to put labels into more layers with di...
Qgis::LabelPlacement placement() const
What placement strategy to use for the labels.
void setEngine(const QgsLabelingEngine *engine)
Associate provider with a labeling engine (should be only called internally from QgsLabelingEngine).
virtual void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const =0
Draw this label at the position determined by the labeling engine.
QString mLayerId
Associated layer's ID, if applicable.
double priority() const
Default priority of labels (may be overridden by individual labels).
virtual void drawLabelBackground(QgsRenderContext &context, pal::LabelPosition *label) const
Draw the background for the specified label.
QString name() const
Name of the layer (for statistics, debugging etc.) - does not need to be unique.
double layerReferenceScale() const
Returns the symbology reference scale of the layer associated with this provider.
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
virtual void startRender(QgsRenderContext &context)
To be called before rendering of labels begins.
Flags flags() const
Flags associated with the provider.
QgsLabelObstacleSettings::ObstacleType obstacleType() const
How the feature geometries will work as obstacles.
@ MergeConnectedLines
Whether adjacent lines (with the same label text) should be merged.
@ DrawLabels
Whether the labels should be rendered.
@ CentroidMustBeInside
Whether location of centroid must be inside of polygons.
QString layerId() const
Returns ID of associated layer, or empty string if no layer is associated with the provider.
QgsWeakMapLayerPointer mLayer
Weak pointer to source layer.
QString providerId() const
Returns provider ID - useful in case there is more than one label provider within a layer (e....
Qgis::UpsideDownLabelHandling upsidedownLabels() const
How to handle labels that would be upside down.
QgsAbstractLabelProvider(QgsMapLayer *layer, const QString &providerId=QString())
Construct the provider with default values.
QString mProviderId
Associated provider ID (one layer may have multiple providers, e.g. in rule-based labeling).
Abstract base class for labeling engine rules.
QgsDefaultLabelingEngine()
Construct the labeling engine with default settings.
void run(QgsRenderContext &context) override
Runs the labeling job.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Abstract base class for all 2D vector feature renderers.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
void setProgress(double progress)
Sets the current progress for the feedback object.
static std::unique_ptr< QgsFillSymbol > createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QgsGeometry difference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
Label blocking region (in map coordinates and CRS).
Represents a label candidate.
Describes a feature that should be used within the labeling engine.
QSizeF size(double angle=0.0) const
Size of the label (in map units).
QgsAbstractLabelProvider * provider() const
Returns provider of this instance.
void setSymbol(const QgsSymbol *symbol)
Sets the feature symbol associated with this label.
pal::Layer * mLayer
Pointer to PAL layer (assigned when registered to PAL).
QgsFeature feature() const
Returns the original feature associated with this label.
double zIndex() const
Returns the label's z-index.
const QgsMargins & visualMargin() const
Returns the visual margin for the label feature.
QRectF outerBounds() const
Returns the extreme outer bounds of the label feature, including any surrounding content like borders...
const QgsSymbol * symbol() const
Returns the feature symbol associated with this label.
QgsFeedback subclass for granular reporting of labeling engine progress.
Stores global configuration for labeling engine.
Qgis::LabelPlacementEngineVersion placementVersion() const
Returns the placement engine version, which dictates how the label placement problem is solved.
bool testFlag(Qgis::LabelingFlag f) const
Test whether a particular flag is enabled.
Qgis::LabelingFlags flags() const
Gets flags of the labeling engine.
double maximumPolygonCandidatesPerCmSquared() const
Returns the maximum number of polygon label candidate positions per centimeter squared.
double maximumLineCandidatesPerCm() const
Returns the maximum number of line label candidate positions per centimeter.
std::unique_ptr< pal::Pal > mPal
const QgsLabelingEngineSettings & engineSettings() const
Gets associated labeling engine settings.
std::unique_ptr< QgsLabelingResults > mResults
Resulting labeling layout.
QgsMapSettings mMapSettings
Associated map settings instance.
bool prepare(QgsRenderContext &context)
Prepares the engine for rendering in the specified context.
void solve(QgsRenderContext &context)
Solves the label problem.
QList< pal::LabelPosition * > mUnlabeled
std::vector< std::unique_ptr< QgsAbstractLabelingEngineRule > > mEngineRules
std::unique_ptr< pal::Problem > mProblem
QString addProvider(QgsAbstractLabelProvider *provider)
Adds a provider of label features.
const QgsMapSettings & mapSettings() const
Gets associated map settings.
QList< pal::LabelPosition * > mLabels
QgsLabelingResults * takeResults()
Returns pointer to recently computed results and pass the ownership of results to the caller.
void cleanup()
Cleans up the engine following a call to registerLabels() or solve().
void setMapSettings(const QgsMapSettings &mapSettings)
Associate map settings instance.
void registerLabels(QgsRenderContext &context)
Runs the label registration step.
QList< QgsAbstractLabelProvider * > mSubProviders
List of labeling engine rules (owned by the labeling engine).
static void drawLabelCandidateRect(pal::LabelPosition *lp, QgsRenderContext &context, const QgsMapToPixel *xform, QList< QgsLabelCandidate > *candidates=nullptr)
Draws label candidate rectangles.
void drawLabels(QgsRenderContext &context, const QString &layerId=QString())
Draws labels to the specified render context.
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.
void processProvider(QgsAbstractLabelProvider *provider, QgsRenderContext &context, pal::Pal &p)
QgsAbstractLabelProvider * providerById(const QString &id)
Returns the provider with matching id, where id corresponds to the value returned by the addProvider(...
QgsLabelingEngine()
Construct the labeling engine with default settings.
QHash< QString, QgsAbstractLabelProvider * > mProvidersById
void removeProvider(QgsAbstractLabelProvider *provider)
Remove provider if the provider's initialization failed. Provider instance is deleted.
static void drawLabelMetrics(pal::LabelPosition *label, const QgsMapToPixel &xform, QgsRenderContext &context, const QPointF &renderPoint)
Draws label metrics.
QList< QgsAbstractLabelProvider * > mProviders
List of providers (the are owned by the labeling engine).
virtual ~QgsLabelingEngine()
Clean up everything (especially the registered providers).
Stores computed placement from labeling engine.
static QString encodePredefinedPositionOrder(const QVector< Qgis::LabelPredefinedPointPosition > &positions)
Encodes an ordered list of predefined point label positions to a string.
static QVector< Qgis::LabelPredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
static Qgis::LabelLinePlacementFlags decodeLinePlacementFlags(const QString &string)
Decodes a string to set of line placement flags.
static QString encodeLinePlacementFlags(Qgis::LabelLinePlacementFlags flags)
Encodes line placement flags to a string.
Base class for all map layer types.
Contains configuration for rendering maps.
Perform transforms between map coordinates and device coordinates.
void setMapRotation(double degrees, double cx, double cy)
Sets map rotation in degrees (clockwise).
double mapUnitsPerPixel() const
Returns the current map units per pixel.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Defines the four margins of a rectangle.
double top() const
Returns the top margin.
double bottom() const
Returns the bottom margin.
QPointF toQPointF() const
Converts a point to a QPointF.
A rectangle specified with double values.
void grow(double delta)
Grows the rectangle in place by the specified amount.
Contains information about the context of a rendering operation.
double convertToMapUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
Scoped object for temporary override of the symbologyReferenceScale property of a QgsRenderContext.
void finalize()
Finalizes and cleans up the engine following the rendering of labels for the last layer to be labeled...
void run(QgsRenderContext &context) override
Runs the labeling job.
QgsStagedRenderLabelingEngine()
Construct the labeling engine with default settings.
void renderLabelsForLayer(QgsRenderContext &context, const QString &layerId)
Renders all the labels which belong only to the layer with matching layerId to the specified render c...
Represents a block of text consisting of one or more QgsTextFragment objects.
int size() const
Returns the number of fragments in the block.
Contains pre-calculated metrics of a QgsTextDocument.
double fragmentVerticalOffset(int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode) const
Returns the vertical offset from a text block's baseline which should be applied to the fragment at t...
double baselineOffset(int blockIndex, Qgis::TextLayoutMode mode) const
Returns the offset from the top of the document to the text baseline for the given block index.
double blockLeftMargin(int blockIndex) const
Returns the margin for the left side of the specified block index.
double fragmentHorizontalAdvance(int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode) const
Returns the horizontal advance of the fragment at the specified block and fragment index.
double blockVerticalMargin(int blockIndex) const
Returns the vertical margin for the specified block index.
Represents a document consisting of one or more QgsTextBlock objects.
const QgsTextBlock & at(int index) const
Returns the block at the specified index.
int size() const
Returns the number of blocks in the document.
Adds extra information to QgsLabelFeature for text labels.
Represents a vector layer which manages a vector based dataset.
QgsLabelFeature * feature()
Returns the parent feature.
LabelPosition is a candidate feature label position.
double getAlpha() const
Returns the angle to rotate text (in radians).
double cost() const
Returns the candidate label position's geographical cost.
bool conflictsWithObstacle() const
Returns whether the position is marked as conflicting with an obstacle feature.
FeaturePart * getFeaturePart() const
Returns the feature corresponding to this labelposition.
double getX(int i=0) const
Returns the down-left x coordinate.
double getY(int i=0) const
Returns the down-left y coordinate.
LabelPosition * nextPart() const
Returns the next part of this label position (i.e.
A set of features which influence the labeling process.
void setUpsidedownLabels(Qgis::UpsideDownLabelHandling ud)
Sets how upside down labels will be handled within the layer.
bool registerFeature(QgsLabelFeature *label)
Register a feature in the layer.
void setObstacleType(QgsLabelObstacleSettings::ObstacleType obstacleType)
Sets the obstacle type, which controls how features within the layer act as obstacles for labels.
void setMergeConnectedLines(bool merge)
Sets whether connected lines should be merged before labeling.
void setCentroidInside(bool forceInside)
Sets whether labels placed at the centroid of features within the layer are forced to be placed insid...
Layer * addLayer(QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel)
add a new layer
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
#define QgsDebugMsgLevel(str, level)