QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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#include "qgsmapsettings.h"
19
20
22 : mLabelSearchTree( std::make_unique< QgsLabelSearchTree >() )
23{
24}
25
27
28
29QList<QgsLabelPosition> QgsLabelingResults::allLabels() const
30{
31 return mLabelSearchTree ? mLabelSearchTree->allLabels() : QList<QgsLabelPosition>();
32}
33
34QList<QgsLabelPosition> QgsLabelingResults::labelsAtPosition( const QgsPointXY &p ) const
35{
36 QList<QgsLabelPosition> positions;
37
38 QList<QgsLabelPosition *> positionPointers;
39 if ( mLabelSearchTree )
40 {
41 mLabelSearchTree->label( p, positionPointers );
42 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
43 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
44 {
45 positions.push_back( QgsLabelPosition( **pointerIt ) );
46 }
47 }
48
49 return positions;
50}
51
52QList<QgsLabelPosition> QgsLabelingResults::labelsWithinRect( const QgsRectangle &r ) const
53{
54 QList<QgsLabelPosition> positions;
55
56 QList<QgsLabelPosition *> positionPointers;
57 if ( mLabelSearchTree )
58 {
59 mLabelSearchTree->labelsInRect( r, positionPointers );
60 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
61 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
62 {
63 positions.push_back( QgsLabelPosition( **pointerIt ) );
64 }
65 }
66
67 return positions;
68}
69
70QList<QgsLabelPosition> QgsLabelingResults::groupedLabelPositions( long long groupId ) const
71{
72 QList<QgsLabelPosition> positions;
73 if ( mLabelSearchTree )
74 {
75 const QList<QgsLabelPosition *> positionPointers = mLabelSearchTree->groupedLabelPositions( groupId );
76 positions.reserve( positionPointers.size() );
77 for ( const QgsLabelPosition *pos : positionPointers )
78 positions.push_back( QgsLabelPosition( *pos ) );
79 }
80 return positions;
81}
82
83QList<QgsCalloutPosition> QgsLabelingResults::calloutsWithinRectangle( const QgsRectangle &rectangle ) const
84{
85 QList<QgsCalloutPosition> positions;
86
87 if ( mLabelSearchTree )
88 {
89 const QList<const QgsCalloutPosition *>positionPointers = mLabelSearchTree->calloutsInRectangle( rectangle );
90 for ( const QgsCalloutPosition *pos : positionPointers )
91 {
92 positions.push_back( QgsCalloutPosition( *pos ) );
93 }
94 }
95
96 return positions;
97}
98
100{
101 mLabelSearchTree->setMapSettings( settings );
102}
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:60
A rectangle specified with double values.