Follow up Auto-break conductors

This commit is contained in:
Kellermorph
2026-08-08 22:10:47 +02:00
parent 3eafe840f1
commit 39b1e836bf
7 changed files with 333 additions and 213 deletions
+29
View File
@@ -17,7 +17,9 @@
*/
#include "diagramcommands.h"
#include "autobreakconductor.h"
#include "diagram.h"
#include "qetproject.h"
#include "qetgraphicsitem/conductortextitem.h"
#include "qetgraphicsitem/element.h"
#include "qetgraphicsitem/elementtextitemgroup.h"
@@ -48,6 +50,7 @@ PasteDiagramCommand::PasteDiagramCommand( Diagram *dia, const DiagramContent &c,
PasteDiagramCommand::~PasteDiagramCommand()
{
diagram -> qgiManager().release(content.items(filter));
delete m_break_cmd;
}
/**
@@ -58,6 +61,10 @@ void PasteDiagramCommand::undo()
{
diagram -> showMe();
//Undo auto-break before removing items, so terminals are still on scene
if (m_break_cmd)
m_break_cmd->undo();
foreach(QGraphicsItem *item, content.items(filter))
diagram->removeItem(item);
}
@@ -102,6 +109,24 @@ void PasteDiagramCommand::redo()
}
}
}
//Auto-break conductors on first paste. Items are already on the
//scene at this point (added before this command was created).
if (diagram->project()->autoBreakConductor())
{
m_break_cmd = new QUndoCommand();
for (Element *e : content.m_elements) {
autoBreakConductors(diagram, e, m_break_cmd);
}
if (m_break_cmd->childCount() == 0) {
delete m_break_cmd;
m_break_cmd = nullptr;
}
else
{
m_break_cmd->redo();
}
}
}
else
{
@@ -109,6 +134,10 @@ void PasteDiagramCommand::redo()
for (QGraphicsItem *item : qgis_list) {
diagram->addItem(item);
}
//Re-execute the stored break commands (items are back on scene)
if (m_break_cmd)
m_break_cmd->redo();
}
const QList<QGraphicsItem *> qgis_list = content.items();