forked from qgis/QGIS
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathqgsmaptool.cpp
169 lines (136 loc) · 3.74 KB
/
qgsmaptool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/***************************************************************************
qgsmaptool.cpp - base class for map canvas tools
----------------------
begin : January 2006
copyright : (C) 2006 by Martin Dobias
email : wonder.sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgslogger.h"
#include "qgsmaptool.h"
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgsmaprenderer.h"
#include <QAction>
#include <QAbstractButton>
QgsMapTool::QgsMapTool( QgsMapCanvas* canvas )
: QObject( canvas ), mCanvas( canvas ), mCursor( Qt::CrossCursor ), mAction( NULL ), mButton( NULL )
{
}
QgsMapTool::~QgsMapTool()
{
mCanvas->unsetMapTool( this );
}
QgsPoint QgsMapTool::toMapCoordinates( const QPoint& point )
{
return mCanvas->getCoordinateTransform()->toMapCoordinates( point );
}
QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QPoint& point )
{
QgsPoint pt = toMapCoordinates( point );
return toLayerCoordinates( layer, pt );
}
QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point )
{
return mCanvas->mapRenderer()->mapToLayerCoordinates( layer, point );
}
QgsPoint QgsMapTool::toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point )
{
return mCanvas->mapRenderer()->layerToMapCoordinates( layer, point );
}
QgsRectangle QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect )
{
return mCanvas->mapRenderer()->mapToLayerCoordinates( layer, rect );
}
QPoint QgsMapTool::toCanvasCoordinates( const QgsPoint& point )
{
double x = point.x(), y = point.y();
mCanvas->getCoordinateTransform()->transformInPlace( x, y );
return QPoint(( int )( x + 0.5 ), ( int )( y + 0.5 ) ); // round the values
}
void QgsMapTool::activate()
{
// make action and/or button active
if ( mAction )
mAction->setChecked( true );
if ( mButton )
mButton->setChecked( true );
// set cursor (map tools usually set it in constructor)
mCanvas->setCursor( mCursor );
QgsDebugMsg( "Cursor has been set" );
}
void QgsMapTool::deactivate()
{
if ( mAction )
mAction->setChecked( false );
if ( mButton )
mButton->setChecked( false );
}
void QgsMapTool::setAction( QAction* action )
{
mAction = action;
}
QAction* QgsMapTool::action()
{
return mAction;
}
void QgsMapTool::setButton( QAbstractButton* button )
{
mButton = button;
}
QAbstractButton* QgsMapTool::button()
{
return mButton;
}
void QgsMapTool::canvasMoveEvent( QMouseEvent *e )
{
Q_UNUSED( e );
}
void QgsMapTool::canvasDoubleClickEvent( QMouseEvent *e )
{
Q_UNUSED( e );
}
void QgsMapTool::canvasPressEvent( QMouseEvent *e )
{
Q_UNUSED( e );
}
void QgsMapTool::canvasReleaseEvent( QMouseEvent *e )
{
Q_UNUSED( e );
}
void QgsMapTool::keyPressEvent( QKeyEvent *e )
{
Q_UNUSED( e );
}
void QgsMapTool::keyReleaseEvent( QKeyEvent *e )
{
Q_UNUSED( e );
}
#ifdef HAVE_TOUCH
bool QgsMapTool::gestureEvent( QGestureEvent *e )
{
Q_UNUSED( e );
return true;
}
#endif
void QgsMapTool::renderComplete()
{
}
bool QgsMapTool::isTransient()
{
return false;
}
bool QgsMapTool::isEditTool()
{
return false;
}
QgsMapCanvas* QgsMapTool::canvas()
{
return mCanvas;
}