24
25
class QgsMapCanvas;
32
class QAbstractButton;
35
* Abstract base class for all map tools.
36
* Map tools are user interactive tools for manipulating the
37
* map canvas. For example map pan and zoom features are
38
* implemented as map tools.
40
class GUI_EXPORT QgsMapTool : public QObject
35
44
//! virtual destructor
36
45
virtual ~QgsMapTool();
38
//! Mouse move event for overriding
39
virtual void canvasMoveEvent(QMouseEvent * e) { }
41
//! Mouse press event for overriding
42
virtual void canvasPressEvent(QMouseEvent * e) { }
44
//! Mouse release event for overriding
45
virtual void canvasReleaseEvent(QMouseEvent * e) { }
47
//! Called when rendering has finished
48
virtual void renderComplete() {}
50
/** Use this to associate a button, toolbutton, menu entry etc
51
* that inherits qaction to this maptool. Then when the setMapTool
47
//! Mouse move event for overriding. Default implementation does nothing.
48
virtual void canvasMoveEvent( QMouseEvent * e );
50
//! Mouse double click event for overriding. Default implementation does nothing.
51
virtual void canvasDoubleClickEvent( QMouseEvent * e );
53
//! Mouse press event for overriding. Default implementation does nothing.
54
virtual void canvasPressEvent( QMouseEvent * e );
56
//! Mouse release event for overriding. Default implementation does nothing.
57
virtual void canvasReleaseEvent( QMouseEvent * e );
59
//! Key event for overriding. Default implementation does nothing.
60
virtual void keyPressEvent( QKeyEvent* e );
62
//! Key event for overriding. Default implementation does nothing.
63
//! Added in version 1.1
64
virtual void keyReleaseEvent( QKeyEvent* e );
66
//! Called when rendering has finished. Default implementation does nothing.
67
virtual void renderComplete();
70
/** Use this to associate a QAction to this maptool. Then when the setMapTool
52
71
* method of mapcanvas is called the action state will be set to on.
53
72
* Usually this will cause e.g. a toolbutton to appear pressed in and
54
73
* the previously used toolbutton to pop out. */
55
void setAction(QAction* action) { mAction = action; }
57
QAction* action() { return mAction; }
74
void setAction( QAction* action );
76
/** Return associated action with map tool or NULL if no action is associated */
79
/** Use this to associate a button to this maptool. It has the same meaning
80
* as setAction() function except it works with a button instead of an QAction. */
81
void setButton( QAbstractButton* button );
83
/** Return associated button with map tool or NULL if no button is associated */
84
QAbstractButton* button();
59
87
/** Check whether this MapTool performs a zoom or pan operation.
60
* If it does, we will be able to perform the zoom and then
88
* If it does, we will be able to perform the zoom and then
61
89
* resume operations with the original / previously used tool.*/
62
virtual bool isZoomTool() { return false;}
90
virtual bool isTransient();
92
/** Check whether this MapTool performs an edit operation.
93
* If it does, we will deactivate it when editing is turned off
95
virtual bool isEditTool();
64
97
//! called when set as currently active map tool
65
98
virtual void activate();
67
100
//! called when map tool is being deactivated
68
101
virtual void deactivate();
103
//! returns pointer to the tool's map canvas
104
QgsMapCanvas* canvas();
72
108
//! constructor takes map canvas as a parameter
73
QgsMapTool(QgsMapCanvas* canvas);
109
QgsMapTool( QgsMapCanvas* canvas );
75
111
//! transformation from screen coordinates to map coordinates
76
QgsPoint toMapCoords(const QPoint& point);
112
QgsPoint toMapCoordinates( const QPoint& point );
78
114
//! transformation from screen coordinates to layer's coordinates
79
QgsPoint toLayerCoords(QgsMapLayer* layer, const QPoint& point);
115
QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QPoint& point );
117
//! trasformation from map coordinates to layer's coordinates
118
QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
120
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
121
QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
123
//! trnasformation of the rect from map coordinates to layer's coordinates
124
QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
81
126
//! transformation from map coordinates to screen coordinates
82
QPoint toCanvasCoords(const QgsPoint& point);
127
QPoint toCanvasCoordinates( const QgsPoint& point );
84
129
//! pointer to map canvas
85
130
QgsMapCanvas* mCanvas;
87
132
//! cursor used in map tool
90
135
//! optionally map tool can have pointer to action
91
136
//! which will be used to set that action as active
139
//! optionally map tool can have pointer to a button
140
//! which will be used to set that action as active
141
QAbstractButton* mButton;