Skip to content

Commit 8f15cdf

Browse files
committed
Respect transform contexts when tracing
1 parent 13ad760 commit 8f15cdf

File tree

9 files changed

+51
-32
lines changed

9 files changed

+51
-32
lines changed

doc/api_break.dox

+8
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,12 @@ loadDefaultStyle argument.
21332133
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.
21342134

21352135

2136+
QgsRasterLayerSaveAsDialog {#qgis_api_break_3_0_QgsRasterLayerSaveAsDialog}
2137+
--------------------------
2138+
2139+
- The currentExtent and currentCrs arguments have been dropped from the constructor. Use setMapCanvas() instead.
2140+
2141+
21362142
QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
21372143
------------------
21382144

@@ -2524,6 +2530,8 @@ QgsTracer {#qgis_api_break_3_0_QgsTracer}
25242530
---------
25252531

25262532
- hasCrsTransformEnabled() and setCrsTransformEnabled() were removed. CRS transformation is now always enabled when required.
2533+
- setDestinationCrs() now requires a QgsCoordinateTransformContext argument.
2534+
25272535

25282536
QgsTransaction {#qgis_api_break_3_0_QgsTransaction}
25292537
--------------

python/core/qgstracer.sip

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ Set layers used for tracing
4343

4444
QgsCoordinateReferenceSystem destinationCrs() const;
4545
%Docstring
46-
Get CRS used for tracing
46+
Returns the CRS used for tracing.
47+
48+
.. seealso:: :py:func:`setDestinationCrs()`
4749
%End
48-
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
50+
51+
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
4952
%Docstring
50-
Set CRS used for tracing
53+
Sets the ``crs`` and transform ``context`` used for tracing.
54+
55+
.. seealso:: :py:func:`destinationCrs()`
5156
%End
5257

5358
QgsRectangle extent() const;

python/gui/qgsmapcanvas.sip

+7
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,13 @@ Emitted when zoom next status changed
898898
Emitted when map CRS has changed
899899

900900
.. versionadded:: 2.4
901+
%End
902+
903+
void transformContextChanged();
904+
%Docstring
905+
Emitted when the canvas transform context is changed.
906+
907+
.. versionadded:: 3.0
901908
%End
902909

903910
void currentLayerChanged( QgsMapLayer *layer );

src/core/qgstracer.cpp

+5-24
Original file line numberDiff line numberDiff line change
@@ -473,37 +473,20 @@ bool QgsTracer::initGraph()
473473

474474
t1.start();
475475
int featuresCounted = 0;
476-
Q_FOREACH ( QgsVectorLayer *vl, mLayers )
476+
for ( QgsVectorLayer *vl : qgis::as_const( mLayers ) )
477477
{
478-
Q_NOWARN_DEPRECATED_PUSH
479-
QgsCoordinateTransform ct( vl->crs(), mCRS );
480-
Q_NOWARN_DEPRECATED_POP
481-
482478
QgsFeatureRequest request;
483479
request.setSubsetOfAttributes( QgsAttributeList() );
480+
request.setDestinationCrs( mCRS, mTransformContext );
484481
if ( !mExtent.isEmpty() )
485-
request.setFilterRect( ct.transformBoundingBox( mExtent, QgsCoordinateTransform::ReverseTransform ) );
482+
request.setFilterRect( mExtent );
486483

487484
QgsFeatureIterator fi = vl->getFeatures( request );
488485
while ( fi.nextFeature( f ) )
489486
{
490487
if ( !f.hasGeometry() )
491488
continue;
492489

493-
if ( !ct.isShortCircuited() )
494-
{
495-
try
496-
{
497-
QgsGeometry transformedGeom = f.geometry();
498-
transformedGeom.transform( ct );
499-
f.setGeometry( transformedGeom );
500-
}
501-
catch ( QgsCsException & )
502-
{
503-
continue; // ignore if the transform failed
504-
}
505-
}
506-
507490
extractLinework( f.geometry(), mpl );
508491

509492
++featuresCounted;
@@ -596,12 +579,10 @@ void QgsTracer::setLayers( const QList<QgsVectorLayer *> &layers )
596579
invalidateGraph();
597580
}
598581

599-
void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
582+
void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context )
600583
{
601-
if ( mCRS == crs )
602-
return;
603-
604584
mCRS = crs;
585+
mTransformContext = context;
605586
invalidateGraph();
606587
}
607588

src/core/qgstracer.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@ class CORE_EXPORT QgsTracer : public QObject
5353
//! Set layers used for tracing
5454
void setLayers( const QList<QgsVectorLayer *> &layers );
5555

56-
//! Get CRS used for tracing
56+
/**
57+
* Returns the CRS used for tracing.
58+
* \see setDestinationCrs()
59+
*/
5760
QgsCoordinateReferenceSystem destinationCrs() const { return mCRS; }
58-
//! Set CRS used for tracing
59-
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
61+
62+
/**
63+
* Sets the \a crs and transform \a context used for tracing.
64+
* \see destinationCrs()
65+
*/
66+
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
6067

6168
//! Get extent to which graph's features will be limited (empty extent means no limit)
6269
QgsRectangle extent() const { return mExtent; }
@@ -161,6 +168,8 @@ class CORE_EXPORT QgsTracer : public QObject
161168
QList<QgsVectorLayer *> mLayers;
162169
//! Destination CRS in which graph is built and tracing done
163170
QgsCoordinateReferenceSystem mCRS;
171+
//! Coordinate transform context
172+
QgsCoordinateTransformContext mTransformContext;
164173
//! Extent for graph building (empty extent means no limit)
165174
QgsRectangle mExtent;
166175

src/gui/qgsmapcanvas.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
144144
this, [ = ]
145145
{
146146
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
147+
emit transformContextChanged();
147148
refresh();
148149
} );
149150

src/gui/qgsmapcanvas.h

+6
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,12 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
801801
*/
802802
void destinationCrsChanged();
803803

804+
/**
805+
* Emitted when the canvas transform context is changed.
806+
* \since QGIS 3.0
807+
*/
808+
void transformContextChanged();
809+
804810
/**
805811
* Emitted when the current layer is changed
806812
* \since QGIS 2.8

src/gui/qgsmapcanvastracer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ QgsMapCanvasTracer::QgsMapCanvasTracer( QgsMapCanvas *canvas, QgsMessageBar *mes
3939

4040
// when things change we just invalidate the graph - and set up new parameters again only when necessary
4141
connect( canvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsMapCanvasTracer::invalidateGraph );
42+
connect( canvas, &QgsMapCanvas::transformContextChanged, this, &QgsMapCanvasTracer::invalidateGraph );
4243
connect( canvas, &QgsMapCanvas::layersChanged, this, &QgsMapCanvasTracer::invalidateGraph );
4344
connect( canvas, &QgsMapCanvas::extentsChanged, this, &QgsMapCanvasTracer::invalidateGraph );
4445
connect( canvas, &QgsMapCanvas::currentLayerChanged, this, &QgsMapCanvasTracer::onCurrentLayerChanged );
@@ -96,7 +97,7 @@ void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVerte
9697

9798
void QgsMapCanvasTracer::configure()
9899
{
99-
setDestinationCrs( mCanvas->mapSettings().destinationCrs() );
100+
setDestinationCrs( mCanvas->mapSettings().destinationCrs(), mCanvas->mapSettings().transformContext() );
100101
setExtent( mCanvas->extent() );
101102

102103
QList<QgsVectorLayer *> layers;

tests/src/core/testqgstracer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ void TestQgsTracer::testReprojection()
313313

314314
QgsTracer tracer;
315315
tracer.setLayers( QList<QgsVectorLayer *>() << vl );
316-
tracer.setDestinationCrs( dstCrs );
316+
QgsCoordinateTransformContext context;
317+
tracer.setDestinationCrs( dstCrs, context );
317318
tracer.init();
318319

319320
QgsPolylineXY points1 = tracer.findShortestPath( p1, p2 );

0 commit comments

Comments
 (0)