QGIS API Documentation  2.99.0-Master (e077efd)
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 
59  enum Flag
60  {
61  Transient = 1 << 1,
64  EditTool = 1 << 2,
65  AllowZoomRect = 1 << 3,
66  };
67  Q_DECLARE_FLAGS( Flags, Flag )
68 
69 
72  virtual Flags flags() const { return Flags(); }
73 
75  virtual ~QgsMapTool();
76 
78  virtual void canvasMoveEvent( QgsMapMouseEvent* e );
79 
81  virtual void canvasDoubleClickEvent( QgsMapMouseEvent* e );
82 
84  virtual void canvasPressEvent( QgsMapMouseEvent* e );
85 
87  virtual void canvasReleaseEvent( QgsMapMouseEvent* e );
88 
90  virtual void wheelEvent( QWheelEvent* e );
91 
93  virtual void keyPressEvent( QKeyEvent* e );
94 
96  virtual void keyReleaseEvent( QKeyEvent* e );
97 
98 #ifdef HAVE_TOUCH
99  virtual bool gestureEvent( QGestureEvent* e );
101 #endif
102 
107  void setAction( QAction* action );
108 
110  QAction* action();
111 
114  void setButton( QAbstractButton* button );
115 
117  QAbstractButton* button();
118 
120  virtual void setCursor( const QCursor& cursor );
121 
123  virtual void activate();
124 
126  virtual void deactivate();
127 
129  QgsMapCanvas* canvas();
130 
133  QString toolName() { return mToolName; }
134 
139  static double searchRadiusMM();
140 
144  static double searchRadiusMU( const QgsRenderContext& context );
145 
149  static double searchRadiusMU( QgsMapCanvas * canvas );
150 
151  signals:
153  void messageEmitted( const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
154 
156  void messageDiscarded();
157 
159  void activated();
160 
162  void deactivated();
163 
164  private slots:
166  void actionDestroyed();
167 
168  protected:
169 
171  QgsMapTool( QgsMapCanvas* canvas );
172 
174  QgsPoint toMapCoordinates( QPoint point );
175 
177  QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point );
178 
180  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
181 
183  QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
184 
187  QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point );
188 
190  QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
191 
193  QPoint toCanvasCoordinates( const QgsPoint& point );
194 
197 
199  QCursor mCursor;
200 
203  QAction* mAction;
204 
207  QAbstractButton* mButton;
208 
210  QString mToolName;
211 
212 };
213 
214 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapTool::Flags )
215 
216 #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:207
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:106
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:210
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:196
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:199
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:35
QString toolName()
Emit map tool changed with the old tool.
Definition: qgsmaptool.h:133
Flag
Enumeration of flags that adjust the way the map tool operates.
Definition: qgsmaptool.h:59
A class to represent a point.
Definition: qgspoint.h:111
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:203