Skip to content

Commit 34f79cf

Browse files
committed
Make a correct copy of QgsCoordinateTransform for labeling (hope it fixes #9600)
1 parent 42a4e75 commit 34f79cf

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/core/qgscoordinatetransform.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ QgsCoordinateTransform::~QgsCoordinateTransform()
127127
}
128128
}
129129

130+
QgsCoordinateTransform* QgsCoordinateTransform::clone() const
131+
{
132+
QgsCoordinateTransform* tr = new QgsCoordinateTransform( sourceCrs(), destCRS() );
133+
tr->setSourceDatumTransform( sourceDatumTransform() );
134+
tr->setDestinationDatumTransform( destinationDatumTransform() );
135+
tr->initialise();
136+
return tr;
137+
}
138+
130139
void QgsCoordinateTransform::setSourceCrs( const QgsCoordinateReferenceSystem& theCRS )
131140
{
132141
mSourceCRS = theCRS;

src/core/qgscoordinatetransform.h

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class CORE_EXPORT QgsCoordinateTransform : public QObject
8888
//! destructor
8989
~QgsCoordinateTransform();
9090

91+
QgsCoordinateTransform* clone() const;
92+
9193
//! Enum used to indicate the direction (forward or inverse) of the transform
9294
enum TransformDirection
9395
{

src/core/qgspallabeling.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -3297,10 +3297,15 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
32973297
lyr.fieldIndex = fldIndex;
32983298

32993299
lyr.xform = mMapRenderer->coordinateTransform();
3300+
lyr.ct = 0;
33003301
if ( mMapRenderer->hasCrsTransformEnabled() )
3301-
lyr.ct = new QgsCoordinateTransform( layer->crs(), mMapRenderer->destinationCrs() );
3302-
else
3303-
lyr.ct = NULL;
3302+
{
3303+
const QgsCoordinateTransform* tr = mMapRenderer->transformation( layer );
3304+
if ( tr )
3305+
{
3306+
lyr.ct = tr->clone();
3307+
}
3308+
}
33043309
lyr.ptZero = lyr.xform->toMapCoordinates( 0, 0 );
33053310
lyr.ptOne = lyr.xform->toMapCoordinates( 1, 0 );
33063311

@@ -3318,10 +3323,15 @@ int QgsPalLabeling::addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSetti
33183323
l->setArrangementFlags( s->placementFlags );
33193324

33203325
s->palLayer = l;
3326+
s->ct = 0;
33213327
if ( mMapRenderer->hasCrsTransformEnabled() )
3322-
s->ct = new QgsCoordinateTransform( layer->crs(), mMapRenderer->destinationCrs() );
3323-
else
3324-
s->ct = NULL;
3328+
{
3329+
const QgsCoordinateTransform* tr = mMapRenderer->transformation( layer );
3330+
if ( tr )
3331+
{
3332+
s->ct = tr->clone();
3333+
}
3334+
}
33253335
s->xform = mMapRenderer->coordinateTransform();
33263336
mActiveDiagramLayers.insert( layer, *s );
33273337
return 1;

0 commit comments

Comments
 (0)