From 345b0e5c7f946b0d4157a87e1676dc05fc5acea8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 2 Nov 2015 18:25:29 +0200 Subject: [PATCH] Fixed crash after undo creating a pattern piece. --HG-- branch : develop --- src/app/tape/mapplication.cpp | 7 ++++ src/app/valentina/core/vapplication.cpp | 7 ++++ src/libs/ifc/exception/vexception.cpp | 42 ++++++++++++++++++- src/libs/ifc/exception/vexception.h | 19 +++++++-- .../drawTools/toolcurve/vabstractspline.cpp | 12 +++++- .../tools/drawTools/toolcurve/vtoolarc.cpp | 16 +++++-- .../toolcurve/vtoolarcwithlength.cpp | 16 +++++-- .../tools/drawTools/toolcurve/vtoolspline.cpp | 14 +++++-- .../drawTools/toolcurve/vtoolsplinepath.cpp | 10 ++++- .../tooldoublepoint/vtooldoublepoint.cpp | 12 +++++- .../tooldoublepoint/vtooltruedarts.cpp | 16 +++++-- .../toolsinglepoint/toolcut/vtoolcutarc.cpp | 14 +++++-- .../toolcut/vtoolcutspline.cpp | 10 ++++- .../toolcut/vtoolcutsplinepath.cpp | 10 ++++- .../toollinepoint/vtoolalongline.cpp | 14 +++++-- .../toollinepoint/vtoolbisector.cpp | 14 +++++-- .../toollinepoint/vtoolcurveintersectaxis.cpp | 16 +++++-- .../toollinepoint/vtoolendline.cpp | 14 +++++-- .../toollinepoint/vtoolheight.cpp | 14 +++++-- .../toollinepoint/vtoollineintersectaxis.cpp | 14 +++++-- .../toollinepoint/vtoolnormal.cpp | 14 +++++-- .../toollinepoint/vtoolshoulderpoint.cpp | 14 +++++-- .../toolsinglepoint/vtoolbasepoint.cpp | 23 ++++++---- .../toolsinglepoint/vtoollineintersect.cpp | 14 +++++-- .../vtoolpointfromarcandtangent.cpp | 14 +++++-- .../vtoolpointfromcircleandtangent.cpp | 14 +++++-- .../toolsinglepoint/vtoolpointofcontact.cpp | 14 +++++-- .../vtoolpointofintersection.cpp | 14 +++++-- .../vtoolpointofintersectionarcs.cpp | 18 +++++--- .../vtoolpointofintersectioncircles.cpp | 16 +++++-- .../toolsinglepoint/vtoolsinglepoint.cpp | 12 +++++- .../toolsinglepoint/vtooltriangle.cpp | 14 +++++-- .../drawTools/toolpoint/vabstractpoint.cpp | 10 ++++- src/libs/vtools/tools/drawTools/vdrawtool.h | 28 +++++++++---- src/libs/vtools/tools/drawTools/vtoolline.cpp | 22 ++++++++-- src/libs/vtools/tools/vabstracttool.cpp | 4 ++ src/libs/vtools/tools/vtooldetail.cpp | 38 ++++++++++++++--- 37 files changed, 468 insertions(+), 106 deletions(-) diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index d6dfdda36..a4c4c68b5 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -277,6 +277,13 @@ bool MApplication::notify(QObject *receiver, QEvent *event) qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); exit(V_EX_DATAERR); } + catch (const VExceptionToolWasDeleted &e) + { + qCCritical(mApp, "%s\n\n%s\n\n%s", + qUtf8Printable("Unhadled deleting tool. Continue use object after deleting!"), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + exit(V_EX_DATAERR); + } catch (const VException &e) { qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 96a2eb350..7735ff1ab 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -335,6 +335,13 @@ bool VApplication::notify(QObject *receiver, QEvent *event) qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); exit(V_EX_DATAERR); } + catch (const VExceptionToolWasDeleted &e) + { + qCCritical(vApp, "%s\n\n%s\n\n%s", + qUtf8Printable("Unhadled deleting tool. Continue use object after deleting"), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + exit(V_EX_DATAERR); + } catch (const VException &e) { qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), diff --git a/src/libs/ifc/exception/vexception.cpp b/src/libs/ifc/exception/vexception.cpp index ee0123c2c..e50f9007b 100644 --- a/src/libs/ifc/exception/vexception.cpp +++ b/src/libs/ifc/exception/vexception.cpp @@ -42,7 +42,8 @@ * @brief VException constructor exception * @param what string with error */ -VException::VException(const QString &what):QException(), what(what), moreInfo(QString()) +VException::VException(const QString &what) V_NOEXCEPT_EXPR (true) + :QException(), what(what), moreInfo(QString()) { Q_ASSERT_X(not what.isEmpty(), Q_FUNC_INFO, "Error message is empty"); } @@ -135,3 +136,42 @@ Q_NORETURN void VException::raise() const { throw *this; } + +//-----------------------------------------VExceptionToolWasDeleted---------------------------------------------------- +VExceptionToolWasDeleted::VExceptionToolWasDeleted(const QString &what) V_NOEXCEPT_EXPR (true) + :VException(what) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionToolWasDeleted::VExceptionToolWasDeleted(const VExceptionToolWasDeleted &e) + :VException(e) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionToolWasDeleted &VExceptionToolWasDeleted::operator=(const VExceptionToolWasDeleted &e) +{ + if ( &e == this ) + { + return *this; + } + VException::operator=(e); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief raise method raise for exception + */ +// cppcheck-suppress unusedFunction +Q_NORETURN void VExceptionToolWasDeleted::VExceptionToolWasDeleted::raise() const +{ + throw *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionToolWasDeleted *VExceptionToolWasDeleted::clone() const +{ + return new VExceptionToolWasDeleted(*this); +} diff --git a/src/libs/ifc/exception/vexception.h b/src/libs/ifc/exception/vexception.h index 0c73fbacd..72213c9ff 100644 --- a/src/libs/ifc/exception/vexception.h +++ b/src/libs/ifc/exception/vexception.h @@ -34,8 +34,6 @@ #include #include "../ifcdef.h" -class QWidget; - /** * @brief The VException class parent for all exception. Could be use for abstract exception */ @@ -43,7 +41,7 @@ class VException : public QException { Q_DECLARE_TR_FUNCTIONS(VException) public: - explicit VException(const QString &what); + explicit VException(const QString &what) V_NOEXCEPT_EXPR (true); VException(const VException &e); VException &operator=(const VException &e); virtual ~VException() V_NOEXCEPT_EXPR (true) Q_DECL_OVERRIDE {} @@ -86,4 +84,19 @@ inline QString VException::MoreInformation() const return moreInfo; } +// Want have special exception for catching unhadled deleting a tool +class VExceptionToolWasDeleted : public VException +{ + Q_DECLARE_TR_FUNCTIONS(VExceptionToolDeleted) +public: + explicit VExceptionToolWasDeleted(const QString &what) V_NOEXCEPT_EXPR (true); + VExceptionToolWasDeleted(const VExceptionToolWasDeleted &e); + VExceptionToolWasDeleted &operator=(const VExceptionToolWasDeleted &e); + virtual ~VExceptionToolWasDeleted() V_NOEXCEPT_EXPR (true) Q_DECL_OVERRIDE {} + + Q_NORETURN virtual void raise() const Q_DECL_OVERRIDE; + // cppcheck-suppress unusedFunction + virtual VExceptionToolWasDeleted *clone() const Q_DECL_OVERRIDE; +}; + #endif // VEXCEPTION_H diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index e3c043b58..2648fc3b1 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -186,8 +186,16 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(); - return; //Leave this method immediately after call!!! + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } + break; default: break; } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp index f38e65e5c..f4b82d6e6 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp @@ -100,8 +100,8 @@ VToolArc* VToolArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstr QString f1 = dialogTool->GetF1(); QString f2 = dialogTool->GetF2(); const QString color = dialogTool->GetColor(); - VToolArc* point = Create(0, center, radius, f1, f2, color, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolArc* point = Create(0, center, radius, f1, f2, color, scene, doc, data, Document::FullParse, + Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -293,7 +293,15 @@ void VToolArc::ShowVisualization(bool show) */ void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- @@ -346,7 +354,7 @@ void VToolArc::SetVisualization() VisToolArc *visual = qobject_cast(vis); SCASSERT(visual != nullptr); - const VTranslateVars *trVars = qApp->TrVars(); + const VTranslateVars *trVars = qApp->TrVars(); visual->setPoint1Id(arc->GetCenter().id()); visual->setRadius(trVars->FormulaToUser(arc->GetFormulaRadius())); visual->setF1(trVars->FormulaToUser(arc->GetFormulaF1())); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp index 7788640e2..3dbfa983a 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp @@ -82,8 +82,8 @@ VToolArcWithLength *VToolArcWithLength::Create(DialogTool *dialog, VMainGraphics QString f1 = dialogTool->GetF1(); QString length = dialogTool->GetLength(); const QString color = dialogTool->GetColor(); - VToolArcWithLength* point = Create(0, center, radius, f1, length, color, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolArcWithLength* point = Create(0, center, radius, f1, length, color, scene, doc, data, Document::FullParse, + Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -255,7 +255,15 @@ void VToolArcWithLength::ShowVisualization(bool show) //--------------------------------------------------------------------------------------------------------------------- void VToolArcWithLength::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- @@ -302,7 +310,7 @@ void VToolArcWithLength::SetVisualization() VisToolArcWithLength *visual = qobject_cast(vis); SCASSERT(visual != nullptr); - const VTranslateVars *trVars = qApp->TrVars(); + const VTranslateVars *trVars = qApp->TrVars(); visual->setPoint1Id(arc->GetCenter().id()); visual->setRadius(trVars->FormulaToUser(arc->GetFormulaRadius())); visual->setF1(trVars->FormulaToUser(arc->GetFormulaF1())); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 7c44d7ec6..85d75b0bd 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -139,8 +139,8 @@ VToolSpline* VToolSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, const qreal angle2 = dialogTool->GetAngle2(); const qreal kCurve = dialogTool->GetKCurve(); const QString color = dialogTool->GetColor(); - VToolSpline *spl = Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, color, scene, doc, data, - Document::FullParse, Source::FromGui); + VToolSpline *spl = Create(0, p1, p4, kAsm1, kAsm2, angle1, angle2, kCurve, color, scene, doc, data, + Document::FullParse, Source::FromGui); if (spl != nullptr) { spl->dialog=dialogTool; @@ -270,7 +270,15 @@ void VToolSpline::EnableToolMove(bool move) */ void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index e2a21186c..6d1ba2bac 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -317,7 +317,15 @@ void VToolSplinePath::ShowVisualization(bool show) */ void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp index 7aea0cd8e..c85079a44 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooldoublepoint.cpp @@ -231,8 +231,16 @@ void VToolDoublePoint::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(); - return; //Leave this method immediately after call!!! + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } + break; default: break; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp index ae9689b29..abc78d74d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.cpp @@ -120,9 +120,9 @@ VToolTrueDarts *VToolTrueDarts::Create(DialogTool *dialog, VMainGraphicsScene *s const quint32 dartP2Id = dialogTool->GetSecondDartPointId(); const quint32 dartP3Id = dialogTool->GetThirdDartPointId(); - VToolTrueDarts *point = Create(0, 0, 0, baseLineP1Id, baseLineP2Id, dartP1Id, dartP2Id, dartP3Id, - point1Name, 5, 10, point2Name, 5, 10, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolTrueDarts *point = Create(0, 0, 0, baseLineP1Id, baseLineP2Id, dartP1Id, dartP2Id, dartP3Id, + point1Name, 5, 10, point2Name, 5, 10, scene, doc, data, Document::FullParse, + Source::FromGui); if (point != nullptr) { point->dialog = dialogTool; @@ -291,7 +291,15 @@ void VToolTrueDarts::SetDartP3Id(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- void VToolTrueDarts::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 2db29bbd3..5ec0fba65 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -94,8 +94,8 @@ VToolCutArc* VToolCutArc::Create(DialogTool *dialog, VMainGraphicsScene *scene, QString formula = dialogTool->GetFormula(); const quint32 arcId = dialogTool->getArcId(); const QString color = dialogTool->GetColor(); - VToolCutArc* point = Create(0, pointName, formula, arcId, 5, 10, color, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolCutArc* point = Create(0, pointName, formula, arcId, 5, 10, color, scene, doc, data, Document::FullParse, + Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -202,7 +202,15 @@ void VToolCutArc::CurveChoosed(quint32 id) */ void VToolCutArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 01433d0d9..c1ffb392b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -210,7 +210,15 @@ void VToolCutSpline::CurveChoosed(quint32 id) */ void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index c1714566d..3f611b0a2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -254,7 +254,15 @@ void VToolCutSplinePath::CurveChoosed(quint32 id) */ void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index 12f6a7d46..04aadefcf 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -77,7 +77,15 @@ void VToolAlongLine::SetFactor(qreal factor) //cppcheck-suppress unusedFunction void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- @@ -205,8 +213,8 @@ VToolAlongLine* VToolAlongLine::Create(DialogTool *dialog, VMainGraphicsScene *s const QString typeLine = dialogTool->GetTypeLine(); const QString lineColor = dialogTool->GetLineColor(); const QString pointName = dialogTool->getPointName(); - VToolAlongLine *point = Create(0, pointName, typeLine, lineColor, formula, firstPointId, secondPointId, - 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolAlongLine *point = Create(0, pointName, typeLine, lineColor, formula, firstPointId, secondPointId, + 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp index 9a15f911b..04522ac5c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolbisector.cpp @@ -137,8 +137,8 @@ VToolBisector* VToolBisector::Create(DialogTool *dialog, VMainGraphicsScene *sce const QString typeLine = dialogTool->GetTypeLine(); const QString lineColor = dialogTool->GetLineColor(); const QString pointName = dialogTool->getPointName(); - VToolBisector *point = Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, lineColor, - pointName, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolBisector *point = Create(0, formula, firstPointId, secondPointId, thirdPointId, typeLine, lineColor, + pointName, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -231,7 +231,15 @@ void VToolBisector::SetFactor(qreal factor) */ void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index 5489e4714..708f53cc4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -84,9 +84,9 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(DialogTool *dialog, VMa const quint32 basePointId = dialogTool->GetBasePointId(); const quint32 curveId = dialogTool->getCurveId(); - VToolCurveIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle, basePointId, - curveId, 5, 10, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolCurveIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle, basePointId, + curveId, 5, 10, scene, doc, data, Document::FullParse, + Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -224,7 +224,15 @@ void VToolCurveIntersectAxis::ShowVisualization(bool show) //--------------------------------------------------------------------------------------------------------------------- void VToolCurveIntersectAxis::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp index 17276a196..55b6546ea 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp @@ -104,8 +104,8 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene QString formulaAngle = dialogTool->GetAngle(); const quint32 basePointId = dialogTool->GetBasePointId(); - VToolEndLine *point = Create(0, pointName, typeLine, lineColor, formulaLength, formulaAngle, - basePointId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolEndLine *point = Create(0, pointName, typeLine, lineColor, formulaLength, formulaAngle, + basePointId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -183,7 +183,15 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, */ void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp index fc4785ecf..4cddc1b2c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolheight.cpp @@ -94,8 +94,8 @@ VToolHeight* VToolHeight::Create(DialogTool *dialog, VMainGraphicsScene *scene, const quint32 p1LineId = dialogTool->GetP1LineId(); const quint32 p2LineId = dialogTool->GetP2LineId(); - VToolHeight *point = Create(0, pointName, typeLine, lineColor, basePointId, p1LineId, p2LineId, 5, 10, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolHeight *point = Create(0, pointName, typeLine, lineColor, basePointId, p1LineId, p2LineId, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -189,7 +189,15 @@ QPointF VToolHeight::FindPoint(const QLineF &line, const QPointF &point) */ void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp index bbe5c1e0a..983c748a9 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp @@ -86,8 +86,8 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(DialogTool *dialog, VMain const quint32 firstPointId = dialogTool->GetFirstPointId(); const quint32 secondPointId = dialogTool->GetSecondPointId(); - VToolLineIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle, - basePointId, firstPointId, secondPointId, 5, 10, + VToolLineIntersectAxis *point = Create(0, pointName, typeLine, lineColor, formulaAngle, + basePointId, firstPointId, secondPointId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { @@ -235,7 +235,15 @@ void VToolLineIntersectAxis::ShowVisualization(bool show) //--------------------------------------------------------------------------------------------------------------------- void VToolLineIntersectAxis::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp index 683f4d7f3..63573b65f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolnormal.cpp @@ -98,8 +98,8 @@ VToolNormal* VToolNormal::Create(DialogTool *dialog, VMainGraphicsScene *scene, const QString lineColor = dialogTool->GetLineColor(); const QString pointName = dialogTool->getPointName(); const qreal angle = dialogTool->GetAngle(); - VToolNormal *point = Create(0, formula, firstPointId, secondPointId, typeLine, lineColor, pointName, angle, 5, 10, - scene, doc, data, Document::FullParse, Source::FromGui); + VToolNormal *point = Create(0, formula, firstPointId, secondPointId, typeLine, lineColor, pointName, angle, 5, 10, + scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -209,7 +209,15 @@ void VToolNormal::SetFactor(qreal factor) */ void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp index 63c79b588..984850531 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolshoulderpoint.cpp @@ -138,8 +138,8 @@ VToolShoulderPoint* VToolShoulderPoint::Create(DialogTool *dialog, VMainGraphics const QString typeLine = dialogTool->GetTypeLine(); const QString lineColor = dialogTool->GetLineColor(); const QString pointName = dialogTool->getPointName(); - VToolShoulderPoint * point = Create(0, formula, p1Line, p2Line, pShoulder, typeLine, lineColor, pointName, 5, - 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolShoulderPoint * point = Create(0, formula, p1Line, p2Line, pShoulder, typeLine, lineColor, pointName, 5, + 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -235,7 +235,15 @@ void VToolShoulderPoint::SetFactor(qreal factor) */ void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index 81b086214..5dc00d645 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -180,6 +180,10 @@ void VToolBasePoint::DeleteTool(bool ask) DeletePatternPiece *deletePP = new DeletePatternPiece(doc, nameActivDraw); connect(deletePP, &DeletePatternPiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); qApp->getUndoStack()->push(deletePP); + + // Throw exception, this will help prevent case when we forget to immediately quit function. + VExceptionToolWasDeleted e("Tool was used after deleting."); + throw e; } } @@ -291,17 +295,22 @@ void VToolBasePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) QApplication::restoreOverrideCursor(); #endif - quint32 ref = _referens; // store referens - _referens = 1; // make available delete pattern piece - if (doc->CountPP() > 1) + try { - ContextMenu(this, event); + if (doc->CountPP() > 1) + { + ContextMenu(this, event, RemoveOption::Enable, Referens::Ignore); + } + else + { + ContextMenu(this, event, RemoveOption::Disable); + } } - else + catch(const VExceptionToolWasDeleted &e) { - ContextMenu(this, event, false); + Q_UNUSED(e); + return;//Leave this method immediately!!! } - _referens = ref; // restore referens. If not restore garbage collector delete point!!! } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp index 72afca3e3..af65be768 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoollineintersect.cpp @@ -93,8 +93,8 @@ VToolLineIntersect* VToolLineIntersect::Create(DialogTool *dialog, VMainGraphics const quint32 p1Line2Id = dialogTool->GetP1Line2(); const quint32 p2Line2Id = dialogTool->GetP2Line2(); const QString pointName = dialogTool->getPointName(); - VToolLineIntersect* point = Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolLineIntersect* point = Create(0, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, pointName, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -197,7 +197,15 @@ void VToolLineIntersect::SetFactor(qreal factor) */ void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp index 464e43939..7b8250272 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp @@ -68,8 +68,8 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(DialogTool *dia const quint32 tangentPointId = dialogTool->GetTangentPointId(); const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint(); const QString pointName = dialogTool->getPointName(); - VToolPointFromArcAndTangent *point = Create(0, pointName, arcId, tangentPointId, pType, 5, 10, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolPointFromArcAndTangent *point = Create(0, pointName, arcId, tangentPointId, pType, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -267,7 +267,15 @@ void VToolPointFromArcAndTangent::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolPointFromArcAndTangent::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp index ddabfb803..5f33471e2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp @@ -73,8 +73,8 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(DialogToo const quint32 tangentPointId = dialogTool->GetTangentPointId(); const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint(); const QString pointName = dialogTool->getPointName(); - VToolPointFromCircleAndTangent *point = Create(0, pointName, circleCenterId, circleRadius, tangentPointId, pType, - 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolPointFromCircleAndTangent *point = Create(0, pointName, circleCenterId, circleRadius, tangentPointId, pType, + 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -251,7 +251,15 @@ void VToolPointFromCircleAndTangent::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolPointFromCircleAndTangent::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp index cdc11205b..c4153c436 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp @@ -155,8 +155,8 @@ VToolPointOfContact* VToolPointOfContact::Create(DialogTool *dialog, VMainGraphi const quint32 firstPointId = dialogTool->GetFirstPoint(); const quint32 secondPointId = dialogTool->GetSecondPoint(); const QString pointName = dialogTool->getPointName(); - VToolPointOfContact *point = Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolPointOfContact *point = Create(0, radius, center, firstPointId, secondPointId, pointName, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -251,7 +251,15 @@ void VToolPointOfContact::SetFactor(qreal factor) */ void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp index 16b53c2db..3350ecc8e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersection.cpp @@ -86,8 +86,8 @@ VToolPointOfIntersection *VToolPointOfIntersection::Create(DialogTool *dialog, V const quint32 firstPointId = dialogTool->GetFirstPointId(); const quint32 secondPointId = dialogTool->GetSecondPointId(); const QString pointName = dialogTool->getPointName(); - VToolPointOfIntersection *point = Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolPointOfIntersection *point = Create(0, pointName, firstPointId, secondPointId, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -170,7 +170,15 @@ void VToolPointOfIntersection::RemoveReferens() */ void VToolPointOfIntersection::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp index 9774aa718..e94124f50 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp @@ -68,8 +68,8 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(DialogTool *d const quint32 secondArcId = dialogTool->GetSecondArcId(); const CrossCirclesPoint pType = dialogTool->GetCrossArcPoint(); const QString pointName = dialogTool->getPointName(); - VToolPointOfIntersectionArcs *point = Create(0, pointName, firstArcId, secondArcId, pType, 5, 10, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolPointOfIntersectionArcs *point = Create(0, pointName, firstArcId, secondArcId, pType, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -125,8 +125,8 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(const quint32 QPointF VToolPointOfIntersectionArcs::FindPoint(const VArc *arc1, const VArc *arc2, const CrossCirclesPoint pType) { QPointF p1, p2; - const QPointF centerArc1 = arc1->GetCenter().toQPointF(); - const QPointF centerArc2 = arc2->GetCenter().toQPointF(); + const QPointF centerArc1 = arc1->GetCenter().toQPointF(); + const QPointF centerArc2 = arc2->GetCenter().toQPointF(); const int res = VGObject::IntersectionCircles(centerArc1, arc1->GetRadius(), centerArc2, arc2->GetRadius(), p1, p2); QLineF r1Arc1(centerArc1, p1); @@ -274,7 +274,15 @@ void VToolPointOfIntersectionArcs::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolPointOfIntersectionArcs::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp index 14ebea687..950ee3fa1 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp @@ -79,9 +79,9 @@ VToolPointOfIntersectionCircles *VToolPointOfIntersectionCircles::Create(DialogT QString secondCircleRadius = dialogTool->GetSecondCircleRadius(); const CrossCirclesPoint pType = dialogTool->GetCrossCirclesPoint(); const QString pointName = dialogTool->getPointName(); - VToolPointOfIntersectionCircles *point = Create(0, pointName, firstCircleCenterId, secondCircleCenterId, - firstCircleRadius, secondCircleRadius, pType, 5, 10, scene, doc, - data, Document::FullParse, Source::FromGui); + VToolPointOfIntersectionCircles *point = Create(0, pointName, firstCircleCenterId, secondCircleCenterId, + firstCircleRadius, secondCircleRadius, pType, 5, 10, scene, doc, + data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -287,7 +287,15 @@ void VToolPointOfIntersectionCircles::RemoveReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolPointOfIntersectionCircles::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp index 1a5eda380..6caad29c8 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.cpp @@ -310,8 +310,16 @@ void VToolSinglePoint::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(); - return; //Leave this method immediately after call!!! + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } + break; default: break; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp index 70ab3f8c8..c210f2265 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp @@ -93,8 +93,8 @@ VToolTriangle* VToolTriangle::Create(DialogTool *dialog, VMainGraphicsScene *sce const quint32 firstPointId = dialogTool->GetFirstPointId(); const quint32 secondPointId = dialogTool->GetSecondPointId(); const QString pointName = dialogTool->getPointName(); - VToolTriangle* point = Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, - scene, doc, data, Document::FullParse, Source::FromGui); + VToolTriangle* point = Create(0, pointName, axisP1Id, axisP2Id, firstPointId, secondPointId, 5, 10, + scene, doc, data, Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -226,7 +226,15 @@ void VToolTriangle::RemoveReferens() */ void VToolTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp index c021dd126..a0423c207 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.cpp @@ -60,7 +60,15 @@ void VAbstractPoint::ShowTool(quint32 id, bool enable) //--------------------------------------------------------------------------------------------------------------------- void VAbstractPoint::DeleteFromLabel() { - DeleteTool(); //Leave this method immediately after call!!! + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 3b6967e30..3fc0b39dd 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -74,6 +74,9 @@ public slots: virtual void Disable(bool disable, const QString &namePP)=0; protected: + enum class RemoveOption : bool {Disable = false, Enable = true}; + enum class Referens : bool {Follow = true, Ignore = false}; + /** @brief nameActivDraw name of tool's pattern peace. */ QString nameActivDraw; @@ -105,7 +108,9 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement)=0; template - void ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove = true); + void ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, + const RemoveOption &showRemove = RemoveOption::Enable, + const Referens &ref = Referens::Follow); template void ShowItem(Item *item, quint32 id, bool enable); @@ -119,9 +124,11 @@ template * @brief ContextMenu show context menu for tool. * @param tool tool. * @param event context menu event. - * @param showRemove true - tool have option delete. + * @param showRemove true - tool enable option delete. + * @param ref true - do not ignore referens value. */ -void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove) +void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, const RemoveOption &showRemove, + const Referens &ref) { SCASSERT(tool != nullptr); SCASSERT(event != nullptr); @@ -129,11 +136,18 @@ void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, b QMenu menu; QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); - if (showRemove) + if (showRemove == RemoveOption::Enable) { - if (_referens > 1) + if (ref == Referens::Follow) { - actionRemove->setEnabled(false); + if (_referens > 1) + { + actionRemove->setEnabled(false); + } + else + { + actionRemove->setEnabled(true); + } } else { @@ -161,7 +175,7 @@ void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, b } if (selectedAction == actionRemove) { - DeleteTool(); + DeleteTool(); // do not catch exception here return; //Leave this method immediately after call!!! } } diff --git a/src/libs/vtools/tools/drawTools/vtoolline.cpp b/src/libs/vtools/tools/drawTools/vtoolline.cpp index e81290868..59502a302 100644 --- a/src/libs/vtools/tools/drawTools/vtoolline.cpp +++ b/src/libs/vtools/tools/drawTools/vtoolline.cpp @@ -231,7 +231,15 @@ void VToolLine::Disable(bool disable, const QString &namePP) */ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { - ContextMenu(this, event); + try + { + ContextMenu(this, event); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- @@ -338,8 +346,16 @@ void VToolLine::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(); - return; //Leave this method immediately after call!!! + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } + break; default: break; } diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 8bf9bfcc8..0036f78c2 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -80,6 +80,10 @@ void VAbstractTool::DeleteTool(bool ask) DelTool *delTool = new DelTool(doc, id); connect(delTool, &DelTool::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); qApp->getUndoStack()->push(delTool); + + // Throw exception, this will help prevent case when we forget to immediately quit function. + VExceptionToolWasDeleted e("Tool was used after deleting."); + throw e; } } diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 793779ced..07936d6da 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -153,7 +153,7 @@ void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstrac for (int i = 0; i< detail.CountNode(); ++i) { quint32 id = 0; - const VNodeDetail &nodeD = detail.at(i); + const VNodeDetail &nodeD = detail.at(i); switch (nodeD.getTypeTool()) { case (Tool::NodePoint): @@ -238,7 +238,15 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap */ void VToolDetail::Remove(bool ask) { - DeleteTool(ask); + try + { + DeleteTool(ask); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } } //--------------------------------------------------------------------------------------------------------------------- @@ -367,8 +375,16 @@ void VToolDetail::keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Delete: - DeleteTool(); - return; //Leave this method immediately after call!!! + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } + break; default: break; } @@ -420,7 +436,15 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } if (selectedAction == actionRemove) { - DeleteTool(); + try + { + DeleteTool(); + } + catch(const VExceptionToolWasDeleted &e) + { + Q_UNUSED(e); + return;//Leave this method immediately!!! + } return; //Leave this method immediately after call!!! } } @@ -525,6 +549,10 @@ void VToolDetail::DeleteTool(bool ask) connect(delDet, &DeleteDetail::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); } qApp->getUndoStack()->push(delDet); + + // Throw exception, this will help prevent case when we forget to immediately quit function. + VExceptionToolWasDeleted e("Tool was used after deleting."); + throw e; } //---------------------------------------------------------------------------------------------------------------------