/
qgsmaptoolcircularstringcurvepoint.cpp
88 lines (80 loc) · 2.63 KB
/
qgsmaptoolcircularstringcurvepoint.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
#include "qgsmaptoolcircularstringcurvepoint.h"
#include "qgscircularstringv2.h"
#include "qgscompoundcurvev2.h"
#include "qgsgeometryrubberband.h"
#include "qgsmapcanvas.h"
#include "qgspointv2.h"
#include <QMouseEvent>
QgsMapToolCircularStringCurvePoint::QgsMapToolCircularStringCurvePoint( QgsMapToolCapture* parentTool,
QgsMapCanvas* canvas, CaptureMode mode )
: QgsMapToolAddCircularString( parentTool, canvas, mode )
{
}
QgsMapToolCircularStringCurvePoint::~QgsMapToolCircularStringCurvePoint()
{
}
void QgsMapToolCircularStringCurvePoint::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
{
QgsPointV2 mapPoint( e->mapPoint().x(), e->mapPoint().y() );
if ( e->button() == Qt::LeftButton )
{
if ( mPoints.size() < 1 ) //connection to vertex of previous line segment needed?
{
const QgsCompoundCurveV2* compoundCurve = mParentTool->captureCurve();
if ( compoundCurve )
{
if ( compoundCurve->nCurves() > 0 )
{
const QgsCurveV2* curve = compoundCurve->curveAt( compoundCurve->nCurves() - 1 );
if ( curve )
{
//mParentTool->captureCurve() is in layer coordinates, but we need map coordinates
QgsPointV2 endPointLayerCoord = curve->endPoint();
QgsPoint mapPoint = toMapCoordinates( mCanvas->currentLayer(), QgsPoint( endPointLayerCoord.x(), endPointLayerCoord.y() ) );
mPoints.append( QgsPointV2( mapPoint.x(), mapPoint.y() ) );
}
}
}
}
mPoints.append( mapPoint );
if ( !mCenterPointRubberBand && mShowCenterPointRubberBand )
{
createCenterPointRubberBand();
}
if ( mPoints.size() >= 1 )
{
if ( !mRubberBand )
{
mRubberBand = createGeometryRubberBand(( mode() == CapturePolygon ) ? QGis::Polygon : QGis::Line );
mRubberBand->show();
}
QgsCircularStringV2* c = new QgsCircularStringV2();
QList< QgsPointV2 > rubberBandPoints = mPoints;
rubberBandPoints.append( mapPoint );
c->setPoints( rubberBandPoints );
mRubberBand->setGeometry( c );
}
if (( mPoints.size() ) % 2 == 1 )
{
removeCenterPointRubberBand();
}
}
else if ( e->button() == Qt::RightButton )
{
deactivate();
if ( mParentTool )
{
mParentTool->canvasReleaseEvent( e );
}
}
}
void QgsMapToolCircularStringCurvePoint::cadCanvasMoveEvent( QgsMapMouseEvent* e )
{
QgsPointV2 mapPoint( e->mapPoint().x(), e->mapPoint().y() );
QgsVertexId idx; idx.part = 0; idx.ring = 0; idx.vertex = mPoints.size();
if ( mRubberBand )
{
mRubberBand->moveVertex( idx, mapPoint );
updateCenterPointRubberBand( mapPoint );
}
}