From a3429484377652434a9d13c48b2d0f8f6d9e2c98 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 3 Nov 2015 17:11:35 +0200 Subject: [PATCH] Improved loging. Base point's DeleteTool should ignore value "_referens". --HG-- branch : develop --- .../toolsinglepoint/vtoolbasepoint.cpp | 37 +++++++++++-------- .../toolsinglepoint/vtoolbasepoint.h | 2 +- src/libs/vtools/tools/drawTools/vdrawtool.h | 7 ++++ src/libs/vtools/tools/vabstracttool.cpp | 10 +++++ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index 5dc00d645..d9f376e55 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -166,25 +166,26 @@ void VToolBasePoint::decrementReferens() //--------------------------------------------------------------------------------------------------------------------- void VToolBasePoint::DeleteTool(bool ask) { - if (_referens <= 1) + qCDebug(vTool, "Deleting base point."); + qApp->getSceneView()->itemClicked(nullptr); + if (ask) { - qApp->getSceneView()->itemClicked(nullptr); - if (ask) + qCDebug(vTool, "Asking."); + if (ConfirmDeletion() == QMessageBox::No) { - if (ConfirmDeletion() == QMessageBox::No) - { - return; - } + qCDebug(vTool, "User said no."); + return; } - - 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; } + + qCDebug(vTool, "Begin deleting."); + 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,26 +292,32 @@ void VToolBasePoint::ReadToolAttributes(const QDomElement &domElement) */ void VToolBasePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) { + qCDebug(vTool, "Context menu base point"); #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); + qCDebug(vTool, "Restored overriden cursor"); #endif try { if (doc->CountPP() > 1) { + qCDebug(vTool, "PP count > 1"); ContextMenu(this, event, RemoveOption::Enable, Referens::Ignore); } else { + qCDebug(vTool, "PP count = 1"); ContextMenu(this, event, RemoveOption::Disable); } } catch(const VExceptionToolWasDeleted &e) { + qCDebug(vTool, "Tool was deleted. Immediately leave method."); Q_UNUSED(e); return;//Leave this method immediately!!! } + qCDebug(vTool, "Context menu closed. Tool was not deleted."); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h index 87397a524..7320ad877 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h @@ -32,7 +32,7 @@ #include "vtoolsinglepoint.h" /** - * @brief The VToolBasePoint class tool for creation pattern base point. Obly base point can move. All object + * @brief The VToolBasePoint class tool for creation pattern base point. Only base point can move. All object * pattern peace depend on base point. */ class VToolBasePoint : public VToolSinglePoint diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 3fc0b39dd..530cf4e17 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -133,6 +133,7 @@ void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, c SCASSERT(tool != nullptr); SCASSERT(event != nullptr); + qCDebug(vTool, "Creating tool context menu."); QMenu menu; QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); @@ -142,26 +143,31 @@ void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, c { if (_referens > 1) { + qCDebug(vTool, "Remove disabled. Tool has childern."); actionRemove->setEnabled(false); } else { + qCDebug(vTool, "Remove enabled. Tool has not childern."); actionRemove->setEnabled(true); } } else { + qCDebug(vTool, "Remove enabled. Ignore referens value."); actionRemove->setEnabled(true); } } else { + qCDebug(vTool, "Remove disabled."); actionRemove->setEnabled(false); } QAction *selectedAction = menu.exec(event->screenPos()); if (selectedAction == actionOption) { + qCDebug(vTool, "Show options."); qApp->getSceneView()->itemClicked(nullptr); dialog = new Dialog(getData(), id, qApp->getMainWindow()); dialog->setModal(true); @@ -175,6 +181,7 @@ void VDrawTool::ContextMenu(Tool *tool, QGraphicsSceneContextMenuEvent *event, c } if (selectedAction == actionRemove) { + qCDebug(vTool, "Deleting tool."); DeleteTool(); // do not catch exception here return; //Leave this method immediately after call!!! } diff --git a/src/libs/vtools/tools/vabstracttool.cpp b/src/libs/vtools/tools/vabstracttool.cpp index 0036f78c2..f4883bcdb 100644 --- a/src/libs/vtools/tools/vabstracttool.cpp +++ b/src/libs/vtools/tools/vabstracttool.cpp @@ -67,16 +67,22 @@ VAbstractTool::~VAbstractTool() */ void VAbstractTool::DeleteTool(bool ask) { + qCDebug(vTool, "Deleting abstract tool."); if (_referens <= 1) { + qCDebug(vTool, "No children."); qApp->getSceneView()->itemClicked(nullptr); if (ask) { + qCDebug(vTool, "Asking."); if (ConfirmDeletion() == QMessageBox::No) { + qCDebug(vTool, "User said no."); return; } } + + qCDebug(vTool, "Begin deleting."); DelTool *delTool = new DelTool(doc, id); connect(delTool, &DelTool::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); qApp->getUndoStack()->push(delTool); @@ -85,6 +91,10 @@ void VAbstractTool::DeleteTool(bool ask) VExceptionToolWasDeleted e("Tool was used after deleting."); throw e; } + else + { + qCDebug(vTool, "Can't delete, tool has children."); + } } //---------------------------------------------------------------------------------------------------------------------