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 );