QGIS API Documentation  2.99.0-Master (5753576)
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 #include "qgis_gui.h"
31 #endif
32 
33 class QgsMapLayer;
34 class QgsMapCanvas;
35 class QgsRenderContext;
36 class QKeyEvent;
37 class QMouseEvent;
38 class QWheelEvent;
39 class QgsPoint;
40 class QgsRectangle;
41 class QPoint;
42 class QAction;
43 class QAbstractButton;
44 
51 class GUI_EXPORT QgsMapTool : public QObject
52 {
53 
54  Q_OBJECT
55 
56  public:
57 
60  enum Flag
61  {
62  Transient = 1 << 1,
65  EditTool = 1 << 2,
66  AllowZoomRect = 1 << 3,
67  };
68  Q_DECLARE_FLAGS( Flags, Flag )
69 
70 
73  virtual Flags flags() const { return Flags(); }
74 
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:36
Base class for all map layer types.
Definition: qgsmaplayer.h:50
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:74
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:36
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:60
A class to represent a point.
Definition: qgspoint.h:143
Abstract base class for all map tools.
Definition: qgsmaptool.h:51
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