Fix crash. Each tool should delete visualization even if scene also can delete

it.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-09-24 16:09:09 +03:00
parent 2b26b986bc
commit eee2144483
37 changed files with 47 additions and 47 deletions

View File

@ -174,7 +174,7 @@ void VToolFlippingByAxis::ShowVisualization(bool show)
//---------------------------------------------------------------------------------------------------------------------
void VToolFlippingByAxis::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolFlippingByAxis *visual = qobject_cast<VisToolFlippingByAxis *>(vis);
SCASSERT(visual != nullptr);

View File

@ -154,7 +154,7 @@ void VToolFlippingByLine::ShowVisualization(bool show)
//---------------------------------------------------------------------------------------------------------------------
void VToolFlippingByLine::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolFlippingByLine *visual = qobject_cast<VisToolFlippingByLine *>(vis);
SCASSERT(visual != nullptr);

View File

@ -156,7 +156,7 @@ void VAbstractOperation::ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
if (vis.isNull())
{
AddVisualization<T>();
SetVisualization();
@ -172,7 +172,6 @@ void VAbstractOperation::ShowToolVisualization(bool show)
else
{
delete vis;
vis = nullptr;
}
}

View File

@ -285,7 +285,7 @@ void VToolRotation::ShowVisualization(bool show)
//---------------------------------------------------------------------------------------------------------------------
void VToolRotation::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolRotation *visual = qobject_cast<VisToolRotation *>(vis);
SCASSERT(visual != nullptr);

View File

@ -144,7 +144,7 @@ inline void VAbstractSpline::ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
if (vis.isNull())
{
AddVisualization<T>();
SetVisualization();
@ -160,7 +160,6 @@ inline void VAbstractSpline::ShowToolVisualization(bool show)
else
{
delete vis;
vis = nullptr;
}
if (detailsMode)

View File

@ -365,7 +365,7 @@ void VToolArc::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &obj)
//---------------------------------------------------------------------------------------------------------------------
void VToolArc::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
const QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(id);
VisToolArc *visual = qobject_cast<VisToolArc *>(vis);

View File

