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