Skip to content

Commit 952439b

Browse files
author
wonder
committed
Updated georeferencer plugin to use emit tool for acquiring coordinates of a point from map canvas.
Removed sendXY signal from QgsMapCanvas. git-svn-id: http://svn.osgeo.org/qgis/trunk@7036 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 40261ce commit 952439b

File tree

9 files changed

+197
-65
lines changed

9 files changed

+197
-65
lines changed

src/gui/qgsmapcanvas.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,6 @@ void QgsMapCanvas::mousePressEvent(QMouseEvent * e)
645645
mCanvasProperties->mouseButtonDown = true;
646646
mCanvasProperties->rubberStartPoint = e->pos();
647647

648-
if (e->button() == Qt::RightButton )
649-
{
650-
QPoint xy = e->pos();
651-
QgsPoint coord = getCoordinateTransform()->toMapCoordinates(xy);
652-
emit sendXY(coord);
653-
}
654-
655648
} // mousePressEvent
656649

657650

src/gui/qgsmapcanvas.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
274274
void setProgress(int,int);
275275
/** emits current mouse position */
276276
void xyCoordinates(QgsPoint & p);
277-
/** emits current mouse position on right mouse click */
278-
void sendXY(QgsPoint & p);
279277

280278
//! Emitted when the scale of the map changes
281279
void scaleChanged(double);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<RCC>
22
<qresource prefix="/" >
3-
<file>icon.png</file>
43
<file>georef.png</file>
4+
<file>icon.png</file>
5+
<file>pencil.png</file>
56
</qresource>
67
</RCC>

src/plugins/georeferencer/mapcoordsdialog.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1+
12
#include <QValidator>
23
#include <mapcoordsdialog.h>
34

5+
#include <qgsmapcanvas.h>
6+
#include <qgsmaptoolemitpoint.h>
47

58
MapCoordsDialog::MapCoordsDialog() {
69

710
}
811

912

