Auto enable snapping when using the trim/extent tool

This commit is contained in:
Yoann Quenach de Quivillic 2024-12-19 23:48:24 +01:00 committed by Loïc Bartoletti
parent 61a27e0d71
commit 0b60e0f866
2 changed files with 24 additions and 0 deletions

View File

@ -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();
}

View File

@ -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