Skip to content

Commit 5d7545c

Browse files
author
wonder
committed
Added QgsMapToolEmitPoint which emits a signal when a point on map canvas is clicked.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6989 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4e8c14e commit 5d7545c

6 files changed

+118
-0
lines changed

python/gui/gui.sip

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
%Include qgsmapcanvasitem.sip
1616
%Include qgsmapcanvasmap.sip
1717
%Include qgsmaptool.sip
18+
%Include qgsmaptoolemitpoint.sip
1819
%Include qgsmaptoolpan.sip
1920
%Include qgsmaptoolzoom.sip
2021
%Include qgsmapoverviewcanvas.sip

python/gui/qgsmaptool.sip

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class QgsMapTool : QObject
1010
sipClass = sipClass_QgsMapToolZoom;
1111
else if (dynamic_cast<QgsMapToolPan*>(sipCpp) != NULL)
1212
sipClass = sipClass_QgsMapToolPan;
13+
else if (dynamic_cast<QgsMapToolEmitPoint*>(sipCpp) != NULL)
14+
sipClass = sipClass_QgsMapToolEmitPoint;
1315
else
1416
sipClass = NULL;
1517
%End

python/gui/qgsmaptoolemitpoint.sip

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
class QgsMapToolEmitPoint : QgsMapTool
3+
{
4+
%TypeHeaderCode
5+
#include <qgsmaptoolemitpoint.h>
6+
%End
7+
8+
public:
9+
//! constructor
10+
QgsMapToolEmitPoint(QgsMapCanvas* canvas);
11+
12+
//! Overridden mouse move event
13+
virtual void canvasMoveEvent(QMouseEvent * e);
14+
15+
//! Overridden mouse press event - emits the signal
16+
virtual void canvasPressEvent(QMouseEvent * e);
17+
18+
//! Overridden mouse release event
19+
virtual void canvasReleaseEvent(QMouseEvent * e);
20+
21+
signals:
22+
23+
//! signal emitted on canvas click
24+
void gotPoint(QgsPoint& point, Qt::MouseButton button);
25+
};

src/gui/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ qgsmapcanvasitem.cpp
1212
qgsmapcanvasmap.cpp
1313
qgsmapoverviewcanvas.cpp
1414
qgsmaptool.cpp
15+
qgsmaptoolemitpoint.cpp
1516
qgsmaptoolpan.cpp
1617
qgsmaptoolzoom.cpp
1718
qgsmessageviewer.cpp
@@ -26,6 +27,7 @@ qgsencodingfiledialog.h
2627
qgslayerprojectionselector.h
2728
qgsmapcanvas.h
2829
qgsmapoverviewcanvas.h
30+
qgsmaptoolemitpoint.h
2931
qgsprojectionselector.h
3032
)
3133

@@ -81,6 +83,7 @@ qgsmapcanvasitem.h
8183
qgsmapcanvasmap.h
8284
qgsmapoverviewcanvas.h
8385
qgsmaptool.h
86+
qgsmaptoolemitpoint.h
8487
qgsmaptoolpan.h
8588
qgsmaptoolzoom.h
8689
qgsmessageviewer.h

src/gui/qgsmaptoolemitpoint.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************
2+
qgsmaptoolemitpoint.cpp - map tool that emits a signal on click
3+
---------------------
4+
begin : June 2007
5+
copyright : (C) 2007 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+
18+
#include "qgsmaptoolemitpoint.h"
19+
#include "qgsmapcanvas.h"
20+
21+
22+
QgsMapToolEmitPoint::QgsMapToolEmitPoint(QgsMapCanvas* canvas)
23+
: QgsMapTool(canvas)
24+
{
25+
}
26+
27+
void QgsMapToolEmitPoint::canvasMoveEvent(QMouseEvent * e)
28+
{
29+
}
30+
31+
void QgsMapToolEmitPoint::canvasPressEvent(QMouseEvent * e)
32+
{
33+
QgsPoint pnt = toMapCoords(e->pos());
34+
emit gotPoint(pnt, e->button());
35+
}
36+
37+
void QgsMapToolEmitPoint::canvasReleaseEvent(QMouseEvent * e)
38+
{
39+
}

src/gui/qgsmaptoolemitpoint.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/***************************************************************************
2+
qgsmaptoolemitpoint.h - map tool that emits a signal on click
3+
---------------------
4+
begin : June 2007
5+
copyright : (C) 2007 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+
#ifndef QGSMAPTOOLEMITPOINT_H
18+
#define QGSMAPTOOLEMITPOINT_H
19+
20+
#include "qgspoint.h"
21+
#include "qgsmaptool.h"
22+
class QgsMapCanvas;
23+
24+
25+
class GUI_EXPORT QgsMapToolEmitPoint : public QgsMapTool
26+
{
27+
Q_OBJECT
28+
29+
public:
30+
//! constructor
31+
QgsMapToolEmitPoint(QgsMapCanvas* canvas);
32+
33+
//! Overridden mouse move event
34+
virtual void canvasMoveEvent(QMouseEvent * e);
35+
36+
//! Overridden mouse press event - emits the signal
37+
virtual void canvasPressEvent(QMouseEvent * e);
38+
39+
//! Overridden mouse release event
40+
virtual void canvasReleaseEvent(QMouseEvent * e);
41+
42+
signals:
43+
44+
//! signal emitted on canvas click
45+
void gotPoint(QgsPoint& point, Qt::MouseButton button);
46+
};
47+
48+
#endif

0 commit comments

Comments
 (0)