Refactoring deleting visualization object.

Instead of searcing inside current graphics scene use QPointer class.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-07-07 14:56:55 +03:00
parent 628fdd4217
commit bd7f328a8a
31 changed files with 7 additions and 47 deletions

View File

@ -142,7 +142,6 @@ DialogAlongLine::~DialogAlongLine()
VContainer *locData = const_cast<VContainer *> (data); VContainer *locData = const_cast<VContainer *> (data);
locData->RemoveVariable(currentLength); locData->RemoveVariable(currentLength);
DeleteVisualization<VisToolAlongLine>();
delete ui; delete ui;
} }

View File

@ -113,7 +113,6 @@ void DialogArc::DeployF2TextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogArc::~DialogArc() DialogArc::~DialogArc()
{ {
DeleteVisualization<VisToolArc>();
delete ui; delete ui;
} }

View File

@ -90,7 +90,6 @@ DialogArcWithLength::DialogArcWithLength(const VContainer *data, const quint32 &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogArcWithLength::~DialogArcWithLength() DialogArcWithLength::~DialogArcWithLength()
{ {
DeleteVisualization<VisToolArcWithLength>();
delete ui; delete ui;
} }

View File

@ -142,7 +142,6 @@ void DialogBisector::DeployFormulaTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogBisector::~DialogBisector() DialogBisector::~DialogBisector()
{ {
DeleteVisualization<VisToolBisector>();
delete ui; delete ui;
} }

View File

@ -63,7 +63,6 @@ DialogCubicBezier::DialogCubicBezier(const VContainer *data, const quint32 &tool
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogCubicBezier::~DialogCubicBezier() DialogCubicBezier::~DialogCubicBezier()
{ {
DeleteVisualization<VisToolCubicBezier>();
delete ui; delete ui;
} }

View File

@ -61,7 +61,6 @@ DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, const quint
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogCubicBezierPath::~DialogCubicBezierPath() DialogCubicBezierPath::~DialogCubicBezierPath()
{ {
DeleteVisualization<VisToolCubicBezierPath>();
delete ui; delete ui;
} }

View File

@ -77,7 +77,6 @@ DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogCurveIntersectAxis::~DialogCurveIntersectAxis() DialogCurveIntersectAxis::~DialogCurveIntersectAxis()
{ {
DeleteVisualization<VisToolCurveIntersectAxis>();
delete ui; delete ui;
} }

View File

@ -106,7 +106,6 @@ void DialogCutArc::DeployFormulaTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogCutArc::~DialogCutArc() DialogCutArc::~DialogCutArc()
{ {
DeleteVisualization<VisToolCutArc>();
delete ui; delete ui;
} }

View File

@ -73,7 +73,6 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId,
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogCutSpline::~DialogCutSpline() DialogCutSpline::~DialogCutSpline()
{ {
DeleteVisualization<VisToolCutSpline>();
delete ui; delete ui;
} }

View File

@ -73,7 +73,6 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogCutSplinePath::~DialogCutSplinePath() DialogCutSplinePath::~DialogCutSplinePath()
{ {
DeleteVisualization<VisToolCutSplinePath>();
delete ui; delete ui;
} }

View File

@ -167,7 +167,7 @@ void DialogEndLine::ChosenObject(quint32 id, const SceneObject &type)
if (SetObject(id, ui->comboBoxBasePoint, "")) if (SetObject(id, ui->comboBoxBasePoint, ""))
{ {
vis->VisualMode(id); vis->VisualMode(id);
connect(vis, &Visualization::ToolTip, this, &DialogTool::ShowVisToolTip); connect(vis.data(), &Visualization::ToolTip, this, &DialogTool::ShowVisToolTip);
prepare = true; prepare = true;
} }
} }
@ -343,7 +343,6 @@ void DialogEndLine::closeEvent(QCloseEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogEndLine::~DialogEndLine() DialogEndLine::~DialogEndLine()
{ {
DeleteVisualization<VisToolEndLine>();
delete ui; delete ui;
} }

View File

@ -75,7 +75,6 @@ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidge
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogHeight::~DialogHeight() DialogHeight::~DialogHeight()
{ {
DeleteVisualization<VisToolHeight>();
delete ui; delete ui;
} }

View File

@ -68,7 +68,6 @@ DialogLine::DialogLine(const VContainer *data, const quint32 &toolId, QWidget *p
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogLine::~DialogLine() DialogLine::~DialogLine()
{ {
DeleteVisualization<VisToolLine>();
delete ui; delete ui;
} }

View File

@ -75,7 +75,6 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogLineIntersect::~DialogLineIntersect() DialogLineIntersect::~DialogLineIntersect()
{ {
DeleteVisualization<VisToolLineIntersect>();
delete ui; delete ui;
} }

View File

@ -86,7 +86,6 @@ DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const q
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogLineIntersectAxis::~DialogLineIntersectAxis() DialogLineIntersectAxis::~DialogLineIntersectAxis()
{ {
DeleteVisualization<VisToolLineIntersectAxis>();
delete ui; delete ui;
} }

View File

@ -132,7 +132,6 @@ void DialogNormal::DeployFormulaTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogNormal::~DialogNormal() DialogNormal::~DialogNormal()
{ {
DeleteVisualization<VisToolNormal>();
delete ui; delete ui;
} }

View File

@ -63,7 +63,6 @@ DialogPointFromArcAndTangent::DialogPointFromArcAndTangent(const VContainer *dat
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPointFromArcAndTangent::~DialogPointFromArcAndTangent() DialogPointFromArcAndTangent::~DialogPointFromArcAndTangent()
{ {
DeleteVisualization<VisToolPointFromArcAndTangent>();
delete ui; delete ui;
} }

View File

@ -88,7 +88,6 @@ DialogPointFromCircleAndTangent::DialogPointFromCircleAndTangent(const VContaine
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPointFromCircleAndTangent::~DialogPointFromCircleAndTangent() DialogPointFromCircleAndTangent::~DialogPointFromCircleAndTangent()
{ {
DeleteVisualization<VisToolPointFromCircleAndTangent>();
delete ui; delete ui;
} }

View File

@ -81,7 +81,6 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPointOfContact::~DialogPointOfContact() DialogPointOfContact::~DialogPointOfContact()
{ {
DeleteVisualization<VisToolPointOfContact>();
delete ui; delete ui;
} }

View File

@ -71,7 +71,6 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, con
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPointOfIntersection::~DialogPointOfIntersection() DialogPointOfIntersection::~DialogPointOfIntersection()
{ {
DeleteVisualization<VisToolPointOfIntersection>();
delete ui; delete ui;
} }

View File

@ -67,7 +67,6 @@ DialogPointOfIntersectionArcs::DialogPointOfIntersectionArcs(const VContainer *d
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPointOfIntersectionArcs::~DialogPointOfIntersectionArcs() DialogPointOfIntersectionArcs::~DialogPointOfIntersectionArcs()
{ {
DeleteVisualization<VisToolPointOfIntersectionArcs>();
delete ui; delete ui;
} }

View File

@ -104,7 +104,6 @@ DialogPointOfIntersectionCircles::DialogPointOfIntersectionCircles(const VContai
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPointOfIntersectionCircles::~DialogPointOfIntersectionCircles() DialogPointOfIntersectionCircles::~DialogPointOfIntersectionCircles()
{ {
DeleteVisualization<VisToolPointOfIntersectionCircles>();
delete ui; delete ui;
} }

View File

@ -65,7 +65,6 @@ DialogPointOfIntersectionCurves::DialogPointOfIntersectionCurves(const VContaine
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogPointOfIntersectionCurves::~DialogPointOfIntersectionCurves() DialogPointOfIntersectionCurves::~DialogPointOfIntersectionCurves()
{ {
DeleteVisualization<VisToolPointOfIntersectionCurves>();
delete ui; delete ui;
} }

View File

@ -81,7 +81,6 @@ DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QW
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogRotation::~DialogRotation() DialogRotation::~DialogRotation()
{ {
DeleteVisualization<VisToolRotation>();
delete ui; delete ui;
} }

View File

@ -143,7 +143,6 @@ void DialogShoulderPoint::DeployFormulaTextEdit()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogShoulderPoint::~DialogShoulderPoint() DialogShoulderPoint::~DialogShoulderPoint()
{ {
DeleteVisualization<VisToolShoulderPoint>();
delete ui; delete ui;
} }

View File

@ -122,7 +122,6 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogSpline::~DialogSpline() DialogSpline::~DialogSpline()
{ {
DeleteVisualization<VisToolSpline>();
delete ui; delete ui;
} }

View File

@ -108,7 +108,6 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogSplinePath::~DialogSplinePath() DialogSplinePath::~DialogSplinePath()
{ {
DeleteVisualization<VisToolSplinePath>();
delete ui; delete ui;
} }

View File

@ -78,6 +78,11 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p
DialogTool::~DialogTool() DialogTool::~DialogTool()
{ {
emit ToolTip(""); emit ToolTip("");
if (not vis.isNull())
{
delete vis;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -181,7 +181,7 @@ protected:
/** @brief number number of handled objects */ /** @brief number number of handled objects */
qint32 number; qint32 number;
Visualization *vis; QPointer<Visualization> vis;
virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE; virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE;
virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE; virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE;
@ -241,9 +241,6 @@ protected:
template <typename T> template <typename T>
void AddVisualization(); void AddVisualization();
template <typename T>
void DeleteVisualization();
void ChangeColor(QWidget *widget, const QColor &color); void ChangeColor(QWidget *widget, const QColor &color);
virtual void ShowVisualization() {} virtual void ShowVisualization() {}
/** /**
@ -360,19 +357,6 @@ inline void DialogTool::AddVisualization()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void DialogTool::DeleteVisualization()
{
T *toolVis = qobject_cast<T *>(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 <typename T> template <typename T>
inline T DialogTool::getCurrentCrossPoint(QComboBox *box) const inline T DialogTool::getCurrentCrossPoint(QComboBox *box) const

View File

@ -75,7 +75,6 @@ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QW
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogTriangle::~DialogTriangle() DialogTriangle::~DialogTriangle()
{ {
DeleteVisualization<VisToolTriangle>();
delete ui; delete ui;
} }

View File

@ -80,7 +80,6 @@ DialogTrueDarts::DialogTrueDarts(const VContainer *data, const quint32 &toolId,
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogTrueDarts::~DialogTrueDarts() DialogTrueDarts::~DialogTrueDarts()
{ {
DeleteVisualization<VisToolTrueDarts>();
delete ui; delete ui;
} }