@@ -775,26 +775,38 @@ void QgsAdvancedDigitizingDockWidget::setPoints( const QList<QgsPointXY> &points
775
775
776
776
bool QgsAdvancedDigitizingDockWidget::eventFilter ( QObject *obj, QEvent *event )
777
777
{
778
- // event for line edits
779
- if ( !cadEnabled () || ( event->type () != QEvent::ShortcutOverride && event->type () != QEvent::KeyPress ) )
778
+ if ( !cadEnabled () )
780
779
{
781
780
return QgsDockWidget::eventFilter ( obj, event );
782
781
}
783
- QKeyEvent *keyEvent = dynamic_cast <QKeyEvent *>( event );
784
- if ( !keyEvent )
782
+
783
+ // event for line edits and map canvas
784
+ // we have to catch both KeyPress events and ShortcutOverride events. This is because
785
+ // the Ctrl+D and Ctrl+A shortcuts for locking distance/angle clash with the global
786
+ // "remove layer" and "select all" shortcuts. Catching ShortcutOverride events allows
787
+ // us to intercept these keystrokes before they are caught by the global shortcuts
788
+ if ( event->type () == QEvent::ShortcutOverride || event->type () == QEvent::KeyPress )
785
789
{
786
- return QgsDockWidget::eventFilter ( obj, event );
790
+ if ( QKeyEvent *keyEvent = dynamic_cast <QKeyEvent *>( event ) )
791
+ {
792
+ return filterKeyPress ( keyEvent );
793
+ }
787
794
}
788
- return filterKeyPress ( keyEvent );
795
+ return QgsDockWidget::eventFilter ( obj, event );
789
796
}
790
797
791
798
bool QgsAdvancedDigitizingDockWidget::filterKeyPress ( QKeyEvent *e )
792
799
{
800
+ // we need to be careful here -- because this method is called on both KeyPress events AND
801
+ // ShortcutOverride events, we have to take care that we don't trigger the handling for BOTH
802
+ // these event types for a single key press. I.e. pressing "A" may first call trigger a
803
+ // ShortcutOverride event (sometimes, not always!) followed immediately by a KeyPress event.
793
804
QEvent::Type type = e->type ();
794
805
switch ( e->key () )
795
806
{
796
807
case Qt::Key_X:
797
808
{
809
+ // modifer+x ONLY caught for ShortcutOverride events...
798
810
if ( type == QEvent::ShortcutOverride && ( e->modifiers () == Qt::AltModifier || e->modifiers () == Qt::ControlModifier ) )
799
811
{
800
812
mXConstraint ->toggleLocked ();
@@ -810,6 +822,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
810
822
e->accept ();
811
823
}
812
824
}
825
+ // .. but "X" alone ONLY caught for KeyPress events (see comment at start of function)
813
826
else if ( type == QEvent::KeyPress )
814
827
{
815
828
mXLineEdit ->setFocus ();
@@ -820,6 +833,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
820
833
}
821
834
case Qt::Key_Y:
822
835
{
836
+ // modifer+y ONLY caught for ShortcutOverride events...
823
837
if ( type == QEvent::ShortcutOverride && ( e->modifiers () == Qt::AltModifier || e->modifiers () == Qt::ControlModifier ) )
824
838
{
825
839
mYConstraint ->toggleLocked ();
@@ -835,6 +849,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
835
849
e->accept ();
836
850
}
837
851
}
852
+ // .. but "y" alone ONLY caught for KeyPress events (see comment at start of function)
838
853
else if ( type == QEvent::KeyPress )
839
854
{
840
855
mYLineEdit ->setFocus ();
@@ -845,6 +860,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
845
860
}
846
861
case Qt::Key_A:
847
862
{
863
+ // modifer+a ONLY caught for ShortcutOverride events...
848
864
if ( type == QEvent::ShortcutOverride && ( e->modifiers () == Qt::AltModifier || e->modifiers () == Qt::ControlModifier ) )
849
865
{
850
866
if ( mCapacities .testFlag ( AbsoluteAngle ) )
@@ -863,6 +879,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
863
879
e->accept ();
864
880
}
865
881
}
882
+ // .. but "a" alone ONLY caught for KeyPress events (see comment at start of function)
866
883
else if ( type == QEvent::KeyPress )
867
884
{
868
885
mAngleLineEdit ->setFocus ();
@@ -873,6 +890,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
873
890
}
874
891
case Qt::Key_D:
875
892
{
893
+ // modifer+d ONLY caught for ShortcutOverride events...
876
894
if ( type == QEvent::ShortcutOverride && ( e->modifiers () == Qt::AltModifier || e->modifiers () == Qt::ControlModifier ) )
877
895
{
878
896
if ( mCapacities .testFlag ( RelativeCoordinates ) )
@@ -882,6 +900,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
882
900
e->accept ();
883
901
}
884
902
}
903
+ // .. but "d" alone ONLY caught for KeyPress events (see comment at start of function)
885
904
else if ( type == QEvent::KeyPress )
886
905
{
887
906
mDistanceLineEdit ->setFocus ();
0 commit comments