QGIS API Documentation  2.99.0-Master (d55fa22)
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 "qgis.h"
21 #include "qgsmessagebar.h"
22 #include "qgspointv2.h"
23 #include "qgsmapmouseevent.h"
24 
25 #include <QCursor>
26 #include <QString>
27 #include <QObject>
28 
29 #include <QGestureEvent>
30 #include "qgis_gui.h"
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 
74  virtual ~QgsMapTool();
75 
77  virtual void canvasMoveEvent( QgsMapMouseEvent *e );
78 
80  virtual void canvasDoubleClickEvent( QgsMapMouseEvent *e );
81 
83  virtual void canvasPressEvent( QgsMapMouseEvent *e );
84 
86  virtual void canvasReleaseEvent( QgsMapMouseEvent *e );
87 
89  virtual void wheelEvent( QWheelEvent *e );
90 
92  virtual void keyPressEvent( QKeyEvent *e );
93 
95  virtual void keyReleaseEvent( QKeyEvent *e );
96 
98  virtual bool gestureEvent( QGestureEvent *e );
99 
104  void setAction( QAction *action );
105 
107  QAction *action();
108 
111  void setButton( QAbstractButton *button );
112 
114  QAbstractButton *button();
115 
117  virtual void setCursor( const QCursor &cursor );
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( const 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 
169 
171  QgsPoint toMapCoordinates( QPoint point );
172 
174  QgsPoint toLayerCoordinates( const QgsMapLayer *layer, QPoint point );
175 
177  QgsPoint toLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point );
178 
180  QgsPoint toMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point );
181 
184  QgsPointV2 toMapCoordinates( const QgsMapLayer *layer, const QgsPointV2 &point ) SIP_PYNAME( toMapCoordinatesV2 );
185 
187  QgsRectangle toLayerCoordinates( const QgsMapLayer *layer, const QgsRectangle &rect );
188 
190  QPoint toCanvasCoordinates( const QgsPoint &point );
191 
193  QgsMapCanvas *mCanvas = nullptr;
194 
196  QCursor mCursor;
197 
200  QAction *mAction = nullptr;
201 
204  QAbstractButton *mButton = nullptr;
205 
207  QString mToolName;
208 
209 };
210 
211 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapTool::Flags )
212 
213 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for all map layer types.
Definition: qgsmaplayer.h:54
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
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:73
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:207
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:196
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:37
QString toolName()
Emit map tool changed with the old tool.
Definition: qgsmaptool.h:130
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:37
Abstract base class for all map tools.
Definition: qgsmaptool.h:50
Contains information about the context of a rendering operation.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:62