Skip to content

Commit 66aaaad

Browse files
committedJan 4, 2018
Fix tracing still active when snapping is turned off
Otherwise tracing is disabled in the snapping toolbar, yet still active on the canvas.
1 parent 63ba4fe commit 66aaaad

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed
 

‎python/gui/qgsmapcanvastracer.sip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ Access to action that user may use to toggle tracing on/off. May be null if no a
4343
%Docstring
4444
Assign "enable tracing" checkable action to the tracer.
4545
The action is used to determine whether tracing is currently enabled by the user
46+
%End
47+
48+
QAction *actionEnableSnapping() const;
49+
%Docstring
50+
Access to action that user may use to toggle snapping on/off. May be null if no action was associated.
51+
52+
.. versionadded:: 3.0
53+
%End
54+
55+
void setActionEnableSnapping( QAction *action );
56+
%Docstring
57+
Assign "enable snapping" checkable action to the tracer.
58+
The action is used to determine whether snapping is currently enabled by the user.
59+
60+
.. versionadded:: 3.0
4661
%End
4762

4863
static QgsMapCanvasTracer *tracerForCanvas( QgsMapCanvas *canvas );

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,7 @@ void QgisApp::createToolBars()
24152415

24162416
mTracer = new QgsMapCanvasTracer( mMapCanvas, messageBar() );
24172417
mTracer->setActionEnableTracing( mSnappingWidget->enableTracingAction() );
2418+
mTracer->setActionEnableSnapping( mSnappingWidget->enableSnappingAction() );
24182419
connect( mSnappingWidget->tracingOffsetSpinBox(), static_cast< void ( QgsDoubleSpinBox::* )( double ) >( &QgsDoubleSpinBox::valueChanged ),
24192420
this, [ = ]( double v ) { mTracer->setOffset( v ); } );
24202421

‎src/app/qgssnappingwidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
7575
*/
7676
QAction *enableTracingAction() { return mEnableTracingAction; }
7777

78+
/**
79+
* Returns the enable snapping action widget.
80+
*/
81+
QAction *enableSnappingAction() { return mEnabledAction; }
82+
7883
//! Returns spin box used to set offset for tracing
7984
QgsDoubleSpinBox *tracingOffsetSpinBox() { return mTracingOffsetSpinBox; }
8085

‎src/gui/qgsmapcanvastracer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ class GUI_EXPORT QgsMapCanvasTracer : public QgsTracer
5555
*/
5656
void setActionEnableTracing( QAction *action ) { mActionEnableTracing = action; }
5757

58+
/**
59+
* Access to action that user may use to toggle snapping on/off. May be null if no action was associated.
60+
* \since QGIS 3.0
61+
*/
62+
QAction *actionEnableSnapping() const { return mActionEnableSnapping; }
63+
64+
/**
65+
* Assign "enable snapping" checkable action to the tracer.
66+
* The action is used to determine whether snapping is currently enabled by the user.
67+
* \since QGIS 3.0
68+
*/
69+
void setActionEnableSnapping( QAction *action ) { mActionEnableSnapping = action; }
70+
5871
/**
5972
* Retrieve instance of this class associated with given canvas (if any).
6073
* The class keeps a simple registry of tracers associated with map canvas
@@ -78,6 +91,7 @@ class GUI_EXPORT QgsMapCanvasTracer : public QgsTracer
7891
QgsMessageBarItem *mLastMessage = nullptr;
7992

8093
QAction *mActionEnableTracing = nullptr;
94+
QAction *mActionEnableSnapping = nullptr;
8195

8296
static QHash<QgsMapCanvas *, QgsMapCanvasTracer *> sTracers;
8397
};

‎src/gui/qgsmaptoolcapture.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
129129
bool QgsMapToolCapture::tracingEnabled()
130130
{
131131
QgsMapCanvasTracer *tracer = QgsMapCanvasTracer::tracerForCanvas( mCanvas );
132-
return tracer && tracer->actionEnableTracing() && tracer->actionEnableTracing()->isChecked();
132+
return tracer && ( !tracer->actionEnableTracing() || tracer->actionEnableTracing()->isChecked() )
133+
&& ( !tracer->actionEnableSnapping() || tracer->actionEnableSnapping()->isChecked() );
133134
}
134135

135136

0 commit comments

Comments
 (0)
Please sign in to comment.