QGIS API Documentation  2.14.0-Essen
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 #include "qgsmapmouseevent.h"
23 
24 #include <QCursor>
25 #include <QString>
26 #include <QObject>
27 
28 #ifdef HAVE_TOUCH
29 #include <QGestureEvent>
30 #endif
31 
32 class QgsMapLayer;
33 class QgsMapCanvas;
34 class QgsRenderContext;
35 class QKeyEvent;
36 class QMouseEvent;
37 class QWheelEvent;
38 class QgsPoint;
39 class QgsRectangle;
40 class QPoint;
41 class QAction;
42 class QAbstractButton;
43 
50 class GUI_EXPORT QgsMapTool : public QObject
51 {
52 
53  Q_OBJECT
54 
55  public:
56 
58  virtual ~QgsMapTool();
59 
61  virtual void canvasMoveEvent( QgsMapMouseEvent* e );
62 
64  virtual void canvasDoubleClickEvent( QgsMapMouseEvent* e );
65 
67  virtual void canvasPressEvent( QgsMapMouseEvent* e );
68 
70  virtual void canvasReleaseEvent( QgsMapMouseEvent* e );
71 
73  virtual void wheelEvent( QWheelEvent* e );
74 
76  virtual void keyPressEvent( QKeyEvent* e );
77 
79  virtual void keyReleaseEvent( QKeyEvent* e );
80 
81 #ifdef HAVE_TOUCH
82  virtual bool gestureEvent( QGestureEvent* e );
84 #endif
85 
88  Q_DECL_DEPRECATED virtual void renderComplete();
89 
90 
95  void setAction( QAction* action );
96 
98  QAction* action();
99 
102  void setButton( QAbstractButton* button );
103 
105  QAbstractButton* button();
106 
108  virtual void setCursor( const QCursor& cursor );
109 
113  virtual bool isTransient();
114 
118  virtual bool isEditTool();
119 
121  virtual void activate();
122 
124  virtual void deactivate();
125 
127  QgsMapCanvas* canvas();
128 
131  QString toolName() { return mToolName; }
132 
137  static double searchRadiusMM();
138 
142  static double searchRadiusMU( const QgsRenderContext& context );
143 
147  static double searchRadiusMU( QgsMapCanvas * canvas );
148 
149  signals:
151  void messageEmitted( const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
152 
154  void messageDiscarded();
155 
157  void activated();
158 
160  void deactivated();
161 
162  private slots:
164  void actionDestroyed();
165 
166  protected:
167 
169  QgsMapTool( QgsMapCanvas* canvas );
170 
172  QgsPoint toMapCoordinates( QPoint point );
173 
175  QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point );
176 
178  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
179 
181  QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
182 
185  QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point );
186 
188  QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
189 
191  QPoint toCanvasCoordinates( const QgsPoint& point );
192 
195 
198 
202 
206 
209 };
210 
211 #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:205
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
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:208
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:194
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:197
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
QString toolName()
Emit map tool changed with the old tool.
Definition: qgsmaptool.h:131
A class to represent a point.
Definition: qgspoint.h:65
Abstract base class for all map tools.
Definition: qgsmaptool.h:50
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:201