10-
MapCoordsDialog::MapCoordsDialog(const QgsPoint& pixelCoords,
13+
MapCoordsDialog::MapCoordsDialog(const QgsPoint& pixelCoords, QgsMapCanvas* qgisCanvas,
1114
QWidget* parent, Qt::WFlags fl)
1215
: QDialog(parent, fl) {
1316
setupUi(this);
1417
mPixelCoords = pixelCoords;
18+
mQgisCanvas = qgisCanvas;
1519
leXCoord->setValidator(new QDoubleValidator(this));
1620
leYCoord->setValidator(new QDoubleValidator(this));
21+
22+
mToolEmitPoint = new QgsMapToolEmitPoint(qgisCanvas);
23+
mToolEmitPoint->setButton(btnPointFromCanvas);
24+
connect(mToolEmitPoint, SIGNAL(gotPoint(QgsPoint&,Qt::MouseButton)), this, SLOT(setXY(QgsPoint&)));
1725
}
1826

1927

2028
MapCoordsDialog::~MapCoordsDialog() {
2129

30+
delete mToolEmitPoint;
2231
}
2332

2433

@@ -35,6 +44,16 @@ void MapCoordsDialog::on_buttonCancel_clicked()
3544

3645
void MapCoordsDialog::setXY(QgsPoint & xy)
3746
{
38-
leXCoord->insert(QString::number(xy.x(),'f',7));
39-
leYCoord->insert(QString::number(xy.y(),'f',7));
47+
leXCoord->clear();
48+
leYCoord->clear();
49+
leXCoord->insert(QString::number(xy.x(),'f',7));
50+
leYCoord->insert(QString::number(xy.y(),'f',7));
51+
52+
mQgisCanvas->setMapTool(mPrevMapTool);
53+
}
54+
55+
void MapCoordsDialog::on_btnPointFromCanvas_clicked()
56+
{
57+
mPrevMapTool = mQgisCanvas->mapTool();
58+
mQgisCanvas->setMapTool(mToolEmitPoint);
4059
}

src/plugins/georeferencer/mapcoordsdialog.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414

1515
#include <qgspoint.h>
1616

17+
class QgsMapCanvas;
18+
class QgsMapTool;
19+
1720
#include <ui_mapcoordsdialogbase.h>
1821
#include <QDialog>
1922
class MapCoordsDialog : public QDialog, private Ui::MapCoordsDialogBase
2023
{
2124
Q_OBJECT
2225
public:
2326
MapCoordsDialog();
24-
MapCoordsDialog(const QgsPoint& pixelCoords,
27+
MapCoordsDialog(const QgsPoint& pixelCoords, QgsMapCanvas* qgisCanvas,
2528
QWidget* parent = 0, Qt::WFlags fl = 0);
2629
~MapCoordsDialog();
2730

@@ -30,11 +33,18 @@ public slots:
3033
void on_buttonOk_clicked();
3134
void on_buttonCancel_clicked();
3235

36+
void on_btnPointFromCanvas_clicked();
37+
3338
void setXY(QgsPoint &);
3439

3540
private:
3641

3742
QgsPoint mPixelCoords;
43+
44+
QgsMapTool* mToolEmitPoint;
45+
QgsMapTool* mPrevMapTool;
46+
47+
QgsMapCanvas* mQgisCanvas;
3848

3949
signals:
4050

Lines changed: 158 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<ui version="4.0" >
2-
<author></author>
3-
<comment></comment>
4-
<exportmacro></exportmacro>
52
<class>MapCoordsDialogBase</class>
63
<widget class="QDialog" name="MapCoordsDialogBase" >
74
<property name="geometry" >
85
<rect>
96
<x>0</x>
107
<y>0</y>
11-
<width>290</width>
12-
<height>110</height>
8+
<width>389</width>
9+
<height>203</height>
1310
</rect>
1411
</property>
1512
<property name="windowTitle" >
@@ -18,77 +15,187 @@
1815
<property name="sizeGripEnabled" >
1916
<bool>true</bool>
2017
</property>
21-
<layout class="QGridLayout" >
18+
<layout class="QVBoxLayout" >
2219
<property name="margin" >
23-
<number>10</number>
20+
<number>9</number>
2421
</property>
2522
<property name="spacing" >
2623
<number>6</number>
2724
</property>
28-
<item row="0" column="0" >
29-
<widget class="QLabel" name="textLabel1" >
25+
<item>
26+
<widget class="QLabel" name="label" >
3027
<property name="text" >
31-
<string>X:</string>
28+
<string>Enter X and Y coordinates which correspond with the selected point on the image. Alternatively, click the button with icon of a pencil and then click a corresponding point on map canvas of QGIS to fill in coordinates of that point.</string>
3229
</property>
33-
</widget>
34-
</item>
35-
<item row="1" column="0" >
36-
<widget class="QLabel" name="textLabel2" >
37-
<property name="text" >
38-
<string>Y:</string>
30+
<property name="wordWrap" >
31+
<bool>true</bool>
3932
</property>
4033
</widget>
4134
</item>
42-
<item row="1" column="1" colspan="3" >
43-
<widget class="QLineEdit" name="leYCoord" />
44-
</item>
45-
<item row="0" column="1" colspan="3" >
46-
<widget class="QLineEdit" name="leXCoord" />
47-
</item>
48-
<item row="2" column="0" colspan="2" >
35+
<item>
4936
<spacer>
5037
<property name="orientation" >
51-
<enum>Qt::Horizontal</enum>
38+
<enum>Qt::Vertical</enum>
5239
</property>
5340
<property name="sizeType" >
54-
<enum>QSizePolicy::Expanding</enum>
41+
<enum>QSizePolicy::Fixed</enum>
5542
</property>
5643
<property name="sizeHint" >
5744
<size>
58-
<width>90</width>
59-
<height>20</height>
45+
<width>20</width>
46+
<height>10</height>
6047
</size>
6148
</property>
6249
</spacer>
6350
</item>
64-
<item row="2" column="3" >
65-
<widget class="QPushButton" name="buttonOk" >
66-
<property name="text" >
67-
<string>&amp;OK</string>
51+
<item>
52+
<layout class="QGridLayout" >
53+
<property name="margin" >
54+
<number>0</number>
6855
</property>
69-
<property name="shortcut" >
70-
<string/>
56+
<property name="spacing" >
57+
<number>6</number>
7158
</property>
72-
<property name="autoDefault" >
73-
<bool>true</bool>
59+
<item row="0" column="1" >
60+
<widget class="QLabel" name="textLabel1" >
61+
<property name="text" >
62+
<string>X:</string>
63+
</property>
64+
</widget>
65+
</item>
66+
<item row="1" column="1" >
67+
<widget class="QLabel" name="textLabel2" >
68+
<property name="text" >
69+
<string>Y:</string>
70+
</property>
71+
</widget>
72+
</item>
73+
<item row="0" column="2" >
74+
<widget class="QLineEdit" name="leXCoord" />
75+
</item>
76+
<item row="1" column="2" >
77+
<widget class="QLineEdit" name="leYCoord" />
78+
</item>
79+
<item rowspan="2" row="0" column="3" >
80+
<spacer>
81+
<property name="orientation" >
82+
<enum>Qt::Horizontal</enum>
83+
</property>
84+
<property name="sizeType" >
85+
<enum>QSizePolicy::Minimum</enum>
86+
</property>
87+
<property name="sizeHint" >
88+
<size>
89+
<width>40</width>
90+
<height>20</height>
91+
</size>
92+
</property>
93+
</spacer>
94+
</item>
95+
<item rowspan="2" row="0" column="0" >
96+
<spacer>
97+
<property name="orientation" >
98+
<enum>Qt::Horizontal</enum>
99+
</property>
100+
<property name="sizeType" >
101+
<enum>QSizePolicy::Minimum</enum>
102+
</property>
103+
<property name="sizeHint" >
104+
<size>
105+
<width>40</width>
106+
<height>20</height>
107+
</size>
108+
</property>
109+
</spacer>
110+
</item>
111+
</layout>
112+
</item>
113+
<item>
114+
<spacer>
115+
<property name="orientation" >
116+
<enum>Qt::Vertical</enum>
74117
</property>
75-
<property name="default" >
76-
<bool>true</bool>
118+
<property name="sizeHint" >
119+
<size>
120+
<width>20</width>
121+
<height>21</height>
122+
</size>
77123
</property>
78-
</widget>
124+
</spacer>
79125
</item>
80-
<item row="2" column="2" >
81-
<widget class="QPushButton" name="buttonCancel" >
82-
<property name="text" >
83-
<string>&amp;Cancel</string>
126+
<item>
127+
<layout class="QHBoxLayout" >
128+
<property name="margin" >
129+
<number>0</number>
84130
</property>
85-
<property name="shortcut" >
86-
<string/>
131+
<property name="spacing" >
132+
<number>6</number>
87133
</property>
88-
<property name="autoDefault" >
89-
<bool>true</bool>
90-
</property>
91-
</widget>
134+
<item>
135+
<widget class="QPushButton" name="btnPointFromCanvas" >
136+
<property name="text" >
137+
<string> from map canvas</string>
138+
</property>
139+
<property name="icon" >
140+
<iconset resource="georeferencer.qrc" >:/pencil.png</iconset>
141+
</property>
142+
<property name="iconSize" >
143+
<size>
144+
<width>18</width>
145+
<height>18</height>
146+
</size>
147+
</property>
148+
<property name="checkable" >
149+
<bool>true</bool>
150+
</property>
151+
</widget>
152+
</item>
153+
<item>
154+
<spacer>
155+
<property name="orientation" >
156+
<enum>Qt::Horizontal</enum>
157+
</property>
158+
<property name="sizeType" >
159+
<enum>QSizePolicy::Expanding</enum>
160+
</property>
161+
<property name="sizeHint" >
162+
<size>
163+
<width>21</width>
164+
<height>27</height>
165+
</size>
166+
</property>
167+
</spacer>
168+
</item>
169+
<item>
170+
<widget class="QPushButton" name="buttonCancel" >
171+
<property name="text" >
172+
<string>&amp;Cancel</string>
173+
</property>
174+
<property name="shortcut" >
175+
<string/>
176+
</property>
177+
<property name="autoDefault" >
178+
<bool>true</bool>
179+
</property>
180+
</widget>
181+
</item>
182+
<item>
183+
<widget class="QPushButton" name="buttonOk" >
184+
<property name="text" >
185+
<string>&amp;OK</string>
186+
</property>
187+
<property name="shortcut" >
188+
<string/>
189+
</property>
190+
<property name="autoDefault" >
191+
<bool>true</bool>
192+
</property>
193+
<property name="default" >
194+
<bool>true</bool>
195+
</property>
196+
</widget>
197+
</item>
198+
</layout>
92199
</item>
93200
</layout>
94201
</widget>
@@ -100,6 +207,8 @@
100207
<tabstop>buttonCancel</tabstop>
101208
<tabstop>buttonOk</tabstop>
102209
</tabstops>
103-
<resources/>
210+
<resources>
211+
<include location="georeferencer.qrc" />
212+
</resources>
104213
<connections/>
105214
</ui>
1.77 KB
Loading

0 commit comments

Comments
 (0)