25class QgsRenderedItemResultsSpatialIndex :
public RTree<const QgsRenderedItemDetails *, float, 2, float>
29 explicit QgsRenderedItemResultsSpatialIndex(
const QgsRectangle &maxBounds )
30 : mXMin( maxBounds.xMinimum() )
31 , mYMin( maxBounds.yMinimum() )
32 , mXRes( ( std::numeric_limits< float >::max() - 1 ) / ( maxBounds.xMaximum() - maxBounds.xMinimum() ) )
33 , mYRes( ( std::numeric_limits< float >::max() - 1 ) / ( maxBounds.yMaximum() - maxBounds.yMinimum() ) )
34 , mMaxBounds( maxBounds )
35 , mUseScale( !maxBounds.isNull() )
40 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
43 scaledBounds[0], scaledBounds[ 1]
47 scaledBounds[2], scaledBounds[ 3]
62 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
65 scaledBounds[0], scaledBounds[ 1]
69 scaledBounds[2], scaledBounds[ 3]
84 bool mUseScale =
false;
86 std::array<float, 4> scaleBounds(
const QgsRectangle &bounds )
const
91 static_cast< float >( ( std::max( bounds.
xMinimum(), mMaxBounds.
xMinimum() ) - mXMin ) / mXRes ),
92 static_cast< float >( ( std::max( bounds.
yMinimum(), mMaxBounds.
yMinimum() ) - mYMin ) / mYRes ),
93 static_cast< float >( ( std::min( bounds.
xMaximum(), mMaxBounds.
xMaximum() ) - mXMin ) / mXRes ),
94 static_cast< float >( ( std::min( bounds.
yMaximum(), mMaxBounds.
yMaximum() ) - mYMin ) / mYRes )
99 static_cast< float >( bounds.
xMinimum() ),
100 static_cast< float >( bounds.
yMinimum() ),
101 static_cast< float >( bounds.
xMaximum() ),
102 static_cast< float >( bounds.
yMaximum() )
109 : mExtent( extent.buffered( std::max( extent.width(), extent.height() ) * 1000 ) )
110 , mAnnotationItemsIndex( std::make_unique< QgsRenderedItemResultsSpatialIndex >( mExtent ) )
119 QList< QgsRenderedItemDetails * > res;
120 for (
const auto &it : mDetails )
122 std::transform( it.second.begin(), it.second.end(), std::back_inserter( res ), [](
const auto & detail )
132 QList<const QgsRenderedAnnotationItemDetails *> res;
136 res << qgis::down_cast< const QgsRenderedAnnotationItemDetails * >( details );
151 details->setBoundingBox( transformedBounds );
155 QgsDebugError( QStringLiteral(
"Could not transform rendered item's bounds to map CRS" ) );
159 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
162 mDetails[ details->layerId() ].emplace_back( std::unique_ptr< QgsRenderedItemDetails >( details ) );
168 for (
const QString &layerId : layerIds )
170 auto otherLayerIt = other->mDetails.find( layerId );
171 if ( otherLayerIt == other->mDetails.end() )
174 std::vector< std::unique_ptr< QgsRenderedItemDetails > > &source = otherLayerIt->second;
176 for ( std::unique_ptr< QgsRenderedItemDetails > &details : source )
179 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
181 mDetails[layerId].emplace_back( std::move( details ) );
184 other->mDetails.erase( otherLayerIt );
190 for (
auto layerIt = other->mDetails.begin(); layerIt != other->mDetails.end(); ++layerIt )
192 std::vector< std::unique_ptr< QgsRenderedItemDetails > > &dest = mDetails[layerIt->first];
193 dest.reserve( layerIt->second.size() );
194 for (
auto it = layerIt->second.begin(); it != layerIt->second.end(); ++it )
197 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
199 dest.emplace_back( std::move( *it ) );
202 other->mDetails.clear();
207 for (
const QString &layerId : layerIds )
209 auto it = mDetails.find( layerId );
210 if ( it != mDetails.end() )
211 mDetails.erase( it );
Custom exception class for Coordinate Reference System related exceptions.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Contains information about a rendered annotation item.
Base class for detailed information about a rendered item.
Stores collated details of rendered items during a map rendering operation.
void transferResults(QgsRenderedItemResults *other, const QStringList &layerIds)
Transfers all results from an other QgsRenderedItemResults object where the items have layer IDs matc...
QList< const QgsRenderedAnnotationItemDetails * > renderedAnnotationItemsInBounds(const QgsRectangle &bounds) const
Returns a list with details of the rendered annotation items within the specified bounds.
QgsRenderedItemResults(const QgsRectangle &extent=QgsRectangle())
Constructor for QgsRenderedItemResults.
QList< QgsRenderedItemDetails * > renderedItems() const
Returns a list of all rendered items.
~QgsRenderedItemResults()
void eraseResultsFromLayers(const QStringList &layerIds)
Erases results from layers matching those in the specified list of layers IDs.
void appendResults(const QList< QgsRenderedItemDetails * > &results, const QgsRenderContext &context)
Appends rendered item details to the results object.
#define QgsDebugError(str)