Add flag for common angle/feature snapping priority

The flag allows to ignore common angle snapping when
there is a feature snapping match

Fixes #52333
This commit is contained in:
Alessandro Pasotti 2023-04-11 16:00:47 +02:00 committed by Nyall Dawson
parent caadb7d046
commit b14482fe5e
5 changed files with 31 additions and 2 deletions

View File

@ -102,6 +102,8 @@ Defines constraints for the :py:func:`QgsCadUtils.alignMapPoint()` method.
QgsCadUtils::AlignMapPointConstraint lineExtensionConstraint;
QgsCadUtils::AlignMapPointConstraint xyVertexConstraint;
bool snappingToFeaturesOverridesCommonAngle;
QList< QgsPoint > cadPoints() const;
%Docstring

View File

@ -162,7 +162,10 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o
// *****************************
// ---- Common Angle constraint
if ( numberOfHardLock < 2 && !ctx.angleConstraint.locked && ctx.cadPoints().count() >= 2 && ctx.commonAngleConstraint.locked && ctx.commonAngleConstraint.value != 0 )
if ( numberOfHardLock < 2 && !ctx.angleConstraint.locked && ctx.cadPoints().count() >= 2 && ctx.commonAngleConstraint.locked && ctx.commonAngleConstraint.value != 0
// Skip common angle constraint if the snapping to features has priority
&& ( ! snapMatch.isValid() || ! ctx.snappingToFeaturesOverridesCommonAngle )
)
{
const double commonAngle = ctx.commonAngleConstraint.value * M_PI / 180;
// see if soft common angle constraint should be performed

View File

@ -134,6 +134,12 @@ class CORE_EXPORT QgsCadUtils
QgsCadUtils::AlignMapPointConstraint lineExtensionConstraint;
QgsCadUtils::AlignMapPointConstraint xyVertexConstraint;
/**
* Flag to set snapping to features priority over common angle.
* \since QGIS 3.32
*/
bool snappingToFeaturesOverridesCommonAngle = false;
/**
* Dumps the context's properties, for debugging.
* \note Not available in Python bindings.

View File

@ -36,7 +36,6 @@
#include "qgsmapmouseevent.h"
#include "qgsmeshlayer.h"
#include "qgsunittypes.h"
#include "qgslocaldefaultsettings.h"
#include <QActionGroup>
@ -144,6 +143,21 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas *
{
commonAngles << QPair<double, QString>( *it, formatCommonAngleSnapping( *it ) );
}
{
QAction *action = new QAction( tr( "Snapping to features has priority over common angles" ), mCommonAngleActionsMenu );
action->setCheckable( true );
mCommonAngleActionsMenu->addAction( action );
connect( action, &QAction::changed, this, [ = ]
{
mSnappingToFeaturesOverridesCommonAngle = action->isChecked();
QgsSettings().setValue( QStringLiteral( "/Cad/SnappingToFeaturesOverridesCommonAngle" ), action->isChecked() );
} );
action->setChecked( QgsSettings().value( QStringLiteral( "/Cad/SnappingToFeaturesOverridesCommonAngle" ), false ).toBool() );
}
mCommonAngleActionsMenu->addSeparator();
for ( QList< QPair<double, QString > >::const_iterator it = commonAngles.constBegin(); it != commonAngles.constEnd(); ++it )
{
QAction *action = new QAction( it->second, mCommonAngleActionsMenu );
@ -1181,6 +1195,7 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
context.mConstraint = _constraint( mMConstraint.get() );
context.distanceConstraint = _constraint( mDistanceConstraint.get() );
context.angleConstraint = _constraint( mAngleConstraint.get() );
context.snappingToFeaturesOverridesCommonAngle = mSnappingToFeaturesOverridesCommonAngle;
context.lineExtensionConstraint = _constraint( mLineExtensionConstraint.get() );
context.xyVertexConstraint = _constraint( mXyVertexConstraint.get() );

View File

@ -1051,6 +1051,9 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
Qgis::BetweenLineConstraint mBetweenLineConstraint;
double mCommonAngleConstraint; // if 0: do not snap to common angles
//! Flag that controls whether snapping to features has priority over common angle
bool mSnappingToFeaturesOverridesCommonAngle = false;
// point list and current snap point / segment
QList<QgsPoint> mCadPointList;
QList<QgsPointXY> mSnappedSegment;