QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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<QgsLabelPosition> QgsLabelingResults::groupedLabelPositions( long long groupId ) const
69 {
70  QList<QgsLabelPosition> positions;
71  if ( mLabelSearchTree )
72  {
73  const QList<QgsLabelPosition *> positionPointers = mLabelSearchTree->groupedLabelPositions( groupId );
74  positions.reserve( positionPointers.size() );
75  for ( const QgsLabelPosition *pos : positionPointers )
76  positions.push_back( QgsLabelPosition( *pos ) );
77  }
78  return positions;
79 }
80 
81 QList<QgsCalloutPosition> QgsLabelingResults::calloutsWithinRectangle( const QgsRectangle &rectangle ) const
82 {
83  QList<QgsCalloutPosition> positions;
84 
85  if ( mLabelSearchTree )
86  {
87  const QList<const QgsCalloutPosition *>positionPointers = mLabelSearchTree->calloutsInRectangle( rectangle );
88  for ( const QgsCalloutPosition *pos : positionPointers )
89  {
90  positions.push_back( QgsCalloutPosition( *pos ) );
91  }
92  }
93 
94  return positions;
95 }
96 
98 {
99  mLabelSearchTree->setMapSettings( settings );
100 }
qgslabelsearchtree.h
QgsLabelingResults::groupedLabelPositions
QList< QgsLabelPosition > groupedLabelPositions(long long groupId) const
Returns a list of all label positions sharing the same group ID (i.e.
Definition: qgslabelingresults.cpp:68
QgsLabelingResults::allLabels
QList< QgsLabelPosition > allLabels() const
Returns a list of all labels generated by the labeling run.
Definition: qgslabelingresults.cpp:27
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsLabelPosition
Represents the calculated placement of a map label.
Definition: qgslabelposition.h:33
qgslabelingresults.h
QgsLabelingResults::calloutsWithinRectangle
QList< QgsCalloutPosition > calloutsWithinRectangle(const QgsRectangle &rectangle) const
Returns a list of callouts with origins or destinations inside the given rectangle.
Definition: qgslabelingresults.cpp:81
QgsCalloutPosition
Represents the calculated placement of a map label callout line.
Definition: qgscalloutposition.h:32
QgsLabelingResults::setMapSettings
void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
Definition: qgslabelingresults.cpp:97
QgsLabelingResults::QgsLabelingResults
QgsLabelingResults()
Definition: qgslabelingresults.cpp:19
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsLabelingResults::~QgsLabelingResults
~QgsLabelingResults()
QgsLabelingResults::labelsAtPosition
QList< QgsLabelPosition > labelsAtPosition(const QgsPointXY &p) const
Returns the details of any labels placed at the specified point (in map coordinates).
Definition: qgslabelingresults.cpp:32
QgsLabelSearchTree
A class to query the labeling structure at a given point (small wrapper around pal RTree class)
Definition: qgslabelsearchtree.h:46
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
Definition: qgsmapsettings.h:88
QgsLabelingResults::labelsWithinRect
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
Returns the details of any labels placed within the specified rectangle (in map coordinates).
Definition: qgslabelingresults.cpp:50