-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgsgeorefdatapoint.cpp
103 lines (90 loc) · 3.27 KB
/
qgsgeorefdatapoint.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
/***************************************************************************
qgsgeorefdatapoint.cpp
--------------------------------------
Date : Sun Sep 16 12:02:45 AKDT 2007
Copyright : (C) 2007 by Gary E. Sherman
Email : sherman at mrcc 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. *
* *
***************************************************************************/
/* $Id$ */
#include <QPainter>
#include "qgsmapcanvas.h"
#include "qgsgcpcanvasitem.h"
#include "qgsgeorefdatapoint.h"
QgsGeorefDataPoint::QgsGeorefDataPoint( QgsMapCanvas* srcCanvas, QgsMapCanvas *dstCanvas,
const QgsPoint& pixelCoords, const QgsPoint& mapCoords,
bool enable )
: mSrcCanvas(srcCanvas)
, mDstCanvas(dstCanvas)
, mPixelCoords( pixelCoords )
, mMapCoords( mapCoords )
, mId(-1)
, mEnabled(enable)
{
mGCPSourceItem = new QgsGCPCanvasItem(srcCanvas, pixelCoords, mapCoords, true);
mGCPDestinationItem = new QgsGCPCanvasItem(dstCanvas, pixelCoords, mapCoords, false);
mGCPSourceItem->setEnabled(enable);
mGCPDestinationItem->setEnabled(enable);
mGCPSourceItem->show();
mGCPDestinationItem->show();
}
QgsGeorefDataPoint::QgsGeorefDataPoint(const QgsGeorefDataPoint &p)
{
// we share item representation on canvas between all points
// mGCPSourceItem = new QgsGCPCanvasItem(p.srcCanvas(), p.pixelCoords(), p.mapCoords(), p.isEnabled());
// mGCPDestinationItem = new QgsGCPCanvasItem(p.dstCanvas(), p.pixelCoords(), p.mapCoords(), p.isEnabled());
mPixelCoords = p.pixelCoords();
mMapCoords = p.mapCoords();
mEnabled = p.isEnabled();
}
QgsGeorefDataPoint::~QgsGeorefDataPoint()
{
delete mGCPSourceItem;
delete mGCPDestinationItem;
}
void QgsGeorefDataPoint::setPixelCoords(const QgsPoint &p)
{
mPixelCoords = p;
mGCPSourceItem->setRasterCoords(p);
mGCPDestinationItem->setRasterCoords(p);
}
void QgsGeorefDataPoint::setMapCoords(const QgsPoint &p)
{
mMapCoords = p;
mGCPSourceItem->setWorldCoords(p);
mGCPDestinationItem->setWorldCoords(p);
}
void QgsGeorefDataPoint::setEnabled(bool enabled)
{
mGCPSourceItem->setEnabled(enabled);
mEnabled = enabled;
}
void QgsGeorefDataPoint::setId(int id) {
mId = id;
mGCPSourceItem->setId(id);
mGCPDestinationItem->setId(id);
}
void QgsGeorefDataPoint::updateCoords()
{
mGCPSourceItem->updatePosition();
mGCPDestinationItem->updatePosition();
mGCPSourceItem->update();
mGCPDestinationItem->update();
}
bool QgsGeorefDataPoint::contains(const QPoint &p)
{
QPointF pnt = mGCPSourceItem->mapFromScene(p);
return mGCPSourceItem->shape().contains(pnt);
}
void QgsGeorefDataPoint::moveTo(const QPoint &p)
{
QgsPoint pnt = mGCPSourceItem->toMapCoordinates(p);
setPixelCoords(pnt);
updateCoords();
}