20 QList<QgsLabelPosition *> *list =
static_cast< QList<QgsLabelPosition *>*
>( context );
21 list->push_back( pos );
34 c_min[0] = p.
x() - 0.1;
35 c_min[1] = p.
y() - 0.1;
37 c_max[0] = p.
x() + 0.1;
38 c_max[1] = p.
y() + 0.1;
40 QList<QgsLabelPosition *> searchResults;
41 mSpatialIndex.Search( c_min, c_max,
searchCallback, &searchResults );
45 QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin();
46 for ( ; resultIt != searchResults.constEnd(); ++resultIt )
48 if ( ( *resultIt )->labelGeometry.contains( &p ) )
50 posList.push_back( *resultIt );
64 QList<QgsLabelPosition *> searchResults;
65 mSpatialIndex.Search( c_min, c_max,
searchCallback, &searchResults );
68 QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin();
69 for ( ; resultIt != searchResults.constEnd(); ++resultIt )
71 if ( ( *resultIt )->labelGeometry.intersects( r ) )
73 posList.push_back( *resultIt );
85 QVector<QgsPointXY> cornerPoints;
86 cornerPoints.reserve( 4 );
87 double xMin = std::numeric_limits< double >::max();
88 double yMin = std::numeric_limits< double >::max();
89 double xMax = std::numeric_limits< double >::lowest();
90 double yMax = std::numeric_limits< double >::lowest();
91 for (
int i = 0; i < 4; ++i )
94 QPointF res = mTransform.map( QPointF( labelPos->
getX( i ), labelPos->
getY( i ) ) );
96 xMin = std::min( xMin, res.x() );
97 xMax = std::max( xMax, res.x() );
98 yMin = std::min( yMin, res.y() );
99 yMax = std::max( yMax, res.y() );
109 std::unique_ptr< QgsLabelPosition > newEntry = qgis::make_unique< QgsLabelPosition >( featureId, labelPos->
getAlpha() + mMapSettings.
rotation(), cornerPoints,
QgsRectangle( c_min[0], c_min[1], c_max[0], c_max[1] ),
110 labelPos->
getWidth(), labelPos->
getHeight(), layerName, labeltext, labelfont, labelPos->
getUpsideDown(), diagram, pinned, providerId, labelGeometry );
111 mSpatialIndex.Insert( c_min, c_max, newEntry.get() );
112 mOwnedPositions.emplace_back( std::move( newEntry ) );
118 mMapSettings = settings;
124 mTransform = QTransform::fromTranslate( center.
x(), center.
y() );
125 mTransform.rotate( mMapSettings.
rotation() );
126 mTransform.translate( -center.
x(), -center.
y() );
130 mTransform = QTransform();
136 mSpatialIndex.RemoveAll();
139 mOwnedPositions.clear();
A rectangle specified with double values.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
double getY(int i=0) const
Returns the down-left y coordinate.
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.
bool searchCallback(QgsLabelPosition *pos, void *context)
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())
Inserts label position.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double getAlpha() const
Returns the angle to rotate text (in rad).
double getX(int i=0) const
Returns the down-left x coordinate.
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.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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.