QGIS API Documentation 4.3.0-Master (ffcfc20b9b4)
Loading...
Searching...
No Matches
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
18
20
21void 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
43QList<QgsLabelPosition> QgsLabelSearchTree::allLabels() const
44{
45 return {};
46}
47
48void 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
67QList<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
83
Represents the calculated placement of a map label callout line.
Represents the calculated placement of a map label.
Q_DECL_DEPRECATED void clear()
Removes and deletes all the entries.
void label(const QgsPointXY &p, QList< QgsLabelPosition * > &posList) const
Returns label position(s) at a given point.
void labelsInRect(const QgsRectangle &r, QList< QgsLabelPosition * > &posList) const
Returns label position(s) in given rectangle.
QList< const QgsCalloutPosition * > calloutsInRectangle(const QgsRectangle &rectangle) const
Returns the list of callouts with origins or destinations inside the given rectangle.
Q_DECL_DEPRECATED void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
Q_DECL_DEPRECATED QList< QgsLabelPosition > allLabels() const
Returns a list of all labels generated by the labeling run.
Contains configuration for rendering maps.
Represents a 2D point.
Definition qgspointxy.h:62
double y
Definition qgspointxy.h:66
double x
Definition qgspointxy.h:65
A rectangle specified with double values.