Skip to content

Commit 506f028

Browse files
committed
Add some explanatory comments
1 parent 57ed9ed commit 506f028

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/gui/qgsadvanceddigitizingdockwidget.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -775,26 +775,38 @@ void QgsAdvancedDigitizingDockWidget::setPoints( const QList<QgsPointXY> &points
775775

776776
bool QgsAdvancedDigitizingDockWidget::eventFilter( QObject *obj, QEvent *event )
777777
{
778-
// event for line edits
779-
if ( !cadEnabled() || ( event->type() != QEvent::ShortcutOverride && event->type() != QEvent::KeyPress ) )
778+
if ( !cadEnabled() )
780779
{
781780
return QgsDockWidget::eventFilter( obj, event );
782781
}
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 )
785789
{
786-
return QgsDockWidget::eventFilter( obj, event );
790+
if ( QKeyEvent *keyEvent = dynamic_cast<QKeyEvent *>( event ) )
791+
{
792+
return filterKeyPress( keyEvent );
793+
}
787794
}
788-
return filterKeyPress( keyEvent );
795+
return QgsDockWidget::eventFilter( obj, event );
789796
}
790797

791798
bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
792799
{
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.
793804
QEvent::Type type = e->type();
794805
switch ( e->key() )
795806
{
796807
case Qt::Key_X:
797808
{
809+
// modifer+x ONLY caught for ShortcutOverride events...
798810
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
799811
{
800812
mXConstraint->toggleLocked();
@@ -810,6 +822,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
810822
e->accept();
811823
}
812824
}
825+
// .. but "X" alone ONLY caught for KeyPress events (see comment at start of function)
813826
else if ( type == QEvent::KeyPress )
814827
{
815828
mXLineEdit->setFocus();
@@ -820,6 +833,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
820833
}
821834
case Qt::Key_Y:
822835
{
836+
// modifer+y ONLY caught for ShortcutOverride events...
823837
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
824838
{
825839
mYConstraint->toggleLocked();
@@ -835,6 +849,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
835849
e->accept();
836850
}
837851
}
852+
// .. but "y" alone ONLY caught for KeyPress events (see comment at start of function)
838853
else if ( type == QEvent::KeyPress )
839854
{
840855
mYLineEdit->setFocus();
@@ -845,6 +860,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
845860
}
846861
case Qt::Key_A:
847862
{
863+
// modifer+a ONLY caught for ShortcutOverride events...
848864
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
849865
{
850866
if ( mCapacities.testFlag( AbsoluteAngle ) )
@@ -863,6 +879,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
863879
e->accept();
864880
}
865881
}
882+
// .. but "a" alone ONLY caught for KeyPress events (see comment at start of function)
866883
else if ( type == QEvent::KeyPress )
867884
{
868885
mAngleLineEdit->setFocus();
@@ -873,6 +890,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
873890
}
874891
case Qt::Key_D:
875892
{
893+
// modifer+d ONLY caught for ShortcutOverride events...
876894
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
877895
{
878896
if ( mCapacities.testFlag( RelativeCoordinates ) )
@@ -882,6 +900,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
882900
e->accept();
883901
}
884902
}
903+
// .. but "d" alone ONLY caught for KeyPress events (see comment at start of function)
885904
else if ( type == QEvent::KeyPress )
886905
{
887906
mDistanceLineEdit->setFocus();

0 commit comments

Comments
 (0)