Skip to content
Permalink
Browse files

deduplicated connecting to the curve of parent tool

also moved it to the active() method
  • Loading branch information
SebDieBln committed Dec 17, 2015
1 parent aad8027 commit 6a2af5d9360019eab8cc209d20ae0a723a4fc4b5
@@ -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();
}
@@ -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 )
{
@@ -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 )

0 comments on commit 6a2af5d

Please sign in to comment.
You can’t perform that action at this time.