Skip to content
Permalink
Browse files

Highlight grid for map tools that snap to grid

  • Loading branch information
m-kuhn committed Aug 25, 2018
1 parent 6c467fb commit b68ce3780e1693db190e2cccd1a0650c225eaf18
Showing with 15 additions and 1 deletion.
  1. +13 −1 src/gui/qgsmaptooladvanceddigitizing.cpp
  2. +2 −0 src/gui/qgsmaptooladvanceddigitizing.h
@@ -19,6 +19,7 @@
#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsvectorlayer.h"
#include "qgsgeometryfixes.h"
#include "qgssnaptogridcanvasitem.h"

QgsMapToolAdvancedDigitizing::QgsMapToolAdvancedDigitizing( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget )
: QgsMapToolEdit( canvas )
@@ -109,6 +110,7 @@ void QgsMapToolAdvancedDigitizing::canvasMoveEvent( QgsMapMouseEvent *e )
if ( mSnapToGridEnabled && layer )
{
e->snapToGrid( layer->geometryFixes()->geometryPrecision(), layer->crs() );
mSnapToGridCanvasItem->setPoint( e->mapPoint() );
}

cadCanvasMoveEvent( e );
@@ -119,13 +121,19 @@ void QgsMapToolAdvancedDigitizing::activate()
QgsMapToolEdit::activate();
connect( mCadDockWidget, &QgsAdvancedDigitizingDockWidget::pointChanged, this, &QgsMapToolAdvancedDigitizing::cadPointChanged );
mCadDockWidget->enable();
mSnapToGridCanvasItem = new QgsSnapToGridCanvasItem( mCanvas );
mSnapToGridCanvasItem->setCrs( currentVectorLayer()->crs() );
mSnapToGridCanvasItem->setPrecision( currentVectorLayer()->geometryFixes()->geometryPrecision() );
mSnapToGridCanvasItem->setEnabled( mSnapToGridEnabled );
}

void QgsMapToolAdvancedDigitizing::deactivate()
{
QgsMapToolEdit::deactivate();
disconnect( mCadDockWidget, &QgsAdvancedDigitizingDockWidget::pointChanged, this, &QgsMapToolAdvancedDigitizing::cadPointChanged );
mCadDockWidget->disable();
delete mSnapToGridCanvasItem;
mSnapToGridCanvasItem = nullptr;
}

void QgsMapToolAdvancedDigitizing::cadPointChanged( const QgsPointXY &point )
@@ -142,5 +150,9 @@ bool QgsMapToolAdvancedDigitizing::snapToGridEnabled() const

void QgsMapToolAdvancedDigitizing::setSnapToGridEnabled( bool snapToGridEnabled )
{
mSnapToGridEnabled = snapToGridEnabled;
if ( mSnapToGridCanvasItem )
{
mSnapToGridEnabled = snapToGridEnabled;
mSnapToGridCanvasItem->setEnabled( snapToGridEnabled );
}
}
@@ -22,6 +22,7 @@

class QgsMapMouseEvent;
class QgsAdvancedDigitizingDockWidget;
class QgsSnapToGridCanvasItem;

/**
* \ingroup gui
@@ -175,6 +176,7 @@ class GUI_EXPORT QgsMapToolAdvancedDigitizing : public QgsMapToolEdit
bool mAutoSnapEnabled = true;
//! Whether to snap to grid before passing coordinates to cadCanvas*Event()
bool mSnapToGridEnabled = true;
QgsSnapToGridCanvasItem *mSnapToGridCanvasItem = nullptr;
};

#endif // QGSMAPTOOLADVANCEDDIGITIZE_H

0 comments on commit b68ce37

Please sign in to comment.
You can’t perform that action at this time.