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 ) );
116 return insertLabel( next, featureId, layerName, labeltext, labelfont, diagram, pinned, providerId );
123 mMapSettings = settings;
129 mTransform = QTransform::fromTranslate( center.
x(), center.
y() );
130 mTransform.rotate( mMapSettings.
rotation() );
131 mTransform.translate( -center.
x(), -center.
y() );
135 mTransform = QTransform();
141 mSpatialIndex.RemoveAll();
144 mOwnedPositions.clear();
A rectangle specified with double values.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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)
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
A geometry is the spatial representation of a feature.
bool insertLabel(pal::LabelPosition *labelPos, int featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram=false, bool pinned=false, const QString &providerId=QString())
Inserts label position.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
The QgsMapSettings class contains configuration for rendering of the map.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double getY(int i=0) const
Returns the down-left y coordinate.
QgsPointXY center() const
Returns the center point of the rectangle.
bool searchCallback(QgsLabelPosition *pos, void *context)
LabelPosition * getNextPart() const
double getX(int i=0) const
Returns the down-left x coordinate.
bool getUpsideDown() const
double getAlpha() const
Returns the angle to rotate text (in rad).
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
void label(const QgsPointXY &p, QList< QgsLabelPosition * > &posList) const
Returns label position(s) at a given point.
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.
void labelsInRect(const QgsRectangle &r, QList< QgsLabelPosition * > &posList) const
Returns label position(s) in given rectangle.
double xMinimum() const
Returns the x minimum value (left side of rectangle).