Skip to content
Permalink
Browse files

Allow disabling snapping on maptools

  • Loading branch information
m-kuhn committed Aug 23, 2018
1 parent 93eef9f commit aae655913082e04475a98ac046bf9b4e664bf764
@@ -149,6 +149,20 @@ canvasMoveEvent is triggered and it's not hidden by the cad's
construction mode.

:param e: Mouse events prepared by the cad system
%End

bool snapToGridEnabled() const;
%Docstring
Enables or disables snap to grid of mouse events.

.. versionadded:: 3.4
%End

void setSnapToGridEnabled( bool snapToGridEnabled );
%Docstring
Enables or disables snap to grid of mouse events.

.. versionadded:: 3.4
%End

};
@@ -40,7 +40,7 @@ void QgsMapToolAdvancedDigitizing::canvasPressEvent( QgsMapMouseEvent *e )
}

QgsVectorLayer *layer = currentVectorLayer();
if ( layer )
if ( mSnapToGridEnabled && layer )
{
e->snapToGrid( layer->geometryOptions().geometryPrecision, layer->crs() );
}
@@ -80,7 +80,7 @@ void QgsMapToolAdvancedDigitizing::canvasReleaseEvent( QgsMapMouseEvent *e )
}

QgsVectorLayer *layer = currentVectorLayer();
if ( layer )
if ( mSnapToGridEnabled && layer )
{
e->snapToGrid( layer->geometryOptions().geometryPrecision, layer->crs() );
}
@@ -105,7 +105,7 @@ void QgsMapToolAdvancedDigitizing::canvasMoveEvent( QgsMapMouseEvent *e )
}

QgsVectorLayer *layer = currentVectorLayer();
if ( layer )
if ( mSnapToGridEnabled && layer )
{
e->snapToGrid( layer->geometryOptions().geometryPrecision, layer->crs() );
}
@@ -133,3 +133,13 @@ void QgsMapToolAdvancedDigitizing::cadPointChanged( const QgsPointXY &point )
QMouseEvent *ev = new QMouseEvent( QEvent::MouseMove, mCanvas->mouseLastXY(), Qt::NoButton, Qt::NoButton, Qt::NoModifier );
qApp->postEvent( mCanvas->viewport(), ev ); // event queue will delete the event when processed
}

bool QgsMapToolAdvancedDigitizing::snapToGridEnabled() const
{
return mSnapToGridEnabled;
}

void QgsMapToolAdvancedDigitizing::setSnapToGridEnabled( bool snapToGridEnabled )
{
mSnapToGridEnabled = snapToGridEnabled;
}
@@ -140,6 +140,20 @@ class GUI_EXPORT QgsMapToolAdvancedDigitizing : public QgsMapToolEdit
*/
virtual void cadCanvasMoveEvent( QgsMapMouseEvent *e ) { Q_UNUSED( e ) }

/**
* Enables or disables snap to grid of mouse events.
*
* \since QGIS 3.4
*/
bool snapToGridEnabled() const;

/**
* Enables or disables snap to grid of mouse events.
*
* \since QGIS 3.4
*/
void setSnapToGridEnabled( bool snapToGridEnabled );

private slots:

/**
@@ -159,6 +173,8 @@ class GUI_EXPORT QgsMapToolAdvancedDigitizing : public QgsMapToolEdit
bool mAdvancedDigitizingAllowed = true;
//! Whether to snap mouse cursor to map before passing coordinates to cadCanvas*Event()
bool mAutoSnapEnabled = true;
//! Whether to snap to grid before passing coordinates to cadCanvas*Event()
bool mSnapToGridEnabled = true;
};

#endif // QGSMAPTOOLADVANCEDDIGITIZE_H

0 comments on commit aae6559

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