25 class 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]
46 scaledBounds[2], scaledBounds[3]
58 std::array< float, 4 > scaledBounds = scaleBounds( bounds );
61 scaledBounds[0], scaledBounds[ 1]
64 scaledBounds[2], scaledBounds[3]
76 bool mUseScale =
false;
78 std::array<float, 4> scaleBounds(
const QgsRectangle &bounds )
const
83 static_cast< float >( ( std::max( bounds.
xMinimum(), mMaxBounds.
xMinimum() ) - mXMin ) / mXRes ),
84 static_cast< float >( ( std::max( bounds.
yMinimum(), mMaxBounds.
yMinimum() ) - mYMin ) / mYRes ),
85 static_cast< float >( ( std::min( bounds.
xMaximum(), mMaxBounds.
xMaximum() ) - mXMin ) / mXRes ),
86 static_cast< float >( ( std::min( bounds.
yMaximum(), mMaxBounds.
yMaximum() ) - mYMin ) / mYRes )
91 static_cast< float >( bounds.
xMinimum() ),
92 static_cast< float >( bounds.
yMinimum() ),
93 static_cast< float >( bounds.
xMaximum() ),
94 static_cast< float >( bounds.
yMaximum() )
101 : mExtent( extent.buffered( std::max( extent.width(), extent.height() ) * 1000 ) )
102 , mAnnotationItemsIndex( std::make_unique< QgsRenderedItemResultsSpatialIndex >( mExtent ) )
111 QList< QgsRenderedItemDetails * > res;
112 for (
const auto &it : mDetails )
114 std::transform( it.second.begin(), it.second.end(), std::back_inserter( res ), [](
const auto & detail )
124 QList<const QgsRenderedAnnotationItemDetails *> res;
128 res << qgis::down_cast< const QgsRenderedAnnotationItemDetails * >( details );
147 QgsDebugMsg( QStringLiteral(
"Could not transform rendered item's bounds to map CRS" ) );
151 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
154 mDetails[ details->
layerId() ].emplace_back( std::unique_ptr< QgsRenderedItemDetails >( details ) );
160 for (
const QString &layerId : layerIds )
162 auto otherLayerIt = other->mDetails.find( layerId );
163 if ( otherLayerIt == other->mDetails.end() )
166 std::vector< std::unique_ptr< QgsRenderedItemDetails > > &source = otherLayerIt->second;
168 for ( std::unique_ptr< QgsRenderedItemDetails > &details : source )
171 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
173 mDetails[layerId].emplace_back( std::move( details ) );
176 other->mDetails.erase( otherLayerIt );
182 for (
auto layerIt = other->mDetails.begin(); layerIt != other->mDetails.end(); ++layerIt )
184 std::vector< std::unique_ptr< QgsRenderedItemDetails > > &dest = mDetails[layerIt->first];
185 dest.reserve( layerIt->second.size() );
186 for (
auto it = layerIt->second.begin(); it != layerIt->second.end(); ++it )
189 mAnnotationItemsIndex->insert( annotationDetails, annotationDetails->boundingBox() );
191 dest.emplace_back( std::move( *it ) );
194 other->mDetails.clear();
199 for (
const QString &layerId : layerIds )
201 auto it = mDetails.find( layerId );
202 if ( it != mDetails.end() )
203 mDetails.erase( it );
Custom exception class for Coordinate Reference System related exceptions.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
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 setBoundingBox(const QgsRectangle &bounds)
Sets the bounding box of the item (in map units).
QString layerId() const
Returns the layer ID of the associated map layer.
QgsRectangle boundingBox() const
Returns the bounding box of the item (in map units).
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.