QGIS API Documentation
2.0.1-Dufour
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
gui
qgsmaptool.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsmaptool.cpp - 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
#include "
qgslogger.h
"
17
#include "
qgsmaptool.h
"
18
#include "
qgsmapcanvas.h
"
19
#include "
qgsmaptopixel.h
"
20
#include "
qgsmaprenderer.h
"
21
#include <QAction>
22
#include <QAbstractButton>
23
24
QgsMapTool::QgsMapTool
(
QgsMapCanvas
* canvas )
25
: QObject( canvas ), mCanvas( canvas ), mCursor( Qt::CrossCursor ), mAction( NULL ), mButton( NULL )
26
{
27
}
28
29
30
QgsMapTool::~QgsMapTool
()
31
{
32
mCanvas
->
unsetMapTool
(
this
);
33
}
34
35
36
QgsPoint
QgsMapTool::toMapCoordinates
(
const
QPoint& point )
37
{
38
return
mCanvas
->
getCoordinateTransform
()->
toMapCoordinates
( point );
39
}
40
41
42
QgsPoint
QgsMapTool::toLayerCoordinates
(
QgsMapLayer
* layer,
const
QPoint& point )
43
{
44
QgsPoint
pt =
toMapCoordinates
( point );
45
return
toLayerCoordinates
( layer, pt );
46
}
47
48
QgsPoint
QgsMapTool::toLayerCoordinates
(
QgsMapLayer
* layer,
const
QgsPoint
& point )
49
{
50
return
mCanvas
->
mapRenderer
()->
mapToLayerCoordinates
( layer, point );
51
}
52
53
QgsPoint
QgsMapTool::toMapCoordinates
(
QgsMapLayer
* layer,
const
QgsPoint
& point )
54
{
55
return
mCanvas
->
mapRenderer
()->
layerToMapCoordinates
( layer, point );
56
}
57
58
QgsRectangle
QgsMapTool::toLayerCoordinates
(
QgsMapLayer
* layer,
const
QgsRectangle
& rect )
59
{
60
return
mCanvas
->
mapRenderer
()->
mapToLayerCoordinates
( layer, rect );
61
}
62
63
QPoint
QgsMapTool::toCanvasCoordinates
(
const
QgsPoint
& point )
64
{
65
double
x = point.
x
(), y = point.
y
();
66
mCanvas
->
getCoordinateTransform
()->
transformInPlace
( x, y );
67
return
QPoint( qRound( x ), qRound( y ) );
68
}
69
70
71
void
QgsMapTool::activate
()
72
{
73
// make action and/or button active
74
if
(
mAction
)
75
mAction
->setChecked(
true
);
76
if
(
mButton
)
77
mButton
->setChecked(
true
);
78
79
// set cursor (map tools usually set it in constructor)
80
mCanvas
->setCursor(
mCursor
);
81
QgsDebugMsg
(
"Cursor has been set"
);
82
}
83
84
85
void
QgsMapTool::deactivate
()
86
{
87
if
(
mAction
)
88
mAction
->setChecked(
false
);
89
if
(
mButton
)
90
mButton
->setChecked(
false
);
91
}
92
93
void
QgsMapTool::setAction
( QAction* action )
94
{
95
mAction
=
action
;
96
}
97
98
QAction*
QgsMapTool::action
()
99
{
100
return
mAction
;
101
}
102
103
void
QgsMapTool::setButton
( QAbstractButton* button )
104
{
105
mButton
=
button
;
106
}
107
108
QAbstractButton*
QgsMapTool::button
()
109
{
110
return
mButton
;
111
}
112
113
void
QgsMapTool::setCursor
( QCursor cursor )
114
{
115
mCursor
= cursor;
116
}
117
118
119
void
QgsMapTool::canvasMoveEvent
( QMouseEvent *e )
120
{
121
Q_UNUSED( e );
122
}
123
124
void
QgsMapTool::canvasDoubleClickEvent
( QMouseEvent *e )
125
{
126
Q_UNUSED( e );
127
}
128
129
void
QgsMapTool::canvasPressEvent
( QMouseEvent *e )
130
{
131
Q_UNUSED( e );
132
}
133
134
void
QgsMapTool::canvasReleaseEvent
( QMouseEvent *e )
135
{
136
Q_UNUSED( e );
137
}
138
139
void
QgsMapTool::wheelEvent
( QWheelEvent *e )
140
{
141
Q_UNUSED( e );
142
}
143
144
void
QgsMapTool::keyPressEvent
( QKeyEvent *e )
145
{
146
Q_UNUSED( e );
147
}
148
149
void
QgsMapTool::keyReleaseEvent
( QKeyEvent *e )
150
{
151
Q_UNUSED( e );
152
}
153
154
#ifdef HAVE_TOUCH
155
bool
QgsMapTool::gestureEvent( QGestureEvent *e )
156
{
157
Q_UNUSED( e );
158
return
true
;
159
}
160
#endif
161
162
void
QgsMapTool::renderComplete
()
163
{
164
}
165
166
bool
QgsMapTool::isTransient
()
167
{
168
return
false
;
169
}
170
171
bool
QgsMapTool::isEditTool
()
172
{
173
return
false
;
174
}
175
176
QgsMapCanvas
*
QgsMapTool::canvas
()
177
{
178
return
mCanvas
;
179
}
Generated on Tue Sep 24 2013 14:41:50 for QGIS API Documentation by
1.8.1.2