mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-20 15:24:14 +02:00
Fix the following issues:
a) paste - conductor does not move - pressing escape does not abort - pressing anything during the process crashes the program instead of aborting b) similar issue with the escape not working fixed for graphics items, texxt fields (and probably others)
This commit is contained in:
@@ -216,6 +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; }
|
||||
|
||||
// methods related to graphics options
|
||||
ExportProperties applyProperties(const ExportProperties &);
|
||||
|
||||
@@ -87,12 +87,12 @@ DiagramEventAddPaste::DiagramEventAddPaste(Diagram *diagram, const QPointF &star
|
||||
*/
|
||||
DiagramEventAddPaste::~DiagramEventAddPaste()
|
||||
{
|
||||
if (!m_finished && m_diagram) {
|
||||
cancel();
|
||||
}
|
||||
if (m_status_bar) {
|
||||
m_status_bar->clearMessage();
|
||||
if (!m_finished) {
|
||||
removeItems();
|
||||
m_finished = true;
|
||||
m_running = false;
|
||||
}
|
||||
if (m_status_bar) m_status_bar->clearMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,6 +139,10 @@ void DiagramEventAddPaste::moveTo(const QPointF &scene_pos)
|
||||
it.key()->setPos(anchor + it.value());
|
||||
}
|
||||
}
|
||||
const auto conductors = m_content.conductors(); // AnyConductor by default
|
||||
for (auto *cond : conductors) {
|
||||
cond->updatePath();
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramEventAddPaste::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
@@ -216,13 +220,14 @@ void DiagramEventAddPaste::commit()
|
||||
void DiagramEventAddPaste::cancel()
|
||||
{
|
||||
if (m_finished || !m_diagram) return;
|
||||
removeItems();
|
||||
m_finished = true;
|
||||
m_running = false;
|
||||
emit finish(); // only the user-driven path signals
|
||||
}
|
||||
|
||||
//Conductors first: they hold pointers to the terminals of the
|
||||
//elements below, so removing an element out from under one would
|
||||
//leave it pointing at freed memory for as long as it is still in the
|
||||
//scene.
|
||||
void DiagramEventAddPaste::removeItems()
|
||||
{
|
||||
const QList<Conductor *> conductors = m_content.conductors(DiagramContent::AnyConductor);
|
||||
for (auto *conductor : conductors) {
|
||||
m_diagram->removeItem(conductor);
|
||||
@@ -237,5 +242,4 @@ void DiagramEventAddPaste::cancel()
|
||||
|
||||
m_content.clear();
|
||||
m_relative_pos.clear();
|
||||
emit finish();
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ class DiagramEventAddPaste : public DiagramEventInterface
|
||||
void commit();
|
||||
void cancel();
|
||||
void showHint();
|
||||
void removeItems();
|
||||
|
||||
DiagramContent m_content;
|
||||
///Each movable item's position relative to the group's top left,
|
||||
|
||||
@@ -317,10 +317,16 @@ void DiagramEventAddShape::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
did anything. Re-running the last known mouse position through
|
||||
applyPosition() here makes the key press or release itself the
|
||||
trigger, giving immediate feedback instead of waiting on chance.
|
||||
Any other key falls back to standard handling, e.g. pressing ESC aborts the operation.
|
||||
*/
|
||||
void DiagramEventAddShape::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
reapplyLastPosition(event);
|
||||
if (event->key() == Qt::Key_Shift || event->key() == Qt::Key_Control) {
|
||||
reapplyLastPosition(event);
|
||||
event->setAccepted(true);
|
||||
} else {
|
||||
DiagramEventInterface::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void DiagramEventAddShape::keyReleaseEvent(QKeyEvent *event)
|
||||
|
||||
@@ -733,6 +733,10 @@ 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()) {
|
||||
QGraphicsView::keyPressEvent(e); // let the active tool see it
|
||||
return;
|
||||
}
|
||||
if (m_diagram && !m_diagram->selectedItems().isEmpty()) {
|
||||
m_diagram->clearSelection();
|
||||
} else {
|
||||
|
||||
@@ -1754,6 +1754,10 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action)
|
||||
// here makes the button's appearance match its actual state
|
||||
// regardless of whether Qt's own change notification fired
|
||||
// correctly.
|
||||
|
||||
if (DiagramView *dv = currentDiagramView())
|
||||
dv->setFocus(); // so the view (and the active tool) actually receives Escape etc
|
||||
|
||||
if (QWidget *button = m_add_item_tool_bar->widgetForAction(action))
|
||||
button->update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user