Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Give map tools a chance to override the cursor keys
  • Loading branch information
nyalldawson committed Sep 9, 2021
1 parent c6e81ab commit 697ddcd
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -1786,9 +1786,20 @@ void QgsMapCanvas::keyPressEvent( QKeyEvent *e )
return;
}

// Don't want to interfer with mouse events
if ( ! mCanvasProperties->mouseButtonDown )
{
// Don't want to interfer with mouse events
// this is backwards, but we can't change now without breaking api because
// forever QgsMapTools have had to explicitly mark events as ignored in order to
// indicate that they've consumed the event and that the default behaviour should not
// be applied..!
e->accept();
if ( mMapTool )
{
mMapTool->keyPressEvent( e );
if ( !e->isAccepted() ) // map tool consumed event
return;
}

QgsRectangle currentExtent = mapSettings().visibleExtent();
double dx = std::fabs( currentExtent.width() / 4 );
Expand Down Expand Up @@ -1820,8 +1831,6 @@ void QgsMapCanvas::keyPressEvent( QKeyEvent *e )
refresh();
break;



case Qt::Key_Space:
QgsDebugMsgLevel( QStringLiteral( "Pressing pan selector" ), 2 );

Expand Down Expand Up @@ -1858,19 +1867,16 @@ void QgsMapCanvas::keyPressEvent( QKeyEvent *e )

default:
// Pass it on
if ( mMapTool )
if ( !mMapTool )
{
mMapTool->keyPressEvent( e );
e->ignore();
QgsDebugMsgLevel( "Ignoring key: " + QString::number( e->key() ), 2 );
}
else e->ignore();

QgsDebugMsgLevel( "Ignoring key: " + QString::number( e->key() ), 2 );
}
}

emit keyPressed( e );

} //keyPressEvent()
}

void QgsMapCanvas::keyReleaseEvent( QKeyEvent *e )
{
Expand Down

0 comments on commit 697ddcd

Please sign in to comment.