QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
105  Q_DECL_DEPRECATED virtual void renderComplete();
106 
111  void setAction( QAction* action );
112 
114  QAction* action();
115 
118  void setButton( QAbstractButton* button );
119 
121  QAbstractButton* button();
122 
124  virtual void setCursor( const QCursor& cursor );
125 
131  Q_DECL_DEPRECATED virtual bool isTransient() const;
132 
137  Q_DECL_DEPRECATED virtual bool isEditTool() const;
138 
140  virtual void activate();
141 
143  virtual void deactivate();
144 
146  QgsMapCanvas* canvas();
147 
150  QString toolName() { return mToolName; }
151 
156  static double searchRadiusMM();
157 
161  static double searchRadiusMU( const QgsRenderContext& context );
162 
166  static double searchRadiusMU( QgsMapCanvas * canvas );
167 
168  signals:
170  void messageEmitted( const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
171 
173  void messageDiscarded();
174 
176  void activated();
177 
179  void deactivated();
180 
181  private slots:
183  void actionDestroyed();
184 
185  protected:
186 
188  QgsMapTool( QgsMapCanvas* canvas );
189 
191  QgsPoint toMapCoordinates( QPoint point );
192 
194  QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point );
195 
197  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
198 
200  QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
201 
204  QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point );
205 
207  QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
208 
210  QPoint toCanvasCoordinates( const QgsPoint& point );
211 
214 
217 
221 
225 
228 
229 };
230 
231 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapTool::Flags )
232 
233 #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:224
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:109
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:227
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:213
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:216
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:150
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:117
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:220