26 : mLabelSearchTree( enableSearchTree ? std::make_unique<
QgsLabelSearchTree >() : nullptr )
33 return static_cast< bool >( mLabelSearchTree );
39 const QString &layerName,
40 const QString &labeltext,
41 const QFont &labelfont,
44 const QString &providerId,
54 QVector<QgsPointXY> cornerPoints;
55 QVector< double > cornerPointsX;
56 QVector< double > cornerPointsY;
57 cornerPoints.resize( 4 );
58 cornerPointsX.resize( 5 );
59 cornerPointsY.resize( 5 );
60 double xMin = std::numeric_limits< double >::max();
61 double yMin = std::numeric_limits< double >::max();
62 double xMax = std::numeric_limits< double >::lowest();
63 double yMax = std::numeric_limits< double >::lowest();
64 for (
int i = 0; i < 4; ++i )
67 const QPointF res = mTransform.map( QPointF( labelPos->
getX( i ), labelPos->
getY( i ) ) );
69 cornerPointsX[i] = res.x();
70 cornerPointsY[i] = res.y();
71 xMin = std::min( xMin, res.x() );
72 xMax = std::max( xMax, res.x() );
73 yMin = std::min( yMin, res.y() );
74 yMax = std::max( yMax, res.y() );
76 cornerPointsX[4] = cornerPointsX[0];
77 cornerPointsY[4] = cornerPointsY[0];
80 long long uniqueLinkedId = 0;
82 uniqueLinkedId = linkedId;
84 uniqueLinkedId = mNextFeatureId++;
87 const QgsGeometry labelGeometry( std::make_unique< QgsPolygon >(
new QgsLineString( cornerPointsX, cornerPointsY ) ) );
88 auto newEntry = std::make_unique< QgsLabelPosition >(
90 -labelPos->
getAlpha() * 180 / M_PI + mMapSettings.rotation(),
105 newEntry->groupedLabelId = uniqueLinkedId;
107 if ( uniqueLinkedId != 0 )
109 mLinkedLabelHash[uniqueLinkedId].append( newEntry.get() );
112 if ( mLabelSearchTree )
114 mLabelSearchTree->mSpatialIndex.insert( newEntry.get(), bounds );
116 mOwnedPositions.emplace_back( std::move( newEntry ) );
120 return insertLabel( next, featureId, layerName, labeltext, labelfont, diagram, pinned, providerId, isUnplaced, uniqueLinkedId );
127 const QPointF origin = position.
origin();
128 const QPointF destination = position.
destination();
130 auto newEntry = std::make_unique< QgsCalloutPosition >( position );
132 if ( mLabelSearchTree )
134 mLabelSearchTree->mCalloutIndex.insert( newEntry.get(),
QgsRectangle( origin.x(), origin.y(), origin.x(), origin.y() ) );
135 mLabelSearchTree->mCalloutIndex.insert( newEntry.get(),
QgsRectangle( destination.x(), destination.y(), destination.x(), destination.y() ) );
138 mOwnedCalloutPositions.emplace_back( std::move( newEntry ) );
145 QList<QgsLabelPosition> res;
146 res.reserve(
static_cast< qsizetype
>( mOwnedPositions.size() ) );
147 for (
const std::unique_ptr< QgsLabelPosition > &pos : mOwnedPositions )
156 QList<QgsLabelPosition> positions;
158 QList<QgsLabelPosition *> positionPointers;
159 if ( mLabelSearchTree )
161 mLabelSearchTree->label( p, positionPointers );
162 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
163 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
174 QList<QgsLabelPosition> positions;
176 QList<QgsLabelPosition *> positionPointers;
177 if ( mLabelSearchTree )
179 mLabelSearchTree->labelsInRect( r, positionPointers );
180 QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
181 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
192 QList<QgsLabelPosition> positions;
193 if ( mLabelSearchTree )
195 const QList<QgsLabelPosition *> positionPointers = mLinkedLabelHash.value( groupId );
196 positions.reserve( positionPointers.size() );
205 QList<QgsCalloutPosition> positions;
207 if ( mLabelSearchTree )
209 const QList<const QgsCalloutPosition *> positionPointers = mLabelSearchTree->calloutsInRectangle( rectangle );
221 mMapSettings = settings;
226 mTransform = QTransform::fromTranslate( center.
x(), center.
y() );
227 mTransform.rotate( mMapSettings.rotation() );
228 mTransform.translate( -center.
x(), -center.
y() );
232 mTransform = QTransform();
Represents the calculated placement of a map label callout line.
QPointF origin() const
Returns the origin of the callout line, in map coordinates.
QPointF destination() const
Returns the destination of the callout line, in map coordinates.
A geometry is the spatial representation of a feature.
Represents the calculated placement of a map label.
Queries the labeling structure at a given point.
bool insertCallout(const QgsCalloutPosition &position)
Inserts a rendered callout position.
bool hasSearchTree() const
Returns true if the results were constructed with search tree enabled.
QList< QgsCalloutPosition > calloutsWithinRectangle(const QgsRectangle &rectangle) const
Returns a list of callouts with origins or destinations inside the given rectangle.
QgsLabelingResults(bool enableSearchTree=true)
Constructor for QgsLabelingResults.
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, long long linkedId=0)
Inserts label position.
void setMapSettings(const QgsMapSettings &settings)
Sets the map settings associated with the labeling run.
QList< QgsLabelPosition > allLabels() const
Returns a list of all labels generated by the labeling run.
QList< QgsLabelPosition > labelsAtPosition(const QgsPointXY &p) const
Returns the details of any labels placed at the specified point (in map coordinates).
QList< QgsLabelPosition > groupedLabelPositions(long long groupId) const
Returns a list of all label positions sharing the same group ID (i.e.
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
Returns the details of any labels placed within the specified rectangle (in map coordinates).
Line string geometry type, with support for z-dimension and m-values.
Contains configuration for rendering maps.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
A rectangle specified with double values.
LabelPosition is a candidate feature label position.
double getAlpha() const
Returns the angle to rotate text (in radians).
double getX(int i=0) const
Returns the down-left x coordinate.
double getY(int i=0) const
Returns the down-left y coordinate.
bool getUpsideDown() const
LabelPosition * nextPart() const
Returns the next part of this label position (i.e.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features