QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 #include "qgspointv2.h"
22 
23 #include <QCursor>
24 #include <QString>
25 #include <QObject>
26 
27 #ifdef HAVE_TOUCH
28 #include <QGestureEvent>
29 #endif
30 
31 class QgsMapLayer;
32 class QgsMapCanvas;
33 class QgsRenderContext;
34 class QKeyEvent;
35 class QMouseEvent;
36 class QWheelEvent;
37 class QgsPoint;
38 class QgsRectangle;
39 class QPoint;
40 class QAction;
41 class QAbstractButton;
42 
49 class GUI_EXPORT QgsMapTool : public QObject
50 {
51 
52  Q_OBJECT
53 
54  public:
55 
57  virtual ~QgsMapTool();
58 
60  virtual void canvasMoveEvent( QMouseEvent * e );
61 
63  virtual void canvasDoubleClickEvent( QMouseEvent * e );
64 
66  virtual void canvasPressEvent( QMouseEvent * e );
67 
69  virtual void canvasReleaseEvent( QMouseEvent * e );
70 
72  virtual void wheelEvent( QWheelEvent* e );
73 
75  virtual void keyPressEvent( QKeyEvent* e );
76 
78  virtual void keyReleaseEvent( QKeyEvent* e );
79 
80 #ifdef HAVE_TOUCH
81  virtual bool gestureEvent( QGestureEvent* e );
83 #endif
84 
87  Q_DECL_DEPRECATED virtual void renderComplete();
88 
89 
94  void setAction( QAction* action );
95 
97  QAction* action();
98 
101  void setButton( QAbstractButton* button );
102 
104  QAbstractButton* button();
105 
107  virtual void setCursor( QCursor cursor );
108 
112  virtual bool isTransient();
113 
117  virtual bool isEditTool();
118 
120  virtual void activate();
121 
123  virtual void deactivate();
124 
126  QgsMapCanvas* canvas();
127 
130  QString toolName() { return mToolName; }
131 
136  static double searchRadiusMM();
137 
141  static double searchRadiusMU( const QgsRenderContext& context );
142 
146  static double searchRadiusMU( QgsMapCanvas * canvas );
147 
148  signals:
150  void messageEmitted( QString message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
151 
153  void messageDiscarded();
154 
156  void activated();
157 
159  void deactivated();
160 
161  private slots:
163  void actionDestroyed();
164 
165  protected:
166 
168  QgsMapTool( QgsMapCanvas* canvas );
169 
171  QgsPoint toMapCoordinates( const QPoint& point );
172 
174  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QPoint& point );
175 
177  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
178 
180  QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
181 
183  QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point );
184 
186  QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
187 
189  QPoint toCanvasCoordinates( const QgsPoint& point );
190 
193 
196 
200 
204 
207 };
208 
209 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
QAbstractButton * mButton
optionally map tool can have pointer to a button which will be used to set that action as active ...
Definition: qgsmaptool.h:203
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:206
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:192
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:195
Point geometry type.
Definition: qgspointv2.h:29
QString toolName()
Emit map tool changed with the old tool.
Definition: qgsmaptool.h:130
A class to represent a point.
Definition: qgspoint.h:63
Abstract base class for all map tools.
Definition: qgsmaptool.h:49
Contains information about the context of a rendering operation.
QAction * mAction
optionally map tool can have pointer to action which will be used to set that action as active ...
Definition: qgsmaptool.h:199