@ -322,7 +322,7 @@ void VToolArcWithLength::SaveOptions(QDomElement &tag, QSharedPointer<VGObject>
//---------------------------------------------------------------------------------------------------------------------
void VToolArcWithLength::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
const QSharedPointer<VArc> arc = VAbstractTool::data.GeometricObject<VArc>(id);
VisToolArcWithLength *visual = qobject_cast<VisToolArcWithLength *>(vis);

View File

@ -216,7 +216,7 @@ void VToolCubicBezier::SaveOptions(QDomElement &tag, QSharedPointer<VGObject> &o
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezier::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
auto visual = qobject_cast<VisToolCubicBezier *>(vis);
SCASSERT(visual != nullptr);

View File

@ -226,7 +226,7 @@ void VToolCubicBezierPath::SaveOptions(QDomElement &tag, QSharedPointer<VGObject
//---------------------------------------------------------------------------------------------------------------------
void VToolCubicBezierPath::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
auto visual = qobject_cast<VisToolCubicBezierPath *>(vis);
SCASSERT(visual != nullptr);

View File

@ -500,7 +500,7 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VToolSpline::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolSpline *visual = qobject_cast<VisToolSpline *>(vis);
SCASSERT(visual != nullptr);

View File

@ -621,7 +621,7 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void VToolSplinePath::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolSplinePath *visual = qobject_cast<VisToolSplinePath *>(vis);
SCASSERT(visual != nullptr);

View File

@ -376,7 +376,7 @@ void VToolTrueDarts::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolTrueDarts::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolTrueDarts *visual = qobject_cast<VisToolTrueDarts *>(vis);
SCASSERT(visual != nullptr);

View File

@ -89,7 +89,7 @@ inline void VToolCut::ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
if (vis.isNull())
{
AddVisualization<T>();
SetVisualization();
@ -105,7 +105,6 @@ inline void VToolCut::ShowToolVisualization(bool show)
else
{
delete vis;
vis = nullptr;
}
if (VAbstractSpline *parentCurve = qobject_cast<VAbstractSpline *>(doc->getTool(curveCutId)))
{

View File

@ -241,7 +241,7 @@ void VToolCutArc::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolCutArc::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolCutArc *visual = qobject_cast<VisToolCutArc *>(vis);
SCASSERT(visual != nullptr);

View File

@ -241,7 +241,7 @@ void VToolCutSpline::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolCutSpline::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolCutSpline *visual = qobject_cast<VisToolCutSpline *>(vis);
SCASSERT(visual != nullptr);

View File

@ -329,7 +329,7 @@ void VToolCutSplinePath::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolCutSplinePath::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolCutSplinePath *visual = qobject_cast<VisToolCutSplinePath *>(vis);
SCASSERT(visual != nullptr);

View File

@ -164,7 +164,7 @@ void VToolAlongLine::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolAlongLine::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolAlongLine *visual = qobject_cast<VisToolAlongLine *>(vis);
SCASSERT(visual != nullptr)

View File

@ -320,7 +320,7 @@ void VToolBisector::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolBisector::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolBisector *visual = qobject_cast<VisToolBisector *>(vis);
SCASSERT(visual != nullptr);

View File

@ -313,7 +313,7 @@ void VToolCurveIntersectAxis::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolCurveIntersectAxis::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolCurveIntersectAxis *visual = qobject_cast<VisToolCurveIntersectAxis *>(vis);
SCASSERT(visual != nullptr);

View File

@ -254,7 +254,7 @@ void VToolEndLine::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolEndLine::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolEndLine *visual = qobject_cast<VisToolEndLine *>(vis);
SCASSERT(visual != nullptr);

View File

@ -261,7 +261,7 @@ void VToolHeight::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolHeight::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolHeight *visual = qobject_cast<VisToolHeight *>(vis);
SCASSERT(visual != nullptr);

View File

@ -313,7 +313,7 @@ void VToolLineIntersectAxis::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolLineIntersectAxis::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolLineIntersectAxis *visual = qobject_cast<VisToolLineIntersectAxis *>(vis);
SCASSERT(visual != nullptr);

View File

@ -295,7 +295,7 @@ void VToolNormal::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolNormal::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolNormal *visual = qobject_cast<VisToolNormal *>(vis);
SCASSERT(visual != nullptr);

View File

@ -326,7 +326,7 @@ void VToolShoulderPoint::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolShoulderPoint::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolShoulderPoint *visual = qobject_cast<VisToolShoulderPoint *>(vis);
SCASSERT(visual != nullptr);

View File

@ -286,7 +286,7 @@ void VToolLineIntersect::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolLineIntersect::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolLineIntersect *visual = qobject_cast<VisToolLineIntersect *>(vis);
SCASSERT(visual != nullptr);
@ -295,7 +295,7 @@ void VToolLineIntersect::SetVisualization()
visual->setLine1P2Id(p2Line1);
visual->setLine2P1Id(p1Line2);
visual->setLine2P2Id(p2Line2);
vis->RefreshGeometry();
visual->RefreshGeometry();
}
}

View File

@ -336,7 +336,7 @@ void VToolPointFromArcAndTangent::ReadToolAttributes(const QDomElement &domEleme
//---------------------------------------------------------------------------------------------------------------------
void VToolPointFromArcAndTangent::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolPointFromArcAndTangent *visual = qobject_cast<VisToolPointFromArcAndTangent *>(vis);
SCASSERT(visual != nullptr);

View File

@ -323,7 +323,7 @@ void VToolPointFromCircleAndTangent::ReadToolAttributes(const QDomElement &domEl
//---------------------------------------------------------------------------------------------------------------------
void VToolPointFromCircleAndTangent::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolPointFromCircleAndTangent *visual = qobject_cast<VisToolPointFromCircleAndTangent *>(vis);
SCASSERT(visual != nullptr);

View File

@ -339,7 +339,7 @@ void VToolPointOfContact::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolPointOfContact::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolPointOfContact *visual = qobject_cast<VisToolPointOfContact *>(vis);
SCASSERT(visual != nullptr);

View File

@ -237,7 +237,7 @@ void VToolPointOfIntersection::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolPointOfIntersection::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolPointOfIntersection *visual = qobject_cast<VisToolPointOfIntersection *>(vis);
SCASSERT(visual != nullptr);

View File

@ -341,7 +341,7 @@ void VToolPointOfIntersectionArcs::ReadToolAttributes(const QDomElement &domElem
//---------------------------------------------------------------------------------------------------------------------
void VToolPointOfIntersectionArcs::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolPointOfIntersectionArcs *visual = qobject_cast<VisToolPointOfIntersectionArcs *>(vis);
SCASSERT(visual != nullptr);

View File

@ -362,7 +362,7 @@ void VToolPointOfIntersectionCircles::ReadToolAttributes(const QDomElement &domE
//---------------------------------------------------------------------------------------------------------------------
void VToolPointOfIntersectionCircles::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolPointOfIntersectionCircles *visual = qobject_cast<VisToolPointOfIntersectionCircles *>(vis);
SCASSERT(visual != nullptr);

View File

@ -404,7 +404,7 @@ void VToolPointOfIntersectionCurves::ReadToolAttributes(const QDomElement &domEl
//---------------------------------------------------------------------------------------------------------------------
void VToolPointOfIntersectionCurves::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
auto visual = qobject_cast<VisToolPointOfIntersectionCurves *>(vis);
SCASSERT(visual != nullptr);

View File

@ -307,7 +307,7 @@ void VToolTriangle::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolTriangle::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolTriangle * visual = qobject_cast<VisToolTriangle *>(vis);
SCASSERT(visual != nullptr);

View File

@ -95,7 +95,7 @@ void VAbstractPoint::ShowToolVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
if (vis.isNull())
{
AddVisualization<T>();
SetVisualization();
@ -111,7 +111,6 @@ void VAbstractPoint::ShowToolVisualization(bool show)
else
{
delete vis;
vis = nullptr;
}
}

View File

@ -319,7 +319,7 @@ void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
if (vis == nullptr)
if (vis.isNull())
{
this->setPen(QPen(CorrectColor(lineColor),
qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit()))/factor,
@ -421,7 +421,7 @@ void VToolLine::ReadToolAttributes(const QDomElement &domElement)
//---------------------------------------------------------------------------------------------------------------------
void VToolLine::SetVisualization()
{
if (vis != nullptr)
if (not vis.isNull())
{
VisToolLine *visual = qobject_cast<VisToolLine *>(vis);
SCASSERT(visual != nullptr);
@ -456,7 +456,7 @@ void VToolLine::ShowVisualization(bool show)
{
if (show)
{
if (vis == nullptr)
if (vis.isNull())
{
AddVisualization<VisToolLine>();
SetVisualization();
@ -472,7 +472,6 @@ void VToolLine::ShowVisualization(bool show)
else
{
delete vis;
vis = nullptr;
hoverLeaveEvent(nullptr);
}
}

View File

@ -83,7 +83,7 @@ const QString VAbstractTool::AttrInUse = QStringLiteral("inUse");
* @param parent parent object.
*/
VAbstractTool::VAbstractTool(VAbstractPattern *doc, VContainer *data, quint32 id, QObject *parent)
:VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), vis(nullptr),
:VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), vis(),
selectionType(SelectionType::ByMouseRelease)
{
SCASSERT(doc != nullptr);
@ -94,7 +94,12 @@ VAbstractTool::VAbstractTool(VAbstractPattern *doc, VContainer *data, quint32 id
//---------------------------------------------------------------------------------------------------------------------
VAbstractTool::~VAbstractTool()
{}
{
if (not vis.isNull())
{
delete vis;
}
}
//---------------------------------------------------------------------------------------------------------------------
/**

View File

@ -122,7 +122,7 @@ protected:
/** @brief baseColor base color for tool. */
Qt::GlobalColor baseColor;
Visualization *vis;
QPointer<Visualization> vis;
SelectionType selectionType;
/**
@ -182,8 +182,8 @@ inline void VAbstractTool::AddVisualization()
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);
connect(visual, &Visualization::ToolTip, [=] (const QString &toolTip) {emit ToolTip(toolTip);});
vis = visual;
connect(vis, &Visualization::ToolTip, [=] (const QString &toolTip) {emit ToolTip(toolTip);});
}
#endif // VABSTRACTTOOL_H