Skip to content

Commit

Permalink
Auto enable snapping when using the trim/extent tool
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ authored and lbartoletti committed Dec 20, 2024
1 parent 61a27e0 commit 0b60e0f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/app/qgsmaptooltrimextendfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
7 changes: 7 additions & 0 deletions src/app/qgsmaptooltrimextendfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgsmaptooledit.h"
#include "qgis_app.h"
#include "qgsrubberband.h"
#include "qgssnappingconfig.h"

class APP_EXPORT QgsMapToolTrimExtendFeature : public QgsMapToolEdit
{
Expand All @@ -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;

Expand Down Expand Up @@ -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

0 comments on commit 0b60e0f

Please sign in to comment.