Skip to content

Commit

Permalink
Adjust snapping options on layer change
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 26, 2018
1 parent 6ae03af commit 5c814cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/gui/qgsmaptooladvanceddigitizing.cpp
Expand Up @@ -25,6 +25,7 @@ QgsMapToolAdvancedDigitizing::QgsMapToolAdvancedDigitizing( QgsMapCanvas *canvas
: QgsMapToolEdit( canvas )
, mCadDockWidget( cadDockWidget )
{
connect( canvas, &QgsMapCanvas::currentLayerChanged, this, &QgsMapToolAdvancedDigitizing::onCurrentLayerChanged );
}

void QgsMapToolAdvancedDigitizing::canvasPressEvent( QgsMapMouseEvent *e )
Expand Down Expand Up @@ -143,6 +144,20 @@ void QgsMapToolAdvancedDigitizing::cadPointChanged( const QgsPointXY &point )
qApp->postEvent( mCanvas->viewport(), ev ); // event queue will delete the event when processed
}

void QgsMapToolAdvancedDigitizing::onCurrentLayerChanged()
{
QgsVectorLayer *layer = currentVectorLayer();
if ( mSnapToGridCanvasItem && layer && mSnapToGridEnabled )
{
mSnapToGridCanvasItem->setPrecision( layer->geometryFixes()->geometryPrecision() );
mSnapToGridCanvasItem->setCrs( layer->crs() );
mSnapToGridCanvasItem->setEnabled( true );
}

if ( !layer )
mSnapToGridCanvasItem->setEnabled( false );
}

bool QgsMapToolAdvancedDigitizing::snapToGridEnabled() const
{
return mSnapToGridEnabled;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmaptooladvanceddigitizing.h
Expand Up @@ -167,6 +167,8 @@ class GUI_EXPORT QgsMapToolAdvancedDigitizing : public QgsMapToolEdit
*/
void cadPointChanged( const QgsPointXY &point );

void onCurrentLayerChanged();

private:
QgsAdvancedDigitizingDockWidget *mCadDockWidget = nullptr;

Expand Down

0 comments on commit 5c814cf

Please sign in to comment.