26using namespace Qt::StringLiterals;
29class QgsRenderedItemResultsSpatialIndex :
public RTree<const QgsRenderedItemDetails *, float, 2, float>
33 explicit QgsRenderedItemResultsSpatialIndex(
const QgsRectangle &maxBounds )
34 : mXMin( maxBounds.xMinimum() )
35 , mYMin( maxBounds.yMinimum() )
36 , mXRes( ( std::numeric_limits< float >::max() - 1 ) / ( maxBounds.xMaximum() - maxBounds.xMinimum() ) )
37 , mYRes( ( std::numeric_limits< float >::max() - 1 ) / ( maxBounds.yMaximum() - maxBounds.yMinimum() ) )
38 , mMaxBounds( maxBounds )
39 , mUseScale( !maxBounds.isNull() )
42 void insert(
const QgsRenderedItemDetails *details,
const QgsRectangle &bounds )
44 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
47 scaledBounds[0], scaledBounds[ 1]
51 scaledBounds[2], scaledBounds[ 3]
64 bool intersects(
const QgsRectangle &bounds,
const std::function<
bool(
const QgsRenderedItemDetails *details )> &callback )
const
66 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
69 scaledBounds[0], scaledBounds[ 1]
73 scaledBounds[2], scaledBounds[ 3]
87 QgsRectangle mMaxBounds;
88 bool mUseScale =
false;
90 std::array<float, 4> scaleBounds(
const QgsRectangle &bounds )
const
95 static_cast< float >( ( std::max( bounds.
xMinimum(), mMaxBounds.
xMinimum() ) - mXMin ) / mXRes ),
96 static_cast< float >( ( std::max( bounds.
yMinimum(), mMaxBounds.
yMinimum() ) - mYMin ) / mYRes ),
97 static_cast< float >( ( std::min( bounds.
xMaximum(), mMaxBounds.
xMaximum() ) - mXMin ) / mXRes ),
98 static_cast< float >( ( std::min( bounds.
yMaximum(), mMaxBounds.
yMaximum() ) - mYMin ) / mYRes )
103 static_cast< float >( bounds.
xMinimum() ),
104 static_cast< float >( bounds.
yMinimum() ),
105 static_cast< float >( bounds.
xMaximum() ),
106 static_cast< float >( bounds.
yMaximum() )
113 : mExtent( extent.buffered( std::max( extent.width(), extent.height() ) * 1000 ) )
114 , mAnnotationItemsIndex( std::make_unique< QgsRenderedItemResultsSpatialIndex >( mExtent ) )
123 QList< QgsRenderedItemDetails * > res;
124 for (
const auto &it : mDetails )
126 std::transform( it.second.begin(), it.second.end(), std::back_inserter( res ), [](
const auto & detail )
136 QList<const QgsRenderedAnnotationItemDetails *> res;
140 res << qgis::down_cast< const QgsRenderedAnnotationItemDetails * >( details );
155 details->setBoundingBox( transformedBounds );
159 QgsDebugError( u
"Could not transform rendered item's bounds to map CRS"_s );
163 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
166 mDetails[ details->layerId() ].emplace_back( std::unique_ptr< QgsRenderedItemDetails >( details ) );
172 for (
const QString &layerId : layerIds )
174 auto otherLayerIt = other->mDetails.find( layerId );
175 if ( otherLayerIt == other->mDetails.end() )
178 std::vector< std::unique_ptr< QgsRenderedItemDetails > > &source = otherLayerIt->second;
180 for ( std::unique_ptr< QgsRenderedItemDetails > &details : source )
183 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
185 mDetails[layerId].emplace_back( std::move( details ) );
188 other->mDetails.erase( otherLayerIt );
194 for (
auto layerIt = other->mDetails.begin(); layerIt != other->mDetails.end(); ++layerIt )
196 std::vector< std::unique_ptr< QgsRenderedItemDetails > > &dest = mDetails[layerIt->first];
197 dest.reserve( layerIt->second.size() );
198 for (
auto it = layerIt->second.begin(); it != layerIt->second.end(); ++it )
201 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
203 dest.emplace_back( std::move( *it ) );
206 other->mDetails.clear();
211 for (
const QString &layerId : layerIds )
213 auto it = mDetails.find( layerId );
214 if ( it != mDetails.end() )
215 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.
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)