Skip to content

Commit

Permalink
deduplicated connecting to the curve of parent tool
Browse files Browse the repository at this point in the history
also moved it to the active() method
  • Loading branch information
SebDieBln committed Dec 21, 2015
1 parent aad8027 commit 6a2af5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
16 changes: 16 additions & 0 deletions src/app/qgsmaptooladdcircularstring.cpp
Expand Up @@ -126,6 +126,22 @@ void QgsMapToolAddCircularString::activate()
if ( mParentTool )
{
mParentTool->deleteTempRubberBand();
if ( mPoints.isEmpty() )
{
// if the parent tool has a curve, use its last point as the first point in this curve
const QgsCompoundCurveV2* compoundCurve = mParentTool->captureCurve();
if ( compoundCurve && 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 ) );
}
}
}
}
QgsMapToolCapture::activate();
}
Expand Down
18 changes: 0 additions & 18 deletions src/app/qgsmaptoolcircularstringcurvepoint.cpp
Expand Up @@ -23,24 +23,6 @@ void QgsMapToolCircularStringCurvePoint::cadCanvasReleaseEvent( QgsMapMouseEvent

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 )
{
Expand Down
20 changes: 2 additions & 18 deletions src/app/qgsmaptoolcircularstringradius.cpp
Expand Up @@ -49,24 +49,8 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e
{
if ( mPoints.isEmpty() )
{
//get first point from parent tool if there. Todo: move to upper class
const QgsCompoundCurveV2* compoundCurve = mParentTool->captureCurve();
if ( compoundCurve && 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() ) );
}
}
else
{
mPoints.append( mapPoint );
return;
}
mPoints.append( mapPoint );
return;
}

if ( mPoints.size() % 2 == 1 )
Expand Down

0 comments on commit 6a2af5d

Please sign in to comment.