QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
18#include "qgslabelsearchtree.h"
19#include "qgsmapsettings.h"
20
22 : mLabelSearchTree( std::make_unique< QgsLabelSearchTree >() )
23{}
24
26
27
28QList<QgsLabelPosition> QgsLabelingResults::allLabels() const
29{
30 return mLabelSearchTree ? mLabelSearchTree->allLabels() : QList<QgsLabelPosition>();
31}
32
33QList<QgsLabelPosition> QgsLabelingResults::labelsAtPosition( const QgsPointXY &p ) const
34{
35 QList<QgsLabelPosition> positions;
36
37 QList<QgsLabelPosition *> positionPointers;
38 if ( mLabelSearchTree )
39 {
40 mLabelSearchTree->label( p, positionPointers );
41 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
42 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
43 {
44 positions.push_back( QgsLabelPosition( **pointerIt ) );
45 }
46 }
47
48 return positions;
49}
50
51QList<QgsLabelPosition> QgsLabelingResults::labelsWithinRect( const QgsRectangle &r ) const
52{
53 QList<QgsLabelPosition> positions;
54
55 QList<QgsLabelPosition *> positionPointers;
56 if ( mLabelSearchTree )
57 {
58 mLabelSearchTree->labelsInRect( r, positionPointers );
59 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
60 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
61 {
62 positions.push_back( QgsLabelPosition( **pointerIt ) );
63 }
64 }
65
66 return positions;
67}
68
69QList<QgsLabelPosition> QgsLabelingResults::groupedLabelPositions( long long groupId ) const
70{
71 QList<QgsLabelPosition> positions;
72 if ( mLabelSearchTree )
73 {
74 const QList<QgsLabelPosition *> positionPointers = mLabelSearchTree->groupedLabelPositions( groupId );
75 positions.reserve( positionPointers.size() );
76 for ( const QgsLabelPosition *pos : positionPointers )
77 positions.push_back( QgsLabelPosition( *pos ) );
78 }
79 return positions;
80}
81
82QList<QgsCalloutPosition> QgsLabelingResults::calloutsWithinRectangle( const QgsRectangle &rectangle ) const
83{
84 QList<QgsCalloutPosition> positions;
85
86 if ( mLabelSearchTree )
87 {
88 const QList<const QgsCalloutPosition *> positionPointers = mLabelSearchTree->calloutsInRectangle( rectangle );
89 for ( const QgsCalloutPosition *pos : positionPointers )
90 {
91 positions.push_back( QgsCalloutPosition( *pos ) );
92 }
93 }
94
95 return positions;
96}
97
99{
100 mLabelSearchTree->setMapSettings( settings );
101}
Represents the calculated placement of a map label callout line.
Represents the calculated placement of a map label.
Queries the labeling structure at a given point.
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).
Contains configuration for rendering maps.
Represents a 2D point.
Definition qgspointxy.h:62
A rectangle specified with double values.