Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add some explanatory comments
  • Loading branch information
nyalldawson committed Jun 21, 2018
1 parent 57ed9ed commit 506f028
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/gui/qgsadvanceddigitizingdockwidget.cpp
Expand Up @@ -775,26 +775,38 @@ void QgsAdvancedDigitizingDockWidget::setPoints( const QList<QgsPointXY> &points

bool QgsAdvancedDigitizingDockWidget::eventFilter( QObject *obj, QEvent *event )
{
// event for line edits
if ( !cadEnabled() || ( event->type() != QEvent::ShortcutOverride && event->type() != QEvent::KeyPress ) )
if ( !cadEnabled() )
{
return QgsDockWidget::eventFilter( obj, event );
}
QKeyEvent *keyEvent = dynamic_cast<QKeyEvent *>( event );
if ( !keyEvent )

// event for line edits and map canvas
// we have to catch both KeyPress events and ShortcutOverride events. This is because
// the Ctrl+D and Ctrl+A shortcuts for locking distance/angle clash with the global
// "remove layer" and "select all" shortcuts. Catching ShortcutOverride events allows
// us to intercept these keystrokes before they are caught by the global shortcuts
if ( event->type() == QEvent::ShortcutOverride || event->type() == QEvent::KeyPress )
{
return QgsDockWidget::eventFilter( obj, event );
if ( QKeyEvent *keyEvent = dynamic_cast<QKeyEvent *>( event ) )
{
return filterKeyPress( keyEvent );
}
}
return filterKeyPress( keyEvent );
return QgsDockWidget::eventFilter( obj, event );
}

bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
{
// we need to be careful here -- because this method is called on both KeyPress events AND
// ShortcutOverride events, we have to take care that we don't trigger the handling for BOTH
// these event types for a single key press. I.e. pressing "A" may first call trigger a
// ShortcutOverride event (sometimes, not always!) followed immediately by a KeyPress event.
QEvent::Type type = e->type();
switch ( e->key() )
{
case Qt::Key_X:
{
// modifer+x ONLY caught for ShortcutOverride events...
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
{
mXConstraint->toggleLocked();
Expand All @@ -810,6 +822,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
e->accept();
}
}
// .. but "X" alone ONLY caught for KeyPress events (see comment at start of function)
else if ( type == QEvent::KeyPress )
{
mXLineEdit->setFocus();
Expand All @@ -820,6 +833,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
}
case Qt::Key_Y:
{
// modifer+y ONLY caught for ShortcutOverride events...
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
{
mYConstraint->toggleLocked();
Expand All @@ -835,6 +849,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
e->accept();
}
}
// .. but "y" alone ONLY caught for KeyPress events (see comment at start of function)
else if ( type == QEvent::KeyPress )
{
mYLineEdit->setFocus();
Expand All @@ -845,6 +860,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
}
case Qt::Key_A:
{
// modifer+a ONLY caught for ShortcutOverride events...
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
{
if ( mCapacities.testFlag( AbsoluteAngle ) )
Expand All @@ -863,6 +879,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
e->accept();
}
}
// .. but "a" alone ONLY caught for KeyPress events (see comment at start of function)
else if ( type == QEvent::KeyPress )
{
mAngleLineEdit->setFocus();
Expand All @@ -873,6 +890,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
}
case Qt::Key_D:
{
// modifer+d ONLY caught for ShortcutOverride events...
if ( type == QEvent::ShortcutOverride && ( e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ControlModifier ) )
{
if ( mCapacities.testFlag( RelativeCoordinates ) )
Expand All @@ -882,6 +900,7 @@ bool QgsAdvancedDigitizingDockWidget::filterKeyPress( QKeyEvent *e )
e->accept();
}
}
// .. but "d" alone ONLY caught for KeyPress events (see comment at start of function)
else if ( type == QEvent::KeyPress )
{
mDistanceLineEdit->setFocus();
Expand Down

0 comments on commit 506f028

Please sign in to comment.