From 9fda6aaf53d814ab30783ae0fff3773abb1e572b Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Wed, 20 Jan 2016 09:43:55 +0100 Subject: [PATCH] [tracing] fix the case when OTF reprojection is disabled --- python/core/qgstracer.sip | 5 +++++ src/core/qgstracer.cpp | 14 ++++++++++++-- src/core/qgstracer.h | 7 +++++++ src/gui/qgsmapcanvastracer.cpp | 1 + tests/src/core/testqgstracer.cpp | 1 + 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/python/core/qgstracer.sip b/python/core/qgstracer.sip index 12e1cd1c863d..a7dff3ad58c9 100644 --- a/python/core/qgstracer.sip +++ b/python/core/qgstracer.sip @@ -20,6 +20,11 @@ class QgsTracer : QObject //! Set layers used for tracing void setLayers( const QList& layers ); + //! Return true if reprojection to destination CRS is enabled + bool hasCrsTransformEnabled() const; + //! Set whether to do reprojection to destination CRS + void setCrsTransformEnabled( bool enabled ); + //! Get CRS used for tracing QgsCoordinateReferenceSystem destinationCrs() const; //! Set CRS used for tracing diff --git a/src/core/qgstracer.cpp b/src/core/qgstracer.cpp index 294e02853533..495c1fd32ba8 100644 --- a/src/core/qgstracer.cpp +++ b/src/core/qgstracer.cpp @@ -437,6 +437,7 @@ void extractLinework( const QgsGeometry* g, QgsMultiPolyline& mpl ) QgsTracer::QgsTracer() : mGraph( 0 ) + , mReprojectionEnabled( false ) , mMaxFeatureCount( 0 ) { } @@ -465,7 +466,7 @@ bool QgsTracer::initGraph() QgsFeatureRequest request; request.setSubsetOfAttributes( QgsAttributeList() ); if ( !mExtent.isEmpty() ) - request.setFilterRect( ct.transformBoundingBox( mExtent, QgsCoordinateTransform::ReverseTransform ) ); + request.setFilterRect( mReprojectionEnabled ? ct.transformBoundingBox( mExtent, QgsCoordinateTransform::ReverseTransform ) : mExtent ); QgsFeatureIterator fi = vl->getFeatures( request ); while ( fi.nextFeature( f ) ) @@ -473,7 +474,7 @@ bool QgsTracer::initGraph() if ( !f.constGeometry() ) continue; - if ( !ct.isShortCircuited() ) + if ( mReprojectionEnabled && !ct.isShortCircuited() ) { try { @@ -565,6 +566,15 @@ void QgsTracer::setLayers( const QList& layers ) invalidateGraph(); } +void QgsTracer::setCrsTransformEnabled( bool enabled ) +{ + if ( mReprojectionEnabled == enabled ) + return; + + mReprojectionEnabled = enabled; + invalidateGraph(); +} + void QgsTracer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs ) { if ( mCRS == crs ) diff --git a/src/core/qgstracer.h b/src/core/qgstracer.h index eace77ebd74c..cb99dd37910a 100644 --- a/src/core/qgstracer.h +++ b/src/core/qgstracer.h @@ -47,6 +47,11 @@ class CORE_EXPORT QgsTracer : public QObject //! Set layers used for tracing void setLayers( const QList& layers ); + //! Return true if reprojection to destination CRS is enabled + bool hasCrsTransformEnabled() const { return mReprojectionEnabled; } + //! Set whether to do reprojection to destination CRS + void setCrsTransformEnabled( bool enabled ); + //! Get CRS used for tracing QgsCoordinateReferenceSystem destinationCrs() const { return mCRS; } //! Set CRS used for tracing @@ -113,6 +118,8 @@ class CORE_EXPORT QgsTracer : public QObject QgsTracerGraph* mGraph; //! Input layers for the graph building QList mLayers; + //! Whether to reproject layer features to specified destination CRS + bool mReprojectionEnabled; //! Destination CRS in which graph is built and tracing done QgsCoordinateReferenceSystem mCRS; //! Extent for graph building (empty extent means no limit) diff --git a/src/gui/qgsmapcanvastracer.cpp b/src/gui/qgsmapcanvastracer.cpp index c0395c673037..5261e92a035c 100644 --- a/src/gui/qgsmapcanvastracer.cpp +++ b/src/gui/qgsmapcanvastracer.cpp @@ -84,6 +84,7 @@ void QgsMapCanvasTracer::reportError( QgsTracer::PathError err, bool addingVerte void QgsMapCanvasTracer::configure() { + setCrsTransformEnabled( mCanvas->mapSettings().hasCrsTransformEnabled() ); setDestinationCrs( mCanvas->mapSettings().destinationCrs() ); setExtent( mCanvas->extent() ); diff --git a/tests/src/core/testqgstracer.cpp b/tests/src/core/testqgstracer.cpp index 98c1cf6ae96b..16ef5eea4ab2 100644 --- a/tests/src/core/testqgstracer.cpp +++ b/tests/src/core/testqgstracer.cpp @@ -312,6 +312,7 @@ void TestQgsTracer::testReprojection() QgsTracer tracer; tracer.setLayers( QList() << vl ); tracer.setDestinationCrs( dstCrs ); + tracer.setCrsTransformEnabled( true ); tracer.init(); QgsPolyline points1 = tracer.findShortestPath( p1, p2 );