QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsmaptool.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptool.h - base class for map canvas tools
3  ----------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPTOOL_H
17 #define QGSMAPTOOL_H
18 
19 #include "qgsconfig.h"
20 #include "qgsmessagebar.h"
21 
22 #include <QCursor>
23 #include <QString>
24 #include <QObject>
25 
26 #ifdef HAVE_TOUCH
27 #include <QGestureEvent>
28 #endif
29 
30 class QgsMapLayer;
31 class QgsMapCanvas;
32 class QgsRenderContext;
33 class QKeyEvent;
34 class QMouseEvent;
35 class QWheelEvent;
36 class QgsPoint;
37 class QgsRectangle;
38 class QPoint;
39 class QAction;
40 class QAbstractButton;
41 
48 class GUI_EXPORT QgsMapTool : public QObject
49 {
50 
51  Q_OBJECT
52 
53  public:
54 
56  virtual ~QgsMapTool();
57 
59  virtual void canvasMoveEvent( QMouseEvent * e );
60 
62  virtual void canvasDoubleClickEvent( QMouseEvent * e );
63 
65  virtual void canvasPressEvent( QMouseEvent * e );
66 
68  virtual void canvasReleaseEvent( QMouseEvent * e );
69 
71  virtual void wheelEvent( QWheelEvent* e );
72 
74  virtual void keyPressEvent( QKeyEvent* e );
75 
77  virtual void keyReleaseEvent( QKeyEvent* e );
78 
79 #ifdef HAVE_TOUCH
80  virtual bool gestureEvent( QGestureEvent* e );
82 #endif
83 
86  Q_DECL_DEPRECATED virtual void renderComplete();
87 
88 
93  void setAction( QAction* action );
94 
96  QAction* action();
97 
100  void setButton( QAbstractButton* button );
101 
103  QAbstractButton* button();
104 
106  virtual void setCursor( QCursor cursor );
107 
111  virtual bool isTransient();
112 
116  virtual bool isEditTool();
117 
119  virtual void activate();
120 
122  virtual void deactivate();
123 
125  QgsMapCanvas* canvas();
126 
129  QString toolName() { return mToolName; }
130 
135  static double searchRadiusMM();
136 
140  static double searchRadiusMU( const QgsRenderContext& context );
141 
145  static double searchRadiusMU( QgsMapCanvas * canvas );
146 
147  signals:
149  void messageEmitted( QString message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
150 
152  void messageDiscarded();
153 
155  void activated();
156 
158  void deactivated();
159 
160  private slots:
162  void actionDestroyed();
163 
164  protected:
165 
167  QgsMapTool( QgsMapCanvas* canvas );
168 
170  QgsPoint toMapCoordinates( const QPoint& point );
171 
173  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QPoint& point );
174 
176  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
177 
179  QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
180 
182  QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
183 
185  QPoint toCanvasCoordinates( const QgsPoint& point );
186 
189 
191  QCursor mCursor;
192 
195  QAction* mAction;
196 
199  QAbstractButton* mButton;
200 
202  QString mToolName;
203 };
204 
205 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
QAbstractButton * mButton
optionally map tool can have pointer to a button which will be used to set that action as active ...
Definition: qgsmaptool.h:199
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:202
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:188
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:191
MessageLevel
Definition: qgsmessagebar.h:47
Definition: qgsmessagebar.h:49
QString toolName()
Emit map tool changed with the old tool.
Definition: qgsmaptool.h:129
A class to represent a point geometry.
Definition: qgspoint.h:63
Abstract base class for all map tools.
Definition: qgsmaptool.h:48
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
QAction * mAction
optionally map tool can have pointer to action which will be used to set that action as active ...
Definition: qgsmaptool.h:195