Skip to content

Commit 6a2af5d

Browse files
committedDec 21, 2015
deduplicated connecting to the curve of parent tool
also moved it to the active() method
1 parent aad8027 commit 6a2af5d

File tree

3 files changed

+18
-36
lines changed

3 files changed

+18
-36
lines changed
 

‎src/app/qgsmaptooladdcircularstring.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ void QgsMapToolAddCircularString::activate()
126126
if ( mParentTool )
127127
{
128128
mParentTool->deleteTempRubberBand();
129+
if ( mPoints.isEmpty() )
130+
{
131+
// if the parent tool has a curve, use its last point as the first point in this curve
132+
const QgsCompoundCurveV2* compoundCurve = mParentTool->captureCurve();
133+
if ( compoundCurve && compoundCurve->nCurves() > 0 )
134+
{
135+
const QgsCurveV2* curve = compoundCurve->curveAt( compoundCurve->nCurves() - 1 );
136+
if ( curve )
137+
{
138+
//mParentTool->captureCurve() is in layer coordinates, but we need map coordinates
139+
QgsPointV2 endPointLayerCoord = curve->endPoint();
140+
QgsPoint mapPoint = toMapCoordinates( mCanvas->currentLayer(), QgsPoint( endPointLayerCoord.x(), endPointLayerCoord.y() ) );
141+
mPoints.append( QgsPointV2( mapPoint ) );
142+
}
143+
}
144+
}
129145
}
130146
QgsMapToolCapture::activate();
131147
}

‎src/app/qgsmaptoolcircularstringcurvepoint.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,6 @@ void QgsMapToolCircularStringCurvePoint::cadCanvasReleaseEvent( QgsMapMouseEvent
2323

2424
if ( e->button() == Qt::LeftButton )
2525
{
26-
if ( mPoints.size() < 1 ) //connection to vertex of previous line segment needed?
27-
{
28-
const QgsCompoundCurveV2* compoundCurve = mParentTool->captureCurve();
29-
if ( compoundCurve )
30-
{
31-
if ( compoundCurve->nCurves() > 0 )
32-
{
33-
const QgsCurveV2* curve = compoundCurve->curveAt( compoundCurve->nCurves() - 1 );
34-
if ( curve )
35-
{
36-
//mParentTool->captureCurve() is in layer coordinates, but we need map coordinates
37-
QgsPointV2 endPointLayerCoord = curve->endPoint();
38-
QgsPoint mapPoint = toMapCoordinates( mCanvas->currentLayer(), QgsPoint( endPointLayerCoord.x(), endPointLayerCoord.y() ) );
39-
mPoints.append( QgsPointV2( mapPoint.x(), mapPoint.y() ) );
40-
}
41-
}
42-
}
43-
}
4426
mPoints.append( mapPoint );
4527
if ( !mCenterPointRubberBand && mShowCenterPointRubberBand )
4628
{

‎src/app/qgsmaptoolcircularstringradius.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,8 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e
4949
{
5050
if ( mPoints.isEmpty() )
5151
{
52-
//get first point from parent tool if there. Todo: move to upper class
53-
const QgsCompoundCurveV2* compoundCurve = mParentTool->captureCurve();
54-
if ( compoundCurve && compoundCurve->nCurves() > 0 )
55-
{
56-
const QgsCurveV2* curve = compoundCurve->curveAt( compoundCurve->nCurves() - 1 );
57-
if ( curve )
58-
{
59-
//mParentTool->captureCurve() is in layer coordinates, but we need map coordinates
60-
QgsPointV2 endPointLayerCoord = curve->endPoint();
61-
QgsPoint mapPoint = toMapCoordinates( mCanvas->currentLayer(), QgsPoint( endPointLayerCoord.x(), endPointLayerCoord.y() ) );
62-
mPoints.append( QgsPointV2( mapPoint.x(), mapPoint.y() ) );
63-
}
64-
}
65-
else
66-
{
67-
mPoints.append( mapPoint );
68-
return;
69-
}
52+
mPoints.append( mapPoint );
53+
return;
7054
}
7155

7256
if ( mPoints.size() % 2 == 1 )

0 commit comments

Comments
 (0)
Please sign in to comment.