Fix tracing still active when snapping is turned off

Otherwise tracing is disabled in the snapping toolbar, yet still
active on the canvas.
This commit is contained in:
Nyall Dawson 2018-01-04 11:05:58 +10:00
parent 63ba4feab6
commit 66aaaadd67
5 changed files with 37 additions and 1 deletions

View File

@ -43,6 +43,21 @@ Access to action that user may use to toggle tracing on/off. May be null if no a
%Docstring
Assign "enable tracing" checkable action to the tracer.
The action is used to determine whether tracing is currently enabled by the user
%End
QAction *actionEnableSnapping() const;
%Docstring
Access to action that user may use to toggle snapping on/off. May be null if no action was associated.
.. versionadded:: 3.0
%End
void setActionEnableSnapping( QAction *action );
%Docstring
Assign "enable snapping" checkable action to the tracer.
The action is used to determine whether snapping is currently enabled by the user.
.. versionadded:: 3.0
%End
static QgsMapCanvasTracer *tracerForCanvas( QgsMapCanvas *canvas );

View File

@ -2415,6 +2415,7 @@ void QgisApp::createToolBars()
mTracer = new QgsMapCanvasTracer( mMapCanvas, messageBar() );
mTracer->setActionEnableTracing( mSnappingWidget->enableTracingAction() );
mTracer->setActionEnableSnapping( mSnappingWidget->enableSnappingAction() );
connect( mSnappingWidget->tracingOffsetSpinBox(), static_cast< void ( QgsDoubleSpinBox::* )( double ) >( &QgsDoubleSpinBox::valueChanged ),
this, [ = ]( double v ) { mTracer->setOffset( v ); } );

View File

@ -75,6 +75,11 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
*/
QAction *enableTracingAction() { return mEnableTracingAction; }
/**
* Returns the enable snapping action widget.
*/
QAction *enableSnappingAction() { return mEnabledAction; }
//! Returns spin box used to set offset for tracing
QgsDoubleSpinBox *tracingOffsetSpinBox() { return mTracingOffsetSpinBox; }

View File

@ -55,6 +55,19 @@ class GUI_EXPORT QgsMapCanvasTracer : public QgsTracer
*/
void setActionEnableTracing( QAction *action ) { mActionEnableTracing = action; }
/**
* Access to action that user may use to toggle snapping on/off. May be null if no action was associated.
* \since QGIS 3.0
*/
QAction *actionEnableSnapping() const { return mActionEnableSnapping; }
/**
* Assign "enable snapping" checkable action to the tracer.
* The action is used to determine whether snapping is currently enabled by the user.
* \since QGIS 3.0
*/
void setActionEnableSnapping( QAction *action ) { mActionEnableSnapping = action; }
/**
* Retrieve instance of this class associated with given canvas (if any).
* The class keeps a simple registry of tracers associated with map canvas
@ -78,6 +91,7 @@ class GUI_EXPORT QgsMapCanvasTracer : public QgsTracer
QgsMessageBarItem *mLastMessage = nullptr;
QAction *mActionEnableTracing = nullptr;
QAction *mActionEnableSnapping = nullptr;
static QHash<QgsMapCanvas *, QgsMapCanvasTracer *> sTracers;
};

View File

@ -129,7 +129,8 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
bool QgsMapToolCapture::tracingEnabled()
{
QgsMapCanvasTracer *tracer = QgsMapCanvasTracer::tracerForCanvas( mCanvas );
return tracer && tracer->actionEnableTracing() && tracer->actionEnableTracing()->isChecked();
return tracer && ( !tracer->actionEnableTracing() || tracer->actionEnableTracing()->isChecked() )
&& ( !tracer->actionEnableSnapping() || tracer->actionEnableSnapping()->isChecked() );
}