Skip to content
Permalink
Browse files

Merge pull request #491 from borysiasty/master

[API] expose mouse wheel to map tools, use it for zoom only if no keyboard modifier pressed
  • Loading branch information
NathanW2 committed Mar 31, 2013
2 parents 7d9f444 + daeafcc commit 05506e39abd2d068c25383cba935080e128f81db
Showing with 26 additions and 0 deletions.
  1. +4 −0 python/gui/qgsmaptool.sip
  2. +12 −0 src/gui/qgsmapcanvas.cpp
  3. +5 −0 src/gui/qgsmaptool.cpp
  4. +5 −0 src/gui/qgsmaptool.h
@@ -47,6 +47,10 @@ class QgsMapTool : QObject
//! Mouse release event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent( QMouseEvent * e );

//! Mouse wheel event for overriding. Default implementation does nothing.
//! Added in version 2.0
virtual void wheelEvent( QWheelEvent * e );

//! Key event for overriding. Default implementation does nothing.
virtual void keyPressEvent( QKeyEvent* e );

@@ -37,6 +37,7 @@ email : sherman at mrcc.com
#include <QWheelEvent>

#include "qgis.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmapcanvasmap.h"
@@ -1093,6 +1094,17 @@ void QgsMapCanvas::wheelEvent( QWheelEvent *e )
return;
}

if ( mMapTool )
{
mMapTool->wheelEvent( e );
}

if ( QgsApplication::keyboardModifiers() )
{
// leave the wheel for map tools if any modifier pressed
return;
}

switch ( mWheelAction )
{
case WheelZoom:
@@ -131,6 +131,11 @@ void QgsMapTool::canvasReleaseEvent( QMouseEvent *e )
Q_UNUSED( e );
}

void QgsMapTool::wheelEvent( QWheelEvent *e )
{
Q_UNUSED( e );
}

void QgsMapTool::keyPressEvent( QKeyEvent *e )
{
Q_UNUSED( e );
@@ -30,6 +30,7 @@ class QgsMapLayer;
class QgsMapCanvas;
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
class QgsPoint;
class QgsRectangle;
class QPoint;
@@ -61,6 +62,10 @@ class GUI_EXPORT QgsMapTool : public QObject
//! Mouse release event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent( QMouseEvent * e );

//! Mouse wheel event for overriding. Default implementation does nothing.
//! Added in version 2.0
virtual void wheelEvent ( QWheelEvent* e );

//! Key event for overriding. Default implementation does nothing.
virtual void keyPressEvent( QKeyEvent* e );

0 comments on commit 05506e3

Please sign in to comment.
You can’t perform that action at this time.