QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgslabelingengine.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  qgslabelingengine.cpp
4  --------------------------------------
5  Date : September 2015
6  Copyright : (C) 2015 by Martin Dobias
7  Email : wonder dot sk at gmail dot com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgslabelingengine.h"
18 
19 #include "qgslogger.h"
20 
21 #include "feature.h"
22 #include "labelposition.h"
23 #include "layer.h"
24 #include "pal.h"
25 #include "problem.h"
26 #include "qgsrendercontext.h"
27 #include "qgsmaplayer.h"
28 #include "qgssymbol.h"
30 
31 // helper function for checking for job cancellation within PAL
32 static bool _palIsCanceled( void *ctx )
33 {
34  return ( reinterpret_cast< QgsRenderContext * >( ctx ) )->renderingStopped();
35 }
36 
43 {
44  public:
45 
46  explicit QgsLabelSorter( const QgsMapSettings &mapSettings )
47  : mMapSettings( mapSettings )
48  {}
49 
51  {
52  QgsLabelFeature *lf1 = lp1->getFeaturePart()->feature();
53  QgsLabelFeature *lf2 = lp2->getFeaturePart()->feature();
54 
55  if ( !qgsDoubleNear( lf1->zIndex(), lf2->zIndex() ) )
56  return lf1->zIndex() < lf2->zIndex();
57 
58  //equal z-index, so fallback to respecting layer render order
59  QStringList layerIds = mMapSettings.layerIds();
60  int layer1Pos = layerIds.indexOf( lf1->provider()->layerId() );
61  int layer2Pos = layerIds.indexOf( lf2->provider()->layerId() );
62  if ( layer1Pos != layer2Pos && layer1Pos >= 0 && layer2Pos >= 0 )
63  return layer1Pos > layer2Pos; //higher positions are rendered first
64 
65  //same layer, so render larger labels first
66  return lf1->size().width() * lf1->size().height() > lf2->size().width() * lf2->size().height();
67  }
68 
69  private:
70 
71  const QgsMapSettings &mMapSettings;
72 };
73 
74 
76  : mResults( new QgsLabelingResults )
77 {}
78 
80 {
81  qDeleteAll( mProviders );
82  qDeleteAll( mSubProviders );
83 }
84 
86 {
88  if ( mResults )
89  mResults->setMapSettings( mapSettings );
90 }
91 
92 QList< QgsMapLayer * > QgsLabelingEngine::participatingLayers() const
93 {
94  QSet< QgsMapLayer * > layers;
95  for ( QgsAbstractLabelProvider *provider : mProviders )
96  {
97  if ( provider->layer() )
98  layers << provider->layer();
99  }
100  for ( QgsAbstractLabelProvider *provider : mSubProviders )
101  {
102  if ( provider->layer() )
103  layers << provider->layer();
104  }
105  return layers.toList();
106 }
107 
109 {
110  provider->setEngine( this );
111  mProviders << provider;
112 }
113 
115 {
116  int idx = mProviders.indexOf( provider );
117  if ( idx >= 0 )
118  {
119  delete mProviders.takeAt( idx );
120  }
121 }
122 
124 {
125  QgsAbstractLabelProvider::Flags flags = provider->flags();
126 
127  // create the pal layer
128  pal::Layer *l = p.addLayer( provider,
129  provider->name(),
130  provider->placement(),
131  provider->priority(),
132  true,
133  flags.testFlag( QgsAbstractLabelProvider::DrawLabels ),
134  flags.testFlag( QgsAbstractLabelProvider::DrawAllLabels ) );
135 
136  // set label mode (label per feature is the default)
138 
139  // set whether adjacent lines should be merged
141 
142  // set obstacle type
143  l->setObstacleType( provider->obstacleType() );
144 
145  // set whether location of centroid must be inside of polygons
147 
148  // set how to show upside-down labels
149  pal::Layer::UpsideDownLabels upsdnlabels;
150  switch ( provider->upsidedownLabels() )
151  {
153  upsdnlabels = pal::Layer::Upright;
154  break;
156  upsdnlabels = pal::Layer::ShowDefined;
157  break;
159  upsdnlabels = pal::Layer::ShowAll;
160  break;
161  }
162  l->setUpsidedownLabels( upsdnlabels );
163 
164 
165  const QList<QgsLabelFeature *> features = provider->labelFeatures( context );
166 
167  for ( QgsLabelFeature *feature : features )
168  {
169  try
170  {
171  l->registerFeature( feature );
172  }
173  catch ( std::exception &e )
174  {
175  Q_UNUSED( e )
176  QgsDebugMsgLevel( QStringLiteral( "Ignoring feature %1 due PAL exception:" ).arg( feature->id() ) + QString::fromLatin1( e.what() ), 4 );
177  continue;
178  }
179  }
180 
181  // any sub-providers?
182  const auto subproviders = provider->subProviders();
183  for ( QgsAbstractLabelProvider *subProvider : subproviders )
184  {
185  mSubProviders << subProvider;
186  processProvider( subProvider, context, p );
187  }
188 }
189 
190 
192 {
194 
195  pal::Pal p;
197  switch ( settings.searchMethod() )
198  {
200  s = pal::CHAIN;
201  break;
203  s = pal::POPMUSIC_TABU;
204  break;
207  break;
210  break;
212  s = pal::FALP;
213  break;
214  }
215  p.setSearch( s );
216 
217  // set number of candidates generated per feature
218  int candPoint, candLine, candPolygon;
219  settings.numCandidatePositions( candPoint, candLine, candPolygon );
220  p.setPointP( candPoint );
221  p.setLineP( candLine );
222  p.setPolyP( candPolygon );
223 
225 
226 
227  // for each provider: get labels and register them in PAL
228  for ( QgsAbstractLabelProvider *provider : qgis::as_const( mProviders ) )
229  {
230  bool appendedLayerScope = false;
231  if ( QgsMapLayer *ml = provider->layer() )
232  {
233  appendedLayerScope = true;
235  }
236  processProvider( provider, context, p );
237  if ( appendedLayerScope )
238  delete context.expressionContext().popScope();
239  }
240 
241 
242  // NOW DO THE LAYOUT (from QgsPalLabeling::drawLabeling)
243 
244  QPainter *painter = context.painter();
245 
247  QPolygonF visiblePoly = mMapSettings.visiblePolygon();
248  visiblePoly.append( visiblePoly.at( 0 ) ); //close polygon
249 
250  // get map label boundary geometry - if one hasn't been explicitly set, we use the whole of the map's visible polygon
252 
253  // label blocking regions work by "chopping away" those regions from the permissible labeling area
254  const QList< QgsLabelBlockingRegion > blockingRegions = mMapSettings.labelBlockingRegions();
255  for ( const QgsLabelBlockingRegion &region : blockingRegions )
256  {
257  mapBoundaryGeom = mapBoundaryGeom.difference( region.geometry );
258  }
259 
261  {
262  // draw map boundary
263  QgsFeature f;
264  f.setGeometry( mapBoundaryGeom );
265  QgsStringMap properties;
266  properties.insert( QStringLiteral( "style" ), QStringLiteral( "no" ) );
267  properties.insert( QStringLiteral( "style_border" ), QStringLiteral( "solid" ) );
268  properties.insert( QStringLiteral( "color_border" ), QStringLiteral( "#0000ff" ) );
269  properties.insert( QStringLiteral( "width_border" ), QStringLiteral( "0.3" ) );
270  properties.insert( QStringLiteral( "joinstyle" ), QStringLiteral( "miter" ) );
271  std::unique_ptr< QgsFillSymbol > boundarySymbol( QgsFillSymbol::createSimple( properties ) );
272  boundarySymbol->startRender( context );
273  boundarySymbol->renderFeature( f, context );
274  boundarySymbol->stopRender( context );
275  }
276 
277  if ( !qgsDoubleNear( mMapSettings.rotation(), 0.0 ) )
278  {
279  //PAL features are prerotated, so extent also needs to be unrotated
281  // yes - this is rotated in the opposite direction... phew, this is confusing!
282  mapBoundaryGeom.rotate( mMapSettings.rotation(), mMapSettings.visibleExtent().center() );
283  }
284 
285  QgsRectangle extent = extentGeom.boundingBox();
286 
287  p.registerCancellationCallback( &_palIsCanceled, reinterpret_cast< void * >( &context ) );
288 
289  QTime t;
290  t.start();
291 
292  // do the labeling itself
293  std::unique_ptr< pal::Problem > problem;
294  try
295  {
296  problem = p.extractProblem( extent, mapBoundaryGeom );
297  }
298  catch ( std::exception &e )
299  {
300  Q_UNUSED( e )
301  QgsDebugMsgLevel( "PAL EXCEPTION :-( " + QString::fromLatin1( e.what() ), 4 );
302  return;
303  }
304 
305  if ( context.renderingStopped() )
306  {
307  return; // it has been canceled
308  }
309 
310 #if 1 // XXX strk
311  // features are pre-rotated but not scaled/translated,
312  // so we only disable rotation here. Ideally, they'd be
313  // also pre-scaled/translated, as suggested here:
314  // https://github.com/qgis/QGIS/issues/20071
316  xform.setMapRotation( 0, 0, 0 );
317 #else
318  const QgsMapToPixel &xform = mMapSettings->mapToPixel();
319 #endif
320 
321  // draw rectangles with all candidates
322  // this is done before actual solution of the problem
323  // before number of candidates gets reduced
324  // TODO mCandidates.clear();
325  if ( settings.testFlag( QgsLabelingEngineSettings::DrawCandidates ) && problem )
326  {
327  painter->setBrush( Qt::NoBrush );
328  for ( int i = 0; i < problem->getNumFeatures(); i++ )
329  {
330  for ( int j = 0; j < problem->getFeatureCandidateCount( i ); j++ )
331  {
332  pal::LabelPosition *lp = problem->getFeatureCandidate( i, j );
333 
334  QgsPalLabeling::drawLabelCandidateRect( lp, painter, &xform );
335  }
336  }
337  }
338 
339  // find the solution
340  QList<pal::LabelPosition *> labels = p.solveProblem( problem.get(), settings.testFlag( QgsLabelingEngineSettings::UseAllLabels ) );
341 
342  QgsDebugMsgLevel( QStringLiteral( "LABELING work: %1 ms ... labels# %2" ).arg( t.elapsed() ).arg( labels.size() ), 4 );
343  t.restart();
344 
345  if ( context.renderingStopped() )
346  {
347  return;
348  }
349  painter->setRenderHint( QPainter::Antialiasing );
350 
351  // sort labels
352  std::sort( labels.begin(), labels.end(), QgsLabelSorter( mMapSettings ) );
353 
354  // draw the labels
355  for ( pal::LabelPosition *label : qgis::as_const( labels ) )
356  {
357  if ( context.renderingStopped() )
358  break;
359 
360  QgsLabelFeature *lf = label->getFeaturePart()->feature();
361  if ( !lf )
362  {
363  continue;
364  }
365 
366  lf->provider()->drawLabel( context, label );
367  }
368 
369  // Reset composition mode for further drawing operations
370  painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
371 
372  QgsDebugMsgLevel( QStringLiteral( "LABELING draw: %1 ms" ).arg( t.elapsed() ), 4 );
373 }
374 
376 {
377  return mResults.release();
378 }
379 
380 
382 
384 {
385  return mLayer ? mLayer->provider() : nullptr;
386 
387 }
388 
390  : mLayerId( layer ? layer->id() : QString() )
391  , mLayer( layer )
392  , mProviderId( providerId )
393  , mFlags( DrawLabels )
394  , mPlacement( QgsPalLayerSettings::AroundPoint )
395  , mPriority( 0.5 )
396  , mObstacleType( QgsPalLayerSettings::PolygonInterior )
397  , mUpsidedownLabels( QgsPalLayerSettings::Upright )
398 {
399 }
400 
401 
402 //
403 // QgsLabelingUtils
404 //
405 
406 QString QgsLabelingUtils::encodePredefinedPositionOrder( const QVector<QgsPalLayerSettings::PredefinedPointPosition> &positions )
407 {
408  QStringList predefinedOrderString;
409  const auto constPositions = positions;
410  for ( QgsPalLayerSettings::PredefinedPointPosition position : constPositions )
411  {
412  switch ( position )
413  {
415  predefinedOrderString << QStringLiteral( "TL" );
416  break;
418  predefinedOrderString << QStringLiteral( "TSL" );
419  break;
421  predefinedOrderString << QStringLiteral( "T" );
422  break;
424  predefinedOrderString << QStringLiteral( "TSR" );
425  break;
427  predefinedOrderString << QStringLiteral( "TR" );
428  break;
430  predefinedOrderString << QStringLiteral( "L" );
431  break;
433  predefinedOrderString << QStringLiteral( "R" );
434  break;
436  predefinedOrderString << QStringLiteral( "BL" );
437  break;
439  predefinedOrderString << QStringLiteral( "BSL" );
440  break;
442  predefinedOrderString << QStringLiteral( "B" );
443  break;
445  predefinedOrderString << QStringLiteral( "BSR" );
446  break;
448  predefinedOrderString << QStringLiteral( "BR" );
449  break;
450  }
451  }
452  return predefinedOrderString.join( ',' );
453 }
454 
455 QVector<QgsPalLayerSettings::PredefinedPointPosition> QgsLabelingUtils::decodePredefinedPositionOrder( const QString &positionString )
456 {
457  QVector<QgsPalLayerSettings::PredefinedPointPosition> result;
458  const QStringList predefinedOrderList = positionString.split( ',' );
459  result.reserve( predefinedOrderList.size() );
460  for ( const QString &position : predefinedOrderList )
461  {
462  QString cleaned = position.trimmed().toUpper();
463  if ( cleaned == QLatin1String( "TL" ) )
465  else if ( cleaned == QLatin1String( "TSL" ) )
467  else if ( cleaned == QLatin1String( "T" ) )
469  else if ( cleaned == QLatin1String( "TSR" ) )
471  else if ( cleaned == QLatin1String( "TR" ) )
473  else if ( cleaned == QLatin1String( "L" ) )
475  else if ( cleaned == QLatin1String( "R" ) )
477  else if ( cleaned == QLatin1String( "BL" ) )
479  else if ( cleaned == QLatin1String( "BSL" ) )
481  else if ( cleaned == QLatin1String( "B" ) )
483  else if ( cleaned == QLatin1String( "BSR" ) )
485  else if ( cleaned == QLatin1String( "BR" ) )
487  }
488  return result;
489 }
490 
491 QString QgsLabelingUtils::encodeLinePlacementFlags( pal::LineArrangementFlags flags )
492 {
493  QStringList parts;
494  if ( flags & pal::FLAG_ON_LINE )
495  parts << QStringLiteral( "OL" );
496  if ( flags & pal::FLAG_ABOVE_LINE )
497  parts << QStringLiteral( "AL" );
498  if ( flags & pal::FLAG_BELOW_LINE )
499  parts << QStringLiteral( "BL" );
500  if ( !( flags & pal::FLAG_MAP_ORIENTATION ) )
501  parts << QStringLiteral( "LO" );
502  return parts.join( ',' );
503 }
504 
505 pal::LineArrangementFlags QgsLabelingUtils::decodeLinePlacementFlags( const QString &string )
506 {
507  pal::LineArrangementFlags flags = nullptr;
508  const QStringList flagList = string.split( ',' );
509  bool foundLineOrientationFlag = false;
510  for ( const QString &flag : flagList )
511  {
512  QString cleaned = flag.trimmed().toUpper();
513  if ( cleaned == QLatin1String( "OL" ) )
514  flags |= pal::FLAG_ON_LINE;
515  else if ( cleaned == QLatin1String( "AL" ) )
516  flags |= pal::FLAG_ABOVE_LINE;
517  else if ( cleaned == QLatin1String( "BL" ) )
518  flags |= pal::FLAG_BELOW_LINE;
519  else if ( cleaned == QLatin1String( "LO" ) )
520  foundLineOrientationFlag = true;
521  }
522  if ( !foundLineOrientationFlag )
523  flags |= pal::FLAG_MAP_ORIENTATION;
524  return flags;
525 }
Label on bottom right of point.
void processProvider(QgsAbstractLabelProvider *provider, QgsRenderContext &context, pal::Pal &p)
Layer * addLayer(QgsAbstractLabelProvider *provider, const QString &layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll=false)
add a new layer
Definition: pal.cpp:103
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:78
Label on bottom-left of point.
Label on top of point, slightly left of center.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
void addProvider(QgsAbstractLabelProvider *provider)
Add provider of label features. Takes ownership of the provider.
QList< QgsAbstractLabelProvider * > mProviders
List of providers (the are owned by the labeling engine)
Only initial solution.
Definition: pal.h:65
void removeProvider(QgsAbstractLabelProvider *provider)
Remove provider if the provider&#39;s initialization failed. Provider instance is deleted.
QgsLabelFeature * feature()
Returns the parent feature.
Definition: feature.h:118
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QStringList layerIds() const
Gets list of layer IDs for map rendering The layers are stored in the reverse order of how they are r...
QgsAbstractLabelProvider * provider() const
Returns provider of this instance.
Label on top-left of point.
QgsAbstractLabelProvider(QgsMapLayer *layer, const QString &providerId=QString())
Construct the provider with default values.
void registerCancellationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
Definition: pal.cpp:447
static void drawLabelCandidateRect(pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList< QgsLabelCandidate > *candidates=nullptr)
A set of features which influence the labeling process.
Definition: layer.h:63
PredefinedPointPosition
Positions for labels when using the QgsPalLabeling::OrderedPositionsAroundPoint placement mode...
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
Definition: qgssymbol.cpp:1184
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:265
OperationResult rotate(double rotation, const QgsPointXY &center)
Rotate this geometry around the Z axis.
QgsPalLayerSettings::ObstacleType obstacleType() const
How the feature geometries will work as obstacles.
Whether to use also label candidates that are partially outside of the map view.
QgsLabelingEngine()
Construct the labeling engine with default settings.
QList< QgsAbstractLabelProvider * > mSubProviders
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
Main Pal labeling class.
Definition: pal.h:87
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition: pal.h:64
UpsideDownLabels
Definition: layer.h:74
Label on top-right of point.
void setMapSettings(const QgsMapSettings &mapSettings)
Associate map settings instance.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:111
void setUpsidedownLabels(UpsideDownLabels ud)
Sets how upside down labels will be handled within the layer.
Definition: layer.h:210
void setShowPartial(bool show)
Set flag show partial label.
Definition: pal.cpp:535
Whether to label each part of multi-part features separately.
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
virtual QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context)=0
Returns list of label features (they are owned by the provider and thus deleted on its destruction) ...
void setObstacleType(QgsPalLayerSettings::ObstacleType obstacleType)
Sets the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:162
QMap< QString, QString > QgsStringMap
Definition: qgis.h:587
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
void setCentroidInside(bool forceInside)
Sets whether labels placed at the centroid of features within the layer are forced to be placed insid...
Definition: layer.h:225
Is a little bit better than CHAIN but slower.
Definition: pal.h:63
Whether adjacent lines (with the same label text) should be merged.
std::unique_ptr< Problem > extractProblem(const QgsRectangle &extent, const QgsGeometry &mapBoundary)
Extracts the labeling problem for the specified map extent - only features within this extent will be...
Definition: pal.cpp:453
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:37
Whether to draw all labels even if there would be collisions.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QgsGeometry labelBoundaryGeometry() const
Returns the label boundary geometry, which restricts where in the rendered map labels are permitted t...
static pal::LineArrangementFlags decodeLinePlacementFlags(const QString &string)
Decodes a string to set of line placement flags.
double zIndex() const
Returns the label&#39;s z-index.
Label on left of point.
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
Show upside down for all labels, including dynamic ones.
Is the best but slowest.
Definition: pal.h:62
bool operator()(pal::LabelPosition *lp1, pal::LabelPosition *lp2) const
void setPointP(int point_p)
set # candidates to generate for points features Higher the value is, longer Pal::labeller will spend...
Definition: pal.cpp:483
Whether location of centroid must be inside of polygons.
void setLineP(int line_p)
set maximum # candidates to generate for lines features Higher the value is, longer Pal::labeller wil...
Definition: pal.cpp:489
Upside-down labels (90 <= angle < 270) are shown upright.
QList< QgsMapLayer *> participatingLayers() const
Returns a list of layers with providers in the engine.
Label below point, slightly right of center.
Whether all features will be labelled even though overlaps occur.
Label blocking region (in map coordinates and CRS).
QgsPalLayerSettings::Placement placement() const
What placement strategy to use for the labels.
const QgsMapToPixel & mapToPixel() const
The QgsAbstractLabelProvider class is an interface class.
Whether to draw rectangles of generated candidates (good for debugging)
static QString encodeLinePlacementFlags(pal::LineArrangementFlags flags)
Encodes line placement flags to a string.
QString layerId() const
Returns ID of associated layer, or empty string if no layer is associated with the provider...
QSizeF size() const
Size of the label (in map units)
QgsPalLayerSettings::UpsideDownLabels upsidedownLabels() const
How to handle labels that would be upside down.
void numCandidatePositions(int &candPoint, int &candLine, int &candPolygon) const
Gets number of candidate positions that will be generated for each label feature (default to 8) ...
QgsLabelSorter(const QgsMapSettings &mapSettings)
QgsExpressionContext & expressionContext()
Gets the expression context.
~QgsLabelingEngine()
Clean up everything (especially the registered providers)
bool registerFeature(QgsLabelFeature *label)
Register a feature in the layer.
Definition: layer.cpp:92
Flags flags() const
Flags associated with the provider.
static QString encodePredefinedPositionOrder(const QVector< QgsPalLayerSettings::PredefinedPointPosition > &positions)
Encodes an ordered list of predefined point label positions to a string.
void run(QgsRenderContext &context)
compute the labeling with given map settings and providers
virtual QList< QgsAbstractLabelProvider * > subProviders()
Returns list of child providers - useful if the provider needs to put labels into more layers with di...
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
QString name() const
Name of the layer (for statistics, debugging etc.) - does not need to be unique.
std::unique_ptr< QgsLabelingResults > mResults
Resulting labeling layout.
void setPolyP(int poly_p)
set maximum # candidates to generate for polygon features Higher the value is, longer Pal::labeller w...
Definition: pal.cpp:495
Label below point, slightly left of center.
QgsMapSettings mMapSettings
Associated map settings instance.
QgsLabelingResults * takeResults()
Returns pointer to recently computed results and pass the ownership of results to the caller...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Stores global configuration for labeling engine.
Label on top of point, slightly right of center.
const QgsMapSettings & mapSettings() const
Gets associated map settings.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
QList< LabelPosition * > solveProblem(Problem *prob, bool displayAll)
Definition: pal.cpp:458
void setLabelMode(LabelMode mode)
Sets the layer&#39;s labeling mode.
Definition: layer.h:184
Label directly below point.
Helper class for sorting labels into correct draw order.
void setGeometry(const QgsGeometry &geometry)
Set the feature&#39;s geometry.
Definition: qgsfeature.cpp:137
double priority() const
Default priority of labels (may be overridden by individual labels)
bool testFlag(Flag f) const
Test whether a particular flag is enabled.
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
Label directly above point.
Label on right of point.
Whether the labels should be rendered.
Class that stores computed placement from labeling engine.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated)
static QVector< QgsPalLayerSettings::PredefinedPointPosition > decodePredefinedPositionOrder(const QString &positionString)
Decodes a string to an ordered list of predefined point label positions.
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:230
SearchMethod
Search method to use.
Definition: pal.h:59
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Show upside down when rotation is layer- or data-defined.
virtual void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const =0
draw this label at the position determined by the labeling engine
Is the worst but fastest method.
Definition: pal.h:61
QList< QgsLabelBlockingRegion > labelBlockingRegions() const
Returns the list of regions to avoid placing labels within.
void setSearch(SearchMethod method)
Select the search method to use.
Definition: pal.cpp:575
void setEngine(const QgsLabelingEngine *engine)
Associate provider with a labeling engine (should be only called internally from QgsLabelingEngine) ...
Search searchMethod() const
Which search method to use for removal collisions between labels.
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
Flags flags() const
Gets flags of the labeling engine.
void setMergeConnectedLines(bool merge)
Sets whether connected lines should be merged before labeling.
Definition: layer.h:197
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...