Skip to content

Commit 05506e3

Browse files
committedMar 31, 2013
Merge pull request #491 from borysiasty/master
[API] expose mouse wheel to map tools, use it for zoom only if no keyboard modifier pressed
2 parents 7d9f444 + daeafcc commit 05506e3

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed
 

‎python/gui/qgsmaptool.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class QgsMapTool : QObject
4747
//! Mouse release event for overriding. Default implementation does nothing.
4848
virtual void canvasReleaseEvent( QMouseEvent * e );
4949

50+
//! Mouse wheel event for overriding. Default implementation does nothing.
51+
//! Added in version 2.0
52+
virtual void wheelEvent( QWheelEvent * e );
53+
5054
//! Key event for overriding. Default implementation does nothing.
5155
virtual void keyPressEvent( QKeyEvent* e );
5256

‎src/gui/qgsmapcanvas.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ email : sherman at mrcc.com
3737
#include <QWheelEvent>
3838

3939
#include "qgis.h"
40+
#include "qgsapplication.h"
4041
#include "qgslogger.h"
4142
#include "qgsmapcanvas.h"
4243
#include "qgsmapcanvasmap.h"
@@ -1093,6 +1094,17 @@ void QgsMapCanvas::wheelEvent( QWheelEvent *e )
10931094
return;
10941095
}
10951096

1097+
if ( mMapTool )
1098+
{
1099+
mMapTool->wheelEvent( e );
1100+
}
1101+
1102+
if ( QgsApplication::keyboardModifiers() )
1103+
{
1104+
// leave the wheel for map tools if any modifier pressed
1105+
return;
1106+
}
1107+
10961108
switch ( mWheelAction )
10971109
{
10981110
case WheelZoom:

‎src/gui/qgsmaptool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ void QgsMapTool::canvasReleaseEvent( QMouseEvent *e )
131131
Q_UNUSED( e );
132132
}
133133

134+
void QgsMapTool::wheelEvent( QWheelEvent *e )
135+
{
136+
Q_UNUSED( e );
137+
}
138+
134139
void QgsMapTool::keyPressEvent( QKeyEvent *e )
135140
{
136141
Q_UNUSED( e );

‎src/gui/qgsmaptool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class QgsMapLayer;
3030
class QgsMapCanvas;
3131
class QKeyEvent;
3232
class QMouseEvent;
33+
class QWheelEvent;
3334
class QgsPoint;
3435
class QgsRectangle;
3536
class QPoint;
@@ -61,6 +62,10 @@ class GUI_EXPORT QgsMapTool : public QObject
6162
//! Mouse release event for overriding. Default implementation does nothing.
6263
virtual void canvasReleaseEvent( QMouseEvent * e );
6364

65+
//! Mouse wheel event for overriding. Default implementation does nothing.
66+
//! Added in version 2.0
67+
virtual void wheelEvent ( QWheelEvent* e );
68+
6469
//! Key event for overriding. Default implementation does nothing.
6570
virtual void keyPressEvent( QKeyEvent* e );
6671

0 commit comments

Comments
 (0)
Please sign in to comment.