~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/gui/qgsmaptool.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include <QCursor>
21
21
#include <QString>
 
22
#include <QObject>
22
23
 
23
24
class QgsMapLayer;
24
25
class QgsMapCanvas;
 
26
class QKeyEvent;
25
27
class QMouseEvent;
26
28
class QgsPoint;
 
29
class QgsRectangle;
27
30
class QPoint;
28
31
class QAction;
29
 
 
30
 
 
31
 
class QgsMapTool
 
32
class QAbstractButton;
 
33
 
 
34
/** \ingroup gui
 
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.
 
39
 */
 
40
class GUI_EXPORT QgsMapTool : public QObject
32
41
{
33
42
  public:
34
 
    
 
43
 
35
44
    //! virtual destructor
36
45
    virtual ~QgsMapTool();
37
 
    
38
 
    //! Mouse move event for overriding
39
 
    virtual void canvasMoveEvent(QMouseEvent * e) { }
40
 
 
41
 
    //! Mouse press event for overriding
42
 
    virtual void canvasPressEvent(QMouseEvent * e) { }
43
 
 
44
 
    //! Mouse release event for overriding
45
 
    virtual void canvasReleaseEvent(QMouseEvent * e) { }
46
 
    
47
 
    //! Called when rendering has finished
48
 
    virtual void renderComplete() {}
49
 
    
50
 
    /** Use this to associate a button, toolbutton, menu entry etc
51
 
     * that inherits qaction to this maptool. Then when the setMapTool
 
46
 
 
47
    //! Mouse move event for overriding. Default implementation does nothing.
 
48
    virtual void canvasMoveEvent( QMouseEvent * e );
 
49
 
 
50
    //! Mouse double click event for overriding. Default implementation does nothing.
 
51
    virtual void canvasDoubleClickEvent( QMouseEvent * e );
 
52
 
 
53
    //! Mouse press event for overriding. Default implementation does nothing.
 
54
    virtual void canvasPressEvent( QMouseEvent * e );
 
55
 
 
56
    //! Mouse release event for overriding. Default implementation does nothing.
 
57
    virtual void canvasReleaseEvent( QMouseEvent * e );
 
58
 
 
59
    //! Key event for overriding. Default implementation does nothing.
 
60
    virtual void keyPressEvent( QKeyEvent* e );
 
61
 
 
62
    //! Key event for overriding. Default implementation does nothing.
 
63
    //! Added in version 1.1
 
64
    virtual void keyReleaseEvent( QKeyEvent* e );
 
65
 
 
66
    //! Called when rendering has finished. Default implementation does nothing.
 
67
    virtual void renderComplete();
 
68
 
 
69
 
 
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; }
56
 
    
57
 
    QAction* action() { return mAction; }
58
 
    
 
74
    void setAction( QAction* action );
 
75
 
 
76
    /** Return associated action with map tool or NULL if no action is associated */
 
77
    QAction* action();
 
78
 
 
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 );
 
82
 
 
83
    /** Return associated button with map tool or NULL if no button is associated */
 
84
    QAbstractButton* button();
 
85
 
 
86
 
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;}
63
 
    
 
90
    virtual bool isTransient();
 
91
 
 
92
    /** Check whether this MapTool performs an edit operation.
 
93
     * If it does, we will deactivate it when editing is turned off
 
94
     */
 
95
    virtual bool isEditTool();
 
96
 
64
97
    //! called when set as currently active map tool
65
98
    virtual void activate();
66
 
    
 
99
 
67
100
    //! called when map tool is being deactivated
68
101
    virtual void deactivate();
69
 
    
 
102
 
 
103
    //! returns pointer to the tool's map canvas
 
104
    QgsMapCanvas* canvas();
 
105
 
70
106
  protected:
71
107
 
72
108
    //! constructor takes map canvas as a parameter
73
 
    QgsMapTool(QgsMapCanvas* canvas);
74
 
        
 
109
    QgsMapTool( QgsMapCanvas* canvas );
 
110
 
75
111
    //! transformation from screen coordinates to map coordinates
76
 
    QgsPoint toMapCoords(const QPoint& point);
77
 
    
 
112
    QgsPoint toMapCoordinates( const QPoint& point );
 
113
 
78
114
    //! transformation from screen coordinates to layer's coordinates
79
 
    QgsPoint toLayerCoords(QgsMapLayer* layer, const QPoint& point);
80
 
    
 
115
    QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QPoint& point );
 
116
 
 
117
    //! trasformation from map coordinates to layer's coordinates
 
118
    QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
 
119
 
 
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 );
 
122
 
 
123
    //! trnasformation of the rect from map coordinates to layer's coordinates
 
124
    QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
 
125
 
81
126
    //! transformation from map coordinates to screen coordinates
82
 
    QPoint toCanvasCoords(const QgsPoint& point);
83
 
    
 
127
    QPoint toCanvasCoordinates( const QgsPoint& point );
 
128
 
84
129
    //! pointer to map canvas
85
130
    QgsMapCanvas* mCanvas;
86
 
    
 
131
 
87
132
    //! cursor used in map tool
88
133
    QCursor mCursor;
89
 
    
 
134
 
90
135
    //! optionally map tool can have pointer to action
91
136
    //! which will be used to set that action as active
92
137
    QAction* mAction;
93
 
    
 
138
 
 
139
    //! optionally map tool can have pointer to a button
 
140
    //! which will be used to set that action as active
 
141
    QAbstractButton* mButton;
 
142
 
94
143
};
95
144
 
96
145
#endif