QGIS API Documentation 3.29.0-Master (694ebda27c)
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
27QList<QgsLabelPosition> QgsLabelingResults::allLabels() const
28{
29 return mLabelSearchTree ? mLabelSearchTree->allLabels() : QList<QgsLabelPosition>();
30}
31
32QList<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
50QList<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
68QList<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
81QList<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}
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 > groupedLabelPositions(long long groupId) const
Returns a list of all label positions sharing the same group ID (i.e.
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