From f613a3a28f2700b751da96cdac1355362f067fc1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 20 Dec 2016 16:58:00 +0200 Subject: [PATCH] Refactoring. Use QScopedPointer class. --HG-- branch : develop --- src/libs/vtools/tools/vtooluniondetails.cpp | 42 ++++++++------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 410520a80..27aa19baa 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -231,19 +231,19 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); - VPointF *p1 = new VPointF(spline->GetP1()); + QScopedPointer p1(new VPointF(spline->GetP1())); VPointF p2 = VPointF(spline->GetP2()); VPointF p3 = VPointF(spline->GetP3()); - VPointF *p4 = new VPointF(spline->GetP4()); + QScopedPointer p4(new VPointF(spline->GetP4())); if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) { const QPointF p = *data->GeometricObject(pRotate); - BiasRotatePoint(p1, dx, dy, p, angle); + BiasRotatePoint(p1.data(), dx, dy, p, angle); BiasRotatePoint(&p2, dx, dy, p, angle); BiasRotatePoint(&p3, dx, dy, p, angle); - BiasRotatePoint(p4, dx, dy, p, angle); + BiasRotatePoint(p4.data(), dx, dy, p, angle); } VSpline *spl = new VSpline(*p1, p2, p3, *p4, 0, Draw::Modeling); @@ -254,9 +254,6 @@ void VToolUnionDetails::AddToNewDetail(VMainGraphicsScene *scene, VAbstractPatte spl1->setMode(Draw::Modeling); id = data->AddGObject(spl1); VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, drawName, idTool); - - delete p4; - delete p1; } break; case (Tool::NodeSplinePath): @@ -361,7 +358,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const const QSharedPointer arc = data->GeometricObject(det.at(i).getId()); VPointF p1 = VPointF(arc->GetP1()); VPointF p2 = VPointF(arc->GetP2()); - VPointF *center = new VPointF(arc->GetCenter()); + QScopedPointer center(new VPointF(arc->GetCenter())); if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) { @@ -369,7 +366,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const BiasRotatePoint(&p1, dx, dy, p, angle); BiasRotatePoint(&p2, dx, dy, p, angle); - BiasRotatePoint(center, dx, dy, p, angle); + BiasRotatePoint(center.data(), dx, dy, p, angle); } QLineF l1(*center, p1); @@ -379,7 +376,6 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const QString().setNum(l1.angle()), l2.angle(), QString().setNum(l2.angle())); arc1->setMode(Draw::Modeling); data->UpdateGObject(TakeNextId(children), arc1); - delete center; } break; case (Tool::NodeElArc): @@ -387,7 +383,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const const QSharedPointer arc = data->GeometricObject(det.at(i).getId()); VPointF p1 = VPointF(arc->GetP1()); VPointF p2 = VPointF(arc->GetP2()); - VPointF *center = new VPointF(arc->GetCenter()); + QScopedPointer center(new VPointF(arc->GetCenter())); if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) { @@ -395,7 +391,7 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const BiasRotatePoint(&p1, dx, dy, p, angle); BiasRotatePoint(&p2, dx, dy, p, angle); - BiasRotatePoint(center, dx, dy, p, angle); + BiasRotatePoint(center.data(), dx, dy, p, angle); } QLineF l1(*center, p1); @@ -407,7 +403,6 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const QString().setNum(l2.angle()), 0, "0"); arc1->setMode(Draw::Modeling); data->UpdateGObject(TakeNextId(children), arc1); - delete center; } break; case (Tool::NodeSpline): @@ -415,25 +410,23 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); - VPointF *p1 = new VPointF(spline->GetP1()); + QScopedPointer p1(new VPointF(spline->GetP1())); VPointF p2 = VPointF(spline->GetP2()); VPointF p3 = VPointF(spline->GetP3()); - VPointF *p4 = new VPointF(spline->GetP4()); + QScopedPointer p4(new VPointF(spline->GetP4())); if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) { const QPointF p = *data->GeometricObject(pRotate); - BiasRotatePoint(p1, dx, dy, p, angle); + BiasRotatePoint(p1.data(), dx, dy, p, angle); BiasRotatePoint(&p2, dx, dy, p, angle); BiasRotatePoint(&p3, dx, dy, p, angle); - BiasRotatePoint(p4, dx, dy, p, angle); + BiasRotatePoint(p4.data(), dx, dy, p, angle); } VSpline *spl = new VSpline(*p1, p2, p3, *p4, 0, Draw::Modeling); data->UpdateGObject(TakeNextId(children), spl); - delete p1; - delete p4; } break; case (Tool::NodeSplinePath): @@ -447,19 +440,19 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const { const VSpline spline = splinePath->GetSpline(i); - VPointF *p1 = new VPointF(spline.GetP1()); + QScopedPointer p1(new VPointF(spline.GetP1())); VPointF p2 = VPointF(spline.GetP2()); VPointF p3 = VPointF(spline.GetP3()); - VPointF *p4 = new VPointF(spline.GetP4()); + QScopedPointer p4(new VPointF(spline.GetP4())); if (not qFuzzyIsNull(dx) || not qFuzzyIsNull(dy) || pRotate != NULL_ID) { const QPointF p = *data->GeometricObject(pRotate); - BiasRotatePoint(p1, dx, dy, p, angle); + BiasRotatePoint(p1.data(), dx, dy, p, angle); BiasRotatePoint(&p2, dx, dy, p, angle); BiasRotatePoint(&p3, dx, dy, p, angle); - BiasRotatePoint(p4, dx, dy, p, angle); + BiasRotatePoint(p4.data(), dx, dy, p, angle); } VSpline spl = VSpline(*p1, p2, p3, *p4); @@ -486,9 +479,6 @@ void VToolUnionDetails::UpdatePoints(VContainer *data, const VDetail &det, const path->append(VSplinePoint(*p4, spl.GetEndAngle(), spl.GetEndAngleFormula(), angle2, angle2F, spline.GetC2Length(), spline.GetC2LengthFormula(), pL2, pL2F)); - - delete p1; - delete p4; } data->UpdateGObject(TakeNextId(children), path); }