From 863ac5f0aeb878e940ed4aa169d2b42b7fc5e241 Mon Sep 17 00:00:00 2001 From: Andre Rummler Date: Thu, 17 Sep 2026 13:25:17 +0200 Subject: [PATCH] avoid that another action triggers while aborting operation --- sources/diagram.cpp | 5 +++++ sources/diagram.h | 2 +- sources/diagramevent/diagrameventaddpaste.cpp | 12 +++++++----- sources/diagramview.cpp | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 591f2b885..aa8e92399 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -801,6 +801,11 @@ void Diagram::clearEventInterface() } } +bool Diagram::eventInterfaceIsRunning() const +{ + return m_event_interface && m_event_interface->isRunning(); +} + /** @brief Diagram::conductorsAutonumName @return the name of autonum to use. diff --git a/sources/diagram.h b/sources/diagram.h index aa9cb1d9f..824b6dc38 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -216,7 +216,7 @@ class Diagram : public QGraphicsScene // methods related to graphics items addition/removal on the diagram virtual void addItem (QGraphicsItem *item); virtual void removeItem (QGraphicsItem *item); - bool hasEventInterface() const { return m_event_interface != nullptr; } + bool eventInterfaceIsRunning() const; // methods related to graphics options ExportProperties applyProperties(const ExportProperties &); diff --git a/sources/diagramevent/diagrameventaddpaste.cpp b/sources/diagramevent/diagrameventaddpaste.cpp index d9be0f159..ccc105192 100644 --- a/sources/diagramevent/diagrameventaddpaste.cpp +++ b/sources/diagramevent/diagrameventaddpaste.cpp @@ -87,12 +87,14 @@ DiagramEventAddPaste::DiagramEventAddPaste(Diagram *diagram, const QPointF &star */ DiagramEventAddPaste::~DiagramEventAddPaste() { - if (!m_finished) { + if (!m_finished && m_diagram) { removeItems(); m_finished = true; m_running = false; } - if (m_status_bar) m_status_bar->clearMessage(); + if (m_status_bar) { + m_status_bar->clearMessage(); + } } /** @@ -164,13 +166,13 @@ void DiagramEventAddPaste::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (!m_running) return; + event->setAccepted(true); if (event->button() == Qt::LeftButton) { moveTo(event->scenePos()); commit(); } else if (event->button() == Qt::RightButton) { cancel(); } - event->setAccepted(true); } void DiagramEventAddPaste::keyPressEvent(QKeyEvent *event) @@ -179,15 +181,15 @@ void DiagramEventAddPaste::keyPressEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Escape: - cancel(); event->setAccepted(true); + cancel(); break; //Return and Enter drop the paste where it stands, so the whole //operation can be completed without a mouse. case Qt::Key_Return: case Qt::Key_Enter: - commit(); event->setAccepted(true); + commit(); break; default: break; diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 3d2a6d340..9e89be6cb 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -733,7 +733,7 @@ void DiagramView::keyPressEvent(QKeyEvent *e) //way off the canvas for someone working without a mouse. //Escape steps back out: first it drops the selection, then it //hands focus to the next widget. - if (m_diagram && m_diagram->hasEventInterface()) { + if (m_diagram && m_diagram->eventInterfaceIsRunning()) { QGraphicsView::keyPressEvent(e); // let the active tool see it return; }