26 QList<QgsLabelPosition *> searchResults;
29 searchResults.push_back( const_cast< QgsLabelPosition * >( pos ) );
35 QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin();
36 for ( ; resultIt != searchResults.constEnd(); ++resultIt )
38 if ( ( *resultIt )->labelGeometry.contains( &p ) )
40 posList.push_back( *resultIt );
47 QList<QgsLabelPosition *> searchResults;
50 searchResults.push_back( const_cast< QgsLabelPosition * >( pos ) );
55 QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin();
56 for ( ; resultIt != searchResults.constEnd(); ++resultIt )
58 if ( ( *resultIt )->labelGeometry.intersects( r ) )
60 posList.push_back( *resultIt );
72 QVector<QgsPointXY> cornerPoints;
73 cornerPoints.reserve( 4 );
74 double xMin = std::numeric_limits< double >::max();
75 double yMin = std::numeric_limits< double >::max();
76 double xMax = std::numeric_limits< double >::lowest();
77 double yMax = std::numeric_limits< double >::lowest();
78 for (
int i = 0; i < 4; ++i )
81 QPointF res = mTransform.map( QPointF( labelPos->
getX( i ), labelPos->
getY( i ) ) );
83 xMin = std::min( xMin, res.x() );
84 xMax = std::max( xMax, res.x() );
85 yMin = std::min( yMin, res.y() );
86 yMax = std::max( yMax, res.y() );
91 std::unique_ptr< QgsLabelPosition > newEntry = qgis::make_unique< QgsLabelPosition >( featureId, labelPos->
getAlpha() + mMapSettings.
rotation(), cornerPoints, bounds,
92 labelPos->
getWidth(), labelPos->
getHeight(), layerName, labeltext, labelfont, labelPos->
getUpsideDown(), diagram, pinned, providerId, labelGeometry, isUnplaced );
93 mSpatialIndex.
insert( newEntry.get(), bounds );
94 mOwnedPositions.emplace_back( std::move( newEntry ) );
98 return insertLabel( next, featureId, layerName, labeltext, labelfont, diagram, pinned, providerId, isUnplaced );
105 mMapSettings = settings;
111 mTransform = QTransform::fromTranslate( center.
x(), center.
y() );
112 mTransform.rotate( mMapSettings.
rotation() );
113 mTransform.translate( -center.
x(), -center.
y() );
117 mTransform = QTransform();
LabelPosition * nextPart() const
Returns the next part of this label position (i.e.
A rectangle specified with double values.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
bool insert(T *data, const QgsRectangle &bounds)
Inserts new data into the spatial index, with the specified bounds.
double getY(int i=0) const
Returns the down-left y coordinate.
bool insertLabel(pal::LabelPosition *labelPos, QgsFeatureId featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram=false, bool pinned=false, const QString &providerId=QString(), bool isUnplaced=false)
Inserts label position.
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
A geometry is the spatial representation of a feature.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
void labelsInRect(const QgsRectangle &r, QList< QgsLabelPosition *> &posList) const
Returns label position(s) in given rectangle.
The QgsMapSettings class contains configuration for rendering of the map.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
QgsLabelSearchTree()
Constructor for QgsLabelSearchTree.
double getAlpha() const
Returns the angle to rotate text (in rad).
double getX(int i=0) const
Returns the down-left x coordinate.
Q_DECL_DEPRECATED void clear()
Removes and deletes all the entries.
void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
LabelPosition is a candidate feature label position.
bool getUpsideDown() const
QgsPointXY center() const
Returns the center point of the rectangle.
void label(const QgsPointXY &p, QList< QgsLabelPosition *> &posList) const
Returns label position(s) at a given point.
bool intersects(const QgsRectangle &bounds, const std::function< bool(T *data)> &callback) const
Performs an intersection check against the index, for data intersecting the specified bounds...