mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
Auto enable snapping when using the trim/extent tool
This commit is contained in:
parent
61a27e0d71
commit
0b60e0f866
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user