QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
labeling
qgslabelsearchtree.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslabelsearchtree.cpp
3
---------------------
4
begin : November 2010
5
copyright : (C) 2010 by Marco Hugentobler
6
email : marco dot hugentobler at sourcepole dot ch
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
#include "
qgslabelsearchtree.h
"
16
17
QgsLabelSearchTree::QgsLabelSearchTree
() =
default
;
18
19
QgsLabelSearchTree::~QgsLabelSearchTree
() =
default
;
20
21
void
QgsLabelSearchTree::label
(
const
QgsPointXY
&point, QList<QgsLabelPosition *> &posList )
const
22
{
23
const
QgsPointXY
p( point );
24
25
QList<QgsLabelPosition *> searchResults;
26
mSpatialIndex.intersects(
QgsRectangle
( p.
x
() - 0.1, p.
y
() - 0.1, p.
x
() + 0.1, p.
y
() + 0.1 ), [&searchResults](
const
QgsLabelPosition
*pos ) ->
bool
{
27
searchResults.push_back( const_cast< QgsLabelPosition * >( pos ) );
28
return true;
29
} );
30
31
//tolerance +-0.1 could be high in case of degree crs, so check if p is really contained in the results
32
posList.clear();
33
QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin();
34
for
( ; resultIt != searchResults.constEnd(); ++resultIt )
35
{
36
if
( ( *resultIt )->labelGeometry.contains( &p ) )
37
{
38
posList.push_back( *resultIt );
39
}
40
}
41
}
42
43
QList<QgsLabelPosition>
QgsLabelSearchTree::allLabels
()
const
44
{
45
return
{};
46
}
47
48
void
QgsLabelSearchTree::labelsInRect
(
const
QgsRectangle
&r, QList<QgsLabelPosition *> &posList )
const
49
{
50
QList<QgsLabelPosition *> searchResults;
51
mSpatialIndex.intersects( r, [&searchResults](
const
QgsLabelPosition
*pos ) ->
bool
{
52
searchResults.push_back(
const_cast<
QgsLabelPosition
*
>
( pos ) );
53
return
true
;
54
} );
55
56
posList.clear();
57
QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin();
58
for
( ; resultIt != searchResults.constEnd(); ++resultIt )
59
{
60
if
( ( *resultIt )->labelGeometry.intersects( r ) )
61
{
62
posList.push_back( *resultIt );
63
}
64
}
65
}
66
67
QList<const QgsCalloutPosition *>
QgsLabelSearchTree::calloutsInRectangle
(
const
QgsRectangle
&rectangle )
const
68
{
69
QList<const QgsCalloutPosition *> searchResults;
70
mCalloutIndex.intersects( rectangle, [&searchResults](
const
QgsCalloutPosition
*pos ) ->
bool
{
71
searchResults.push_back( pos );
72
return
true
;
73
} );
74
75
std::sort( searchResults.begin(), searchResults.end() );
76
searchResults.erase( std::unique( searchResults.begin(), searchResults.end() ), searchResults.end() );
77
78
return
searchResults;
79
}
80
81
void
QgsLabelSearchTree::setMapSettings
(
const
QgsMapSettings
& )
82
{}
83
84
void
QgsLabelSearchTree::clear
()
85
{}
QgsCalloutPosition
Represents the calculated placement of a map label callout line.
Definition
qgscalloutposition.h:32
QgsLabelPosition
Represents the calculated placement of a map label.
Definition
qgslabelposition.h:36
QgsLabelSearchTree::clear
Q_DECL_DEPRECATED void clear()
Removes and deletes all the entries.
Definition
qgslabelsearchtree.cpp:84
QgsLabelSearchTree::QgsLabelSearchTree
QgsLabelSearchTree()
QgsLabelSearchTree::label
void label(const QgsPointXY &p, QList< QgsLabelPosition * > &posList) const
Returns label position(s) at a given point.
Definition
qgslabelsearchtree.cpp:21
QgsLabelSearchTree::labelsInRect
void labelsInRect(const QgsRectangle &r, QList< QgsLabelPosition * > &posList) const
Returns label position(s) in given rectangle.
Definition
qgslabelsearchtree.cpp:48
QgsLabelSearchTree::calloutsInRectangle
QList< const QgsCalloutPosition * > calloutsInRectangle(const QgsRectangle &rectangle) const
Returns the list of callouts with origins or destinations inside the given rectangle.
Definition
qgslabelsearchtree.cpp:67
QgsLabelSearchTree::~QgsLabelSearchTree
~QgsLabelSearchTree()
QgsLabelSearchTree::setMapSettings
Q_DECL_DEPRECATED void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
Definition
qgslabelsearchtree.cpp:81
QgsLabelSearchTree::allLabels
Q_DECL_DEPRECATED QList< QgsLabelPosition > allLabels() const
Returns a list of all labels generated by the labeling run.
Definition
qgslabelsearchtree.cpp:43
QgsMapSettings
Contains configuration for rendering maps.
Definition
qgsmapsettings.h:91
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
QgsPointXY::y
double y
Definition
qgspointxy.h:66
QgsPointXY::x
double x
Definition
qgspointxy.h:65
QgsRectangle
A rectangle specified with double values.
Definition
qgsrectangle.h:47
qgslabelsearchtree.h
Generated on
for QGIS API Documentation by
1.17.0