QGIS API Documentation  2.99.0-Master (9ed189e)
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 #include <QGestureEvent>
29 #include "qgis_gui.h"
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 
58  enum Flag
59  {
60  Transient = 1 << 1,
63  EditTool = 1 << 2,
64  AllowZoomRect = 1 << 3,
65  };
66  Q_DECLARE_FLAGS( Flags, Flag )
67 
68 
71  virtual Flags flags() const { return Flags(); }
72 
73  virtual ~QgsMapTool();
74 
76  virtual void canvasMoveEvent( QgsMapMouseEvent* e );
77 
79  virtual void canvasDoubleClickEvent( QgsMapMouseEvent* e );
80 
82  virtual void canvasPressEvent( QgsMapMouseEvent* e );
83 
85  virtual void canvasReleaseEvent( QgsMapMouseEvent* e );
86 
88  virtual void wheelEvent( QWheelEvent* e );
89 
91  virtual void keyPressEvent( QKeyEvent* e );
92 
94  virtual void keyReleaseEvent( QKeyEvent* e );
95 
97  virtual bool gestureEvent( QGestureEvent* e );
98 
103  void setAction( QAction* action );
104 
106  QAction* action();
107 
110  void setButton( QAbstractButton* button );
111 
113  QAbstractButton* button();
114 
116  virtual void setCursor( const QCursor& cursor );
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( const 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( QPoint point );
171 
173  QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point );
174 
176  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
177 
179  QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
180 
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 
192  QgsMapCanvas* mCanvas = nullptr;
193 
195  QCursor mCursor;
196 
199  QAction* mAction = nullptr;
200 
203  QAbstractButton* mButton = nullptr;
204 
206  QString mToolName;
207 
208 };
209 
210 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapTool::Flags )
211 
212 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for all map layer types.
Definition: qgsmaplayer.h:52
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:72
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:206
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:195
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:36
QString toolName()
Emit map tool changed with the old tool.
Definition: qgsmaptool.h:129
Flag
Enumeration of flags that adjust the way the map tool operates.
Definition: qgsmaptool.h:58
A class to represent a point.
Definition: qgspoint.h:143
Abstract base class for all map tools.
Definition: qgsmaptool.h:49
Contains information about the context of a rendering operation.