diff --git a/src/app/qgsmaptooltrimextendfeature.cpp b/src/app/qgsmaptooltrimextendfeature.cpp index e1253ba7f239..339b2e6d8b78 100644 --- a/src/app/qgsmaptooltrimextendfeature.cpp +++ b/src/app/qgsmaptooltrimextendfeature.cpp @@ -387,8 +387,25 @@ void QgsMapToolTrimExtendFeature::reset() mVlayer = nullptr; mLimitLayer = nullptr; } +void QgsMapToolTrimExtendFeature::activate() +{ + QgsMapTool::activate(); + + // Save the original snapping configuration + mOriginalSnappingConfig = mCanvas->snappingUtils()->config(); + + // Enable Snapping & Snapping on Segment + QgsSnappingConfig snappingConfig = mOriginalSnappingConfig; + snappingConfig.setEnabled( true ); + Qgis::SnappingTypes flags = snappingConfig.typeFlag(); + flags |= Qgis::SnappingType::Segment; + snappingConfig.setTypeFlag( flags ); + mCanvas->snappingUtils()->setConfig( snappingConfig ); +} void QgsMapToolTrimExtendFeature::deactivate() { reset(); + // Restore the original snapping configuration + mCanvas->snappingUtils()->setConfig( mOriginalSnappingConfig ); QgsMapTool::deactivate(); } diff --git a/src/app/qgsmaptooltrimextendfeature.h b/src/app/qgsmaptooltrimextendfeature.h index 4f2542aabda4..45a9992b1ea6 100644 --- a/src/app/qgsmaptooltrimextendfeature.h +++ b/src/app/qgsmaptooltrimextendfeature.h @@ -19,6 +19,7 @@ #include "qgsmaptooledit.h" #include "qgis_app.h" #include "qgsrubberband.h" +#include "qgssnappingconfig.h" class APP_EXPORT QgsMapToolTrimExtendFeature : public QgsMapToolEdit { @@ -35,6 +36,9 @@ class APP_EXPORT QgsMapToolTrimExtendFeature : public QgsMapToolEdit void keyPressEvent( QKeyEvent *e ) override; + //! called when map tool is being activated + void activate() override; + //! called when map tool is being deactivated void deactivate() override; @@ -81,6 +85,9 @@ class APP_EXPORT QgsMapToolTrimExtendFeature : public QgsMapToolEdit }; //! The first step (0): choose the limit. The second step (1): choose the segment to trim/extend Step mStep = StepLimit; + + //! Snapping config that will be restored on deactivation + QgsSnappingConfig mOriginalSnappingConfig; }; #endif // QGSMAPTOOLTRIMEXTENDFEATURE_H