Skip to content

Commit

Permalink
Fix tracing still active when snapping is turned off
Browse files Browse the repository at this point in the history
Otherwise tracing is disabled in the snapping toolbar, yet still
active on the canvas.
  • Loading branch information
nyalldawson committed Jan 4, 2018
1 parent 63ba4fe commit 66aaaad
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
15 changes: 15 additions & 0 deletions python/gui/qgsmapcanvastracer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ); } );

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgssnappingwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgsmapcanvastracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -78,6 +91,7 @@ class GUI_EXPORT QgsMapCanvasTracer : public QgsTracer
QgsMessageBarItem *mLastMessage = nullptr;

QAction *mActionEnableTracing = nullptr;
QAction *mActionEnableSnapping = nullptr;

static QHash<QgsMapCanvas *, QgsMapCanvasTracer *> sTracers;
};
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}


Expand Down

0 comments on commit 66aaaad

Please sign in to comment.