Fixed crash after undo creating a pattern piece.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-11-02 18:25:29 +02:00
parent 9aa8713203
commit 345b0e5c7f
37 changed files with 468 additions and 106 deletions

View File

@ -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!!")),

View File

@ -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!!")),

View File

@ -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);
}

View File

@ -34,8 +34,6 @@
#include <QCoreApplication>
#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

View File

@ -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;
}

View File

@ -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<DialogArc>(this, event);
try
{
ContextMenu<DialogArc>(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<VisToolArc *>(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()));

View File

@ -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<DialogArcWithLength>(this, event);
try
{
ContextMenu<DialogArcWithLength>(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<VisToolArcWithLength *>(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()));

View File

@ -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<DialogSpline>(this, event);
try
{
ContextMenu<DialogSpline>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -317,7 +317,15 @@ void VToolSplinePath::ShowVisualization(bool show)
*/
void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
ContextMenu<DialogSplinePath>(this, event);
try
{
ContextMenu<DialogSplinePath>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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;
}

View File

@ -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<DialogTrueDarts>(this, event);
try
{
ContextMenu<DialogTrueDarts>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogCutArc>(this, event);
try
{
ContextMenu<DialogCutArc>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -210,7 +210,15 @@ void VToolCutSpline::CurveChoosed(quint32 id)
*/
void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
ContextMenu<DialogCutSpline>(this, event);
try
{
ContextMenu<DialogCutSpline>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -254,7 +254,15 @@ void VToolCutSplinePath::CurveChoosed(quint32 id)
*/
void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
ContextMenu<DialogCutSplinePath>(this, event);
try
{
ContextMenu<DialogCutSplinePath>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -77,7 +77,15 @@ void VToolAlongLine::SetFactor(qreal factor)
//cppcheck-suppress unusedFunction
void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
ContextMenu<DialogAlongLine>(this, event);
try
{
ContextMenu<DialogAlongLine>(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;

View File

@ -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<DialogBisector>(this, event);
try
{
ContextMenu<DialogBisector>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogCurveIntersectAxis>(this, event);
try
{
ContextMenu<DialogCurveIntersectAxis>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogEndLine>(this, event);
try
{
ContextMenu<DialogEndLine>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogHeight>(this, event);
try
{
ContextMenu<DialogHeight>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogLineIntersectAxis>(this, event);
try
{
ContextMenu<DialogLineIntersectAxis>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogNormal>(this, event);
try
{
ContextMenu<DialogNormal>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogShoulderPoint>(this, event);
try
{
ContextMenu<DialogShoulderPoint>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogSinglePoint>(this, event);
if (doc->CountPP() > 1)
{
ContextMenu<DialogSinglePoint>(this, event, RemoveOption::Enable, Referens::Ignore);
}
else
{
ContextMenu<DialogSinglePoint>(this, event, RemoveOption::Disable);
}
}
else
catch(const VExceptionToolWasDeleted &e)
{
ContextMenu<DialogSinglePoint>(this, event, false);
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
_referens = ref; // restore referens. If not restore garbage collector delete point!!!
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogLineIntersect>(this, event);
try
{
ContextMenu<DialogLineIntersect>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogPointFromArcAndTangent>(this, event);
try
{
ContextMenu<DialogPointFromArcAndTangent>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogPointFromCircleAndTangent>(this, event);
try
{
ContextMenu<DialogPointFromCircleAndTangent>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogPointOfContact>(this, event);
try
{
ContextMenu<DialogPointOfContact>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogPointOfIntersection>(this, event);
try
{
ContextMenu<DialogPointOfIntersection>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogPointOfIntersectionArcs>(this, event);
try
{
ContextMenu<DialogPointOfIntersectionArcs>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<DialogPointOfIntersectionCircles>(this, event);
try
{
ContextMenu<DialogPointOfIntersectionCircles>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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;
}

View File

@ -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<DialogTriangle>(this, event);
try
{
ContextMenu<DialogTriangle>(this, event);
}
catch(const VExceptionToolWasDeleted &e)
{
Q_UNUSED(e);
return;//Leave this method immediately!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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!!!
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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 <typename Dialog, typename Tool>
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 <typename Item>
void ShowItem(Item *item, quint32 id, bool enable);
@ -119,9 +124,11 @@ template <typename Dialog, typename Tool>
* @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!!!
}
}

View File

@ -231,7 +231,15 @@ void VToolLine::Disable(bool disable, const QString &namePP)
*/
void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
ContextMenu<DialogLine>(this, event);
try
{
ContextMenu<DialogLine>(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;
}

View File

@ -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;
}
}

View File

@ -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;
}
//---------------------------------------------------------------------------------------------------------------------