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> res;
48 res.reserve( mOwnedPositions.size() );
49 for (
const std::unique_ptr< QgsLabelPosition > &pos : mOwnedPositions )
58 QList<QgsLabelPosition *> searchResults;
66 QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin();
67 for ( ; resultIt != searchResults.constEnd(); ++resultIt )
69 if ( ( *resultIt )->labelGeometry.intersects( r ) )
71 posList.push_back( *resultIt );
83 QVector<QgsPointXY> cornerPoints;
84 cornerPoints.reserve( 4 );
85 double xMin = std::numeric_limits< double >::max();
86 double yMin = std::numeric_limits< double >::max();
87 double xMax = std::numeric_limits< double >::lowest();
88 double yMax = std::numeric_limits< double >::lowest();
89 for (
int i = 0; i < 4; ++i )
92 const QPointF res = mTransform.map( QPointF( labelPos->
getX( i ), labelPos->
getY( i ) ) );
94 xMin = std::min( xMin, res.x() );
95 xMax = std::max( xMax, res.x() );
96 yMin = std::min( yMin, res.y() );
97 yMax = std::max( yMax, res.y() );
102 std::unique_ptr< QgsLabelPosition > newEntry = std::make_unique< QgsLabelPosition >( featureId, labelPos->
getAlpha() + mMapSettings.
rotation(), cornerPoints, bounds,
103 labelPos->
getWidth(), labelPos->
getHeight(), layerName, labeltext, labelfont, labelPos->
getUpsideDown(), diagram, pinned, providerId, labelGeometry, isUnplaced );
104 mSpatialIndex.
insert( newEntry.get(), bounds );
105 mOwnedPositions.emplace_back( std::move( newEntry ) );
109 return insertLabel( next, featureId, layerName, labeltext, labelfont, diagram, pinned, providerId, isUnplaced );
116 const QPointF origin = position.
origin();
117 const QPointF destination = position.
destination();
119 std::unique_ptr< QgsCalloutPosition > newEntry = std::make_unique< QgsCalloutPosition >( position );
121 mCalloutIndex.
insert( newEntry.get(),
QgsRectangle( origin.x(), origin.y(), origin.x(), origin.y() ) );
122 mCalloutIndex.
insert( newEntry.get(),
QgsRectangle( destination.x(), destination.y(), destination.x(), destination.y() ) );
124 mOwnedCalloutPositions.emplace_back( std::move( newEntry ) );
131 QList<const QgsCalloutPosition *> searchResults;
134 searchResults.push_back( pos );
138 std::sort( searchResults.begin(), searchResults.end() );
139 searchResults.erase( std::unique( searchResults.begin(), searchResults.end() ), searchResults.end() );
141 return searchResults;
146 mMapSettings = settings;
152 mTransform = QTransform::fromTranslate( center.
x(), center.
y() );
153 mTransform.rotate( mMapSettings.
rotation() );
154 mTransform.translate( -center.
x(), -center.
y() );
158 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.
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.
bool insert(T *data, const QgsRectangle &bounds)
Inserts new data into the spatial index, with the specified bounds.
A geometry is the spatial representation of a feature.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygonXY.
Represents the calculated placement of a map label.
Q_DECL_DEPRECATED void clear()
Removes and deletes all the entries.
QgsLabelSearchTree()
Constructor for QgsLabelSearchTree.
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.
bool insertCallout(const QgsCalloutPosition &position)
Inserts a rendered callout position.
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.
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.
The QgsMapSettings class contains configuration for rendering of the map.
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 class to represent a 2D point.
A rectangle specified with double values.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
LabelPosition is a candidate feature label position.
double getAlpha() const
Returns the angle to rotate text (in rad).
LabelPosition * nextPart() const
Returns the next part of this label position (i.e.
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
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