QGIS API Documentation  3.23.0-Master (eb871beae0)
qgslabelingresults.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslabelingresults.cpp
3  -------------------
4  begin : February 2021
5  copyright : (C) Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgslabelingresults.h"
17 #include "qgslabelsearchtree.h"
18 
20  : mLabelSearchTree( std::make_unique< QgsLabelSearchTree >() )
21 {
22 }
23 
25 
26 
27 QList<QgsLabelPosition> QgsLabelingResults::allLabels() const
28 {
29  return mLabelSearchTree ? mLabelSearchTree->allLabels() : QList<QgsLabelPosition>();
30 }
31 
32 QList<QgsLabelPosition> QgsLabelingResults::labelsAtPosition( const QgsPointXY &p ) const
33 {
34  QList<QgsLabelPosition> positions;
35 
36  QList<QgsLabelPosition *> positionPointers;
37  if ( mLabelSearchTree )
38  {
39  mLabelSearchTree->label( p, positionPointers );
40  QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
41  for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
42  {
43  positions.push_back( QgsLabelPosition( **pointerIt ) );
44  }
45  }
46 
47  return positions;
48 }
49 
50 QList<QgsLabelPosition> QgsLabelingResults::labelsWithinRect( const QgsRectangle &r ) const
51 {
52  QList<QgsLabelPosition> positions;
53 
54  QList<QgsLabelPosition *> positionPointers;
55  if ( mLabelSearchTree )
56  {
57  mLabelSearchTree->labelsInRect( r, positionPointers );
58  QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
59  for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
60  {
61  positions.push_back( QgsLabelPosition( **pointerIt ) );
62  }
63  }
64 
65  return positions;
66 }
67 
68 QList<QgsCalloutPosition> QgsLabelingResults::calloutsWithinRectangle( const QgsRectangle &rectangle ) const
69 {
70  QList<QgsCalloutPosition> positions;
71 
72  if ( mLabelSearchTree )
73  {
74  const QList<const QgsCalloutPosition *>positionPointers = mLabelSearchTree->calloutsInRectangle( rectangle );
75  for ( const QgsCalloutPosition *pos : positionPointers )
76  {
77  positions.push_back( QgsCalloutPosition( *pos ) );
78  }
79  }
80 
81  return positions;
82 }
83 
85 {
86  mLabelSearchTree->setMapSettings( settings );
87 }
Represents the calculated placement of a map label callout line.
Represents the calculated placement of a map label.
A class to query the labeling structure at a given point (small wrapper around pal RTree class)
QList< QgsCalloutPosition > calloutsWithinRectangle(const QgsRectangle &rectangle) const
Returns a list of callouts with origins or destinations inside the given rectangle.
void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
QList< QgsLabelPosition > allLabels() const
Returns a list of all labels generated by the labeling run.
QList< QgsLabelPosition > labelsAtPosition(const QgsPointXY &p) const
Returns the details of any labels placed at the specified point (in map coordinates).
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
Returns the details of any labels placed within the specified rectangle (in map coordinates).
The QgsMapSettings class contains configuration for rendering of the map.
A class to represent a 2D point.
Definition: qgspointxy.h:59
A rectangle specified with double values.
Definition: qgsrectangle.h:42