From bd7f328a8a9081470cb437a426477a57efe016a0 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 7 Jul 2016 14:56:55 +0300 Subject: [PATCH] Refactoring deleting visualization object. Instead of searcing inside current graphics scene use QPointer class. --HG-- branch : develop --- .../vtools/dialogs/tools/dialogalongline.cpp | 1 - src/libs/vtools/dialogs/tools/dialogarc.cpp | 1 - .../dialogs/tools/dialogarcwithlength.cpp | 1 - .../vtools/dialogs/tools/dialogbisector.cpp | 1 - .../vtools/dialogs/tools/dialogcubicbezier.cpp | 1 - .../dialogs/tools/dialogcubicbezierpath.cpp | 1 - .../dialogs/tools/dialogcurveintersectaxis.cpp | 1 - src/libs/vtools/dialogs/tools/dialogcutarc.cpp | 1 - .../vtools/dialogs/tools/dialogcutspline.cpp | 1 - .../dialogs/tools/dialogcutsplinepath.cpp | 1 - .../vtools/dialogs/tools/dialogendline.cpp | 3 +-- src/libs/vtools/dialogs/tools/dialogheight.cpp | 1 - src/libs/vtools/dialogs/tools/dialogline.cpp | 1 - .../dialogs/tools/dialoglineintersect.cpp | 1 - .../dialogs/tools/dialoglineintersectaxis.cpp | 1 - src/libs/vtools/dialogs/tools/dialognormal.cpp | 1 - .../tools/dialogpointfromarcandtangent.cpp | 1 - .../tools/dialogpointfromcircleandtangent.cpp | 1 - .../dialogs/tools/dialogpointofcontact.cpp | 1 - .../tools/dialogpointofintersection.cpp | 1 - .../tools/dialogpointofintersectionarcs.cpp | 1 - .../tools/dialogpointofintersectioncircles.cpp | 1 - .../tools/dialogpointofintersectioncurves.cpp | 1 - .../vtools/dialogs/tools/dialogrotation.cpp | 1 - .../dialogs/tools/dialogshoulderpoint.cpp | 1 - src/libs/vtools/dialogs/tools/dialogspline.cpp | 1 - .../vtools/dialogs/tools/dialogsplinepath.cpp | 1 - src/libs/vtools/dialogs/tools/dialogtool.cpp | 5 +++++ src/libs/vtools/dialogs/tools/dialogtool.h | 18 +----------------- .../vtools/dialogs/tools/dialogtriangle.cpp | 1 - .../vtools/dialogs/tools/dialogtruedarts.cpp | 1 - 31 files changed, 7 insertions(+), 47 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index f9ddcb36d..117e03e1a 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -142,7 +142,6 @@ DialogAlongLine::~DialogAlongLine() VContainer *locData = const_cast (data); locData->RemoveVariable(currentLength); - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index 28b4e8e5a..38e592113 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -113,7 +113,6 @@ void DialogArc::DeployF2TextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogArc::~DialogArc() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index 294aef428..46dae81de 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -90,7 +90,6 @@ DialogArcWithLength::DialogArcWithLength(const VContainer *data, const quint32 & //--------------------------------------------------------------------------------------------------------------------- DialogArcWithLength::~DialogArcWithLength() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogbisector.cpp b/src/libs/vtools/dialogs/tools/dialogbisector.cpp index 88b8313f0..d8e7d08ac 100644 --- a/src/libs/vtools/dialogs/tools/dialogbisector.cpp +++ b/src/libs/vtools/dialogs/tools/dialogbisector.cpp @@ -142,7 +142,6 @@ void DialogBisector::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogBisector::~DialogBisector() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp index c33761b7e..0f4103100 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp @@ -63,7 +63,6 @@ DialogCubicBezier::DialogCubicBezier(const VContainer *data, const quint32 &tool //--------------------------------------------------------------------------------------------------------------------- DialogCubicBezier::~DialogCubicBezier() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index a53098c78..ef7e22793 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -61,7 +61,6 @@ DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, const quint //--------------------------------------------------------------------------------------------------------------------- DialogCubicBezierPath::~DialogCubicBezierPath() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp index 52ab4aa38..b645fa884 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp @@ -77,7 +77,6 @@ DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, const //--------------------------------------------------------------------------------------------------------------------- DialogCurveIntersectAxis::~DialogCurveIntersectAxis() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index c247013aa..531e3da96 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -106,7 +106,6 @@ void DialogCutArc::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogCutArc::~DialogCutArc() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index fe6f2ffc7..f5c8a46a2 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -73,7 +73,6 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, //--------------------------------------------------------------------------------------------------------------------- DialogCutSpline::~DialogCutSpline() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index 181f958c2..d240740bc 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -73,7 +73,6 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & //--------------------------------------------------------------------------------------------------------------------- DialogCutSplinePath::~DialogCutSplinePath() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogendline.cpp b/src/libs/vtools/dialogs/tools/dialogendline.cpp index e1a921897..dd668813e 100644 --- a/src/libs/vtools/dialogs/tools/dialogendline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogendline.cpp @@ -167,7 +167,7 @@ void DialogEndLine::ChosenObject(quint32 id, const SceneObject &type) if (SetObject(id, ui->comboBoxBasePoint, "")) { vis->VisualMode(id); - connect(vis, &Visualization::ToolTip, this, &DialogTool::ShowVisToolTip); + connect(vis.data(), &Visualization::ToolTip, this, &DialogTool::ShowVisToolTip); prepare = true; } } @@ -343,7 +343,6 @@ void DialogEndLine::closeEvent(QCloseEvent *event) //--------------------------------------------------------------------------------------------------------------------- DialogEndLine::~DialogEndLine() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogheight.cpp b/src/libs/vtools/dialogs/tools/dialogheight.cpp index 81e0b40b8..9cb4fad5d 100644 --- a/src/libs/vtools/dialogs/tools/dialogheight.cpp +++ b/src/libs/vtools/dialogs/tools/dialogheight.cpp @@ -75,7 +75,6 @@ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidge //--------------------------------------------------------------------------------------------------------------------- DialogHeight::~DialogHeight() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogline.cpp b/src/libs/vtools/dialogs/tools/dialogline.cpp index 10a908252..298937b69 100644 --- a/src/libs/vtools/dialogs/tools/dialogline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogline.cpp @@ -68,7 +68,6 @@ DialogLine::DialogLine(const VContainer *data, const quint32 &toolId, QWidget *p //--------------------------------------------------------------------------------------------------------------------- DialogLine::~DialogLine() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp b/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp index 0688571d1..5fe9c1f4b 100644 --- a/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp +++ b/src/libs/vtools/dialogs/tools/dialoglineintersect.cpp @@ -75,7 +75,6 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 & //--------------------------------------------------------------------------------------------------------------------- DialogLineIntersect::~DialogLineIntersect() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp index a61a6e3d0..7f6b56f61 100644 --- a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp @@ -86,7 +86,6 @@ DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const q //--------------------------------------------------------------------------------------------------------------------- DialogLineIntersectAxis::~DialogLineIntersectAxis() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialognormal.cpp b/src/libs/vtools/dialogs/tools/dialognormal.cpp index d219318fd..11505b5b4 100644 --- a/src/libs/vtools/dialogs/tools/dialognormal.cpp +++ b/src/libs/vtools/dialogs/tools/dialognormal.cpp @@ -132,7 +132,6 @@ void DialogNormal::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogNormal::~DialogNormal() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogpointfromarcandtangent.cpp b/src/libs/vtools/dialogs/tools/dialogpointfromarcandtangent.cpp index 70899b26b..b35e26fcf 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointfromarcandtangent.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointfromarcandtangent.cpp @@ -63,7 +63,6 @@ DialogPointFromArcAndTangent::DialogPointFromArcAndTangent(const VContainer *dat //--------------------------------------------------------------------------------------------------------------------- DialogPointFromArcAndTangent::~DialogPointFromArcAndTangent() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp index 9b0d84830..ed7ce0ac8 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp @@ -88,7 +88,6 @@ DialogPointFromCircleAndTangent::DialogPointFromCircleAndTangent(const VContaine //--------------------------------------------------------------------------------------------------------------------- DialogPointFromCircleAndTangent::~DialogPointFromCircleAndTangent() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp index e20065ab2..29d367c0e 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp @@ -81,7 +81,6 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 //--------------------------------------------------------------------------------------------------------------------- DialogPointOfContact::~DialogPointOfContact() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersection.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersection.cpp index dc62a0b03..869af1e5e 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersection.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersection.cpp @@ -71,7 +71,6 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, con //--------------------------------------------------------------------------------------------------------------------- DialogPointOfIntersection::~DialogPointOfIntersection() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectionarcs.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectionarcs.cpp index 08e2d66a9..00b31ca68 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectionarcs.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectionarcs.cpp @@ -67,7 +67,6 @@ DialogPointOfIntersectionArcs::DialogPointOfIntersectionArcs(const VContainer *d //--------------------------------------------------------------------------------------------------------------------- DialogPointOfIntersectionArcs::~DialogPointOfIntersectionArcs() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp index 90abbd364..d43be12c0 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp @@ -104,7 +104,6 @@ DialogPointOfIntersectionCircles::DialogPointOfIntersectionCircles(const VContai //--------------------------------------------------------------------------------------------------------------------- DialogPointOfIntersectionCircles::~DialogPointOfIntersectionCircles() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp index c6c09102c..2a0bb2e9b 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncurves.cpp @@ -65,7 +65,6 @@ DialogPointOfIntersectionCurves::DialogPointOfIntersectionCurves(const VContaine //--------------------------------------------------------------------------------------------------------------------- DialogPointOfIntersectionCurves::~DialogPointOfIntersectionCurves() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index 8af42964d..08c8f33ae 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -81,7 +81,6 @@ DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QW //--------------------------------------------------------------------------------------------------------------------- DialogRotation::~DialogRotation() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp index 79f4ff42b..881944dd8 100644 --- a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp @@ -143,7 +143,6 @@ void DialogShoulderPoint::DeployFormulaTextEdit() //--------------------------------------------------------------------------------------------------------------------- DialogShoulderPoint::~DialogShoulderPoint() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index ffd05e80d..cc74e38e2 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -122,7 +122,6 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge //--------------------------------------------------------------------------------------------------------------------- DialogSpline::~DialogSpline() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 338f00ce6..ed4a3eb50 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -108,7 +108,6 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId //--------------------------------------------------------------------------------------------------------------------- DialogSplinePath::~DialogSplinePath() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index af36c41af..1515c9af8 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -78,6 +78,11 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p DialogTool::~DialogTool() { emit ToolTip(""); + + if (not vis.isNull()) + { + delete vis; + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogtool.h b/src/libs/vtools/dialogs/tools/dialogtool.h index ee47436bc..1a5a0ee78 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.h +++ b/src/libs/vtools/dialogs/tools/dialogtool.h @@ -181,7 +181,7 @@ protected: /** @brief number number of handled objects */ qint32 number; - Visualization *vis; + QPointer vis; virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE; virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE; @@ -241,9 +241,6 @@ protected: template void AddVisualization(); - template - void DeleteVisualization(); - void ChangeColor(QWidget *widget, const QColor &color); virtual void ShowVisualization() {} /** @@ -360,19 +357,6 @@ inline void DialogTool::AddVisualization() } } -//--------------------------------------------------------------------------------------------------------------------- -template -inline void DialogTool::DeleteVisualization() -{ - T *toolVis = qobject_cast(vis); - SCASSERT(toolVis != nullptr); - - if (qApp->getCurrentScene()->items().contains(toolVis)) - { // In some cases scene delete object yourself. If not make check program will crash. - delete vis; - } -} - //--------------------------------------------------------------------------------------------------------------------- template inline T DialogTool::getCurrentCrossPoint(QComboBox *box) const diff --git a/src/libs/vtools/dialogs/tools/dialogtriangle.cpp b/src/libs/vtools/dialogs/tools/dialogtriangle.cpp index 4076937cf..248390888 100644 --- a/src/libs/vtools/dialogs/tools/dialogtriangle.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtriangle.cpp @@ -75,7 +75,6 @@ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QW //--------------------------------------------------------------------------------------------------------------------- DialogTriangle::~DialogTriangle() { - DeleteVisualization(); delete ui; } diff --git a/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp b/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp index ba909e210..cb8c310b4 100644 --- a/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtruedarts.cpp @@ -80,7 +80,6 @@ DialogTrueDarts::DialogTrueDarts(const VContainer *data, const quint32 &toolId, //--------------------------------------------------------------------------------------------------------------------- DialogTrueDarts::~DialogTrueDarts() { - DeleteVisualization(); delete ui; }