Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add method for a callout to obtain a transform from the original
associated layer's crs to the destination map crs
- Loading branch information
|
@@ -183,9 +183,31 @@ Returns the desired drawing order (stacking) to use while rendering this callout |
|
|
The default order is QgsCallout.OrderBelowIndividualLabels. |
|
|
%End |
|
|
|
|
|
struct QgsCalloutContext |
|
|
{ |
|
|
bool allFeaturePartsLabeled; |
|
|
class QgsCalloutContext |
|
|
{ |
|
|
%Docstring |
|
|
Contains additional contextual information about the context in which a callout is |
|
|
being rendered. |
|
|
|
|
|
.. versionadded:: 3.10 |
|
|
%End |
|
|
|
|
|
%TypeHeaderCode |
|
|
#include "qgscallout.h" |
|
|
%End |
|
|
public: |
|
|
bool allFeaturePartsLabeled; |
|
|
|
|
|
QgsCoordinateReferenceSystem originalFeatureCrs; |
|
|
|
|
|
QgsCoordinateTransform originalFeatureToMapTransform( const QgsRenderContext &renderContext ) const; |
|
|
%Docstring |
|
|
Returns the coordinate transform to convert from the original layer associated with |
|
|
the callout to the destination map CRS. |
|
|
|
|
|
.. versionadded:: 3.20 |
|
|
%End |
|
|
|
|
|
}; |
|
|
|
|
|
void render( QgsRenderContext &context, QRectF rect, const double angle, const QgsGeometry &anchor, QgsCalloutContext &calloutContext ); |
|
|
|
@@ -694,3 +694,13 @@ void QgsManhattanLineCallout::draw( QgsRenderContext &context, QRectF rect, cons |
|
|
drawCalloutLine( part ); |
|
|
} |
|
|
} |
|
|
|
|
|
QgsCoordinateTransform QgsCallout::QgsCalloutContext::originalFeatureToMapTransform( const QgsRenderContext &renderContext ) const |
|
|
{ |
|
|
if ( !mOriginalFeatureToMapTransform.isValid() ) |
|
|
{ |
|
|
// lazy initialization, only create if needed... |
|
|
mOriginalFeatureToMapTransform = QgsCoordinateTransform( originalFeatureCrs, renderContext.coordinateTransform().destinationCrs(), renderContext.transformContext() ); |
|
|
} |
|
|
return mOriginalFeatureToMapTransform; |
|
|
} |
|
@@ -211,10 +211,30 @@ class CORE_EXPORT QgsCallout |
|
|
* \ingroup core |
|
|
* \since QGIS 3.10 |
|
|
*/ |
|
|
struct CORE_EXPORT QgsCalloutContext |
|
|
class CORE_EXPORT QgsCalloutContext |
|
|
{ |
|
|
//! TRUE if all parts of associated feature were labeled |
|
|
bool allFeaturePartsLabeled = false; |
|
|
public: |
|
|
//! TRUE if all parts of associated feature were labeled |
|
|
bool allFeaturePartsLabeled = false; |
|
|
|
|
|
/** |
|
|
* Contains the CRS of the original feature associated with this callout. |
|
|
* |
|
|
* \since QGIS 3.18 |
|
|
*/ |
|
|
QgsCoordinateReferenceSystem originalFeatureCrs; |
|
|
|
|
|
/** |
|
|
* Returns the coordinate transform to convert from the original layer associated with |
|
|
* the callout to the destination map CRS. |
|
|
* |
|
|
* \since QGIS 3.20 |
|
|
*/ |
|
|
QgsCoordinateTransform originalFeatureToMapTransform( const QgsRenderContext &renderContext ) const; |
|
|
|
|
|
private: |
|
|
//! Lazy initialized coordinate transform from original feature CRS to map CRS |
|
|
mutable QgsCoordinateTransform mOriginalFeatureToMapTransform; |
|
|
}; |
|
|
|
|
|
/** |
|
|
|
@@ -330,6 +330,7 @@ void QgsVectorLayerLabelProvider::drawCallout( QgsRenderContext &context, pal::L |
|
|
g.transform( xform.transform() ); |
|
|
QgsCallout::QgsCalloutContext calloutContext; |
|
|
calloutContext.allFeaturePartsLabeled = label->getFeaturePart()->feature()->labelAllParts(); |
|
|
calloutContext.originalFeatureCrs = label->getFeaturePart()->feature()->originalFeatureCrs(); |
|
|
mSettings.callout()->render( context, rect, label->getAlpha() * 180 / M_PI, g, calloutContext ); |
|
|
} |
|
|
} |
|
|
|
@@ -649,6 +649,9 @@ LabelRenderJob QgsMapRendererJob::prepareLabelingJob( QPainter *painter, QgsLabe |
|
|
job.context.setLabelingEngine( labelingEngine2 ); |
|
|
job.context.setExtent( mSettings.visibleExtent() ); |
|
|
job.context.setFeatureFilterProvider( mFeatureFilterProvider ); |
|
|
QgsCoordinateTransform ct; |
|
|
ct.setDestinationCrs( mSettings.destinationCrs() ); |
|
|
job.context.setCoordinateTransform( ct ); |
|
|
|
|
|
// if we can use the cache, let's do it and avoid rendering! |
|
|
bool hasCache = canUseLabelCache && mCache && mCache->hasCacheImage( LABEL_CACHE_ID ); |
|
|