QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
22 #include <QCursor>
23 #include <QString>
24 #include <QObject>
25 
26 #ifdef HAVE_TOUCH
27 #include <QGestureEvent>
28 #endif
29 
30 class QgsMapLayer;
31 class QgsMapCanvas;
32 class QgsRenderContext;
33 class QKeyEvent;
34 class QMouseEvent;
35 class QWheelEvent;
36 class QgsPoint;
37 class QgsRectangle;
38 class QPoint;
39 class QAction;
40 class QAbstractButton;
41 
48 class GUI_EXPORT QgsMapTool : public QObject
49 {
50 
51  Q_OBJECT
52 
53  public:
54 
56  virtual ~QgsMapTool();
57 
59  virtual void canvasMoveEvent( QMouseEvent * e );
60 
62  virtual void canvasDoubleClickEvent( QMouseEvent * e );
63 
65  virtual void canvasPressEvent( QMouseEvent * e );
66 
68  virtual void canvasReleaseEvent( QMouseEvent * e );
69 
72  virtual void wheelEvent( QWheelEvent* e );
73 
75  virtual void keyPressEvent( QKeyEvent* e );
76 
79  virtual void keyReleaseEvent( QKeyEvent* e );
80 
81 #ifdef HAVE_TOUCH
82  virtual bool gestureEvent( QGestureEvent* e );
84 #endif
85 
88  Q_DECL_DEPRECATED virtual void renderComplete();
89 
90 
95  void setAction( QAction* action );
96 
98  QAction* action();
99 
102  void setButton( QAbstractButton* button );
103 
105  QAbstractButton* button();
106 
108  virtual void setCursor( QCursor cursor );
109 
113  virtual bool isTransient();
114 
118  virtual bool isEditTool();
119 
121  virtual void activate();
122 
124  virtual void deactivate();
125 
127  QgsMapCanvas* canvas();
128 
131  QString toolName() { return mToolName; }
132 
137  static double searchRadiusMM();
138 
142  static double searchRadiusMU( const QgsRenderContext& context );
143 
147  static double searchRadiusMU( QgsMapCanvas * canvas );
148 
149  signals:
151  void messageEmitted( QString message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
152 
154  void messageDiscarded();
155 
156  private slots:
158  void actionDestroyed();
159 
160  protected:
161 
163  QgsMapTool( QgsMapCanvas* canvas );
164 
166  QgsPoint toMapCoordinates( const QPoint& point );
167 
169  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QPoint& point );
170 
172  QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
173 
175  QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
176 
178  QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
179 
181  QPoint toCanvasCoordinates( const QgsPoint& point );
182 
185 
187  QCursor mCursor;
188 
191  QAction* mAction;
192 
195  QAbstractButton* mButton;
196 
198  QString mToolName;
199 };
200 
201 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:47
QAbstractButton * mButton
optionally map tool can have pointer to a button which will be used to set that action as active ...
Definition: qgsmaptool.h:195
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:198
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:184
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:187
QString toolName()
Emit map tool changed with the old tool.
Definition: qgsmaptool.h:131
A class to represent a point geometry.
Definition: qgspoint.h:63
Abstract base class for all map tools.
Definition: qgsmaptool.h:48
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:191