Skip to content

Commit d0135dd

Browse files
author
timlinux
committed
Show rubber band on coordinate click position.
Make cursor hotspot the center of the cursor Added some icons & changed to grid layout git-svn-id: http://svn.osgeo.org/qgis/trunk@9001 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 390b145 commit d0135dd

8 files changed

+400
-16
lines changed

src/plugins/coordinate_capture/coordinatecapture.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void CoordinateCapture::initGui()
7676
{
7777

7878
// Create the action for tool
79-
mQActionPointer = new QAction(QIcon(":/coordinatecapture/coordinatecapture.png"),tr("Coordinate Capture"), this);
79+
mQActionPointer = new QAction(QIcon(":/coordinatecapture/coordinate_capture.png"),tr("Coordinate Capture"), this);
8080
// Set the what's this text
8181
mQActionPointer->setWhatsThis(tr("Click on the map to view coordinates and capture to clipboard."));
8282
// Connect the action to the run
@@ -92,18 +92,25 @@ void CoordinateCapture::initGui()
9292

9393
// create a little widget with x and y display to put into our dock widget
9494
QWidget * mypWidget = new QWidget();
95-
QLayout * mypLayout = new QVBoxLayout();
95+
QGridLayout *mypLayout = new QGridLayout ( mypWidget );
96+
mypLayout->setColumnMinimumWidth( 0, 36 );
9697
mypWidget->setLayout(mypLayout);
9798

99+
QLabel * mypGeoLabel = new QLabel(mypWidget);
100+
mypGeoLabel->setPixmap(QPixmap(":/coordinatecapture/geographic.png"));
101+
QLabel * mypCRSLabel = new QLabel(mypWidget);
102+
mypCRSLabel->setPixmap(QPixmap(":/coordinatecapture/transformed.png"));
98103
mpXEdit = new QLineEdit(mypWidget);
99104
mpYEdit = new QLineEdit(mypWidget);
100105
QPushButton * mypCopyButton = new QPushButton(mypWidget);
101106
mypCopyButton->setText(tr("Copy to clipboard"));
102107
connect(mypCopyButton, SIGNAL(clicked()), this, SLOT(copy()));
103108

104-
mypLayout->addWidget(mpXEdit);
105-
mypLayout->addWidget(mpYEdit);
106-
mypLayout->addWidget(mypCopyButton);
109+
mypLayout->addWidget(mypGeoLabel, 0,0);
110+
mypLayout->addWidget(mpXEdit, 0,1);
111+
mypLayout->addWidget(mypCRSLabel, 1,0);
112+
mypLayout->addWidget(mpYEdit, 1,1);
113+
mypLayout->addWidget(mypCopyButton, 2,1);
107114

108115

109116
//create the dock widget
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<RCC>
22
<qresource prefix="/coordinatecapture/" >
3-
<file>coordinatecapture.png</file>
3+
<file>coordinate_capture.png</file>
4+
<file>geographic.png</file>
5+
<file>transformed.png</file>
46
</qresource>
57
</RCC>

src/plugins/coordinate_capture/coordinatecapturemaptool.cpp

+23-10
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ CoordinateCaptureMapTool::CoordinateCaptureMapTool(QgsMapCanvas* thepCanvas)
3131
: QgsMapTool(thepCanvas)
3232
{
3333
// set cursor
34-
QPixmap myIdentifyCursor = QPixmap((const char **) capture_point_cursor);
35-
mCursor = QCursor(myIdentifyCursor, 1, 1);
34+
QPixmap myCursor = QPixmap((const char **) capture_point_cursor);
35+
mCursor = QCursor(myCursor, 8, 8); //8,8 is the point in the cursor where clicks register
3636
mpMapCanvas = thepCanvas;
37-
mpRubberBand = new QgsRubberBand(mpMapCanvas,false); //false - not a polygon
37+
mpRubberBand = new QgsRubberBand(mpMapCanvas,true); //true - its a polygon
3838
mpRubberBand->setColor(Qt::red);
39-
mpRubberBand->setWidth(3);
39+
mpRubberBand->setWidth(1);
4040
}
4141

4242
CoordinateCaptureMapTool::~CoordinateCaptureMapTool()
@@ -60,14 +60,27 @@ void CoordinateCaptureMapTool::canvasReleaseEvent(QMouseEvent * thepEvent)
6060
return;
6161
}
6262

63-
QgsPoint myPoint =
63+
QgsPoint myOriginalPoint =
6464
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x(), thepEvent->y());
65-
emit pointCaptured(myPoint);
66-
mpRubberBand->reset(false);
65+
emit pointCaptured(myOriginalPoint);
66+
67+
//make a little box for display
68+
69+
QgsPoint myPoint1 =
70+
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() - 1, thepEvent->y()-1);
71+
QgsPoint myPoint2 =
72+
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() + 1, thepEvent->y()-1);
73+
QgsPoint myPoint3 =
74+
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() + 1, thepEvent->y() + 1);
75+
QgsPoint myPoint4 =
76+
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x() - 1, thepEvent->y() + 1);
77+
78+
mpRubberBand->reset(true);
6779
// convert screen coordinates to map coordinates
68-
mpRubberBand->addPoint(myPoint,false); //true - update canvas
69-
mpRubberBand->addPoint(myPoint,false); //true - update canvas
70-
mpRubberBand->addPoint(myPoint,false); //true - update canvas
80+
mpRubberBand->addPoint(myPoint1,false); //true - update canvas
81+
mpRubberBand->addPoint(myPoint2,false); //true - update canvas
82+
mpRubberBand->addPoint(myPoint3,false); //true - update canvas
83+
mpRubberBand->addPoint(myPoint4,true); //true - update canvas
7184
mpRubberBand->show();
7285
}
7386

2.74 KB
Loading
Loading
994 Bytes
Loading

0 commit comments

Comments
 (